Skip to content

Commit e709843

Browse files
Merge pull request #1778 from OceanParcels/grid_negate_depth
Adding support for grid.negate_depth() method
2 parents a1f7a56 + bb1a047 commit e709843

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

parcels/grid.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ def lat(self):
114114
def depth(self):
115115
return self._depth
116116

117+
def negate_depth(self):
118+
"""Method to flip the sign of the depth dimension of a Grid.
119+
Note that this method does _not_ change the direction of the vertical velocity;
120+
for that users need to add a fieldset.W.set_scaling_factor(-1.0)
121+
"""
122+
self._depth = -self._depth
123+
117124
@property
118125
def mesh(self):
119126
return self._mesh

tests/test_grids.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ def test_time_format_in_grid():
112112
RectilinearZGrid(lon, lat, time=time)
113113

114114

115+
def test_negate_depth():
116+
depth = np.linspace(0, 5, 10, dtype=np.float32)
117+
fieldset = FieldSet.from_data(
118+
{"U": np.zeros((10, 1, 1)), "V": np.zeros((10, 1, 1))}, {"lon": [0], "lat": [0], "depth": depth}
119+
)
120+
assert np.all(fieldset.gridset.grids[0].depth == depth)
121+
fieldset.U.grid.negate_depth()
122+
assert np.all(fieldset.gridset.grids[0].depth == -depth)
123+
124+
115125
def test_avoid_repeated_grids():
116126
lon_g0 = np.linspace(0, 1000, 11, dtype=np.float32)
117127
lat_g0 = np.linspace(0, 1000, 11, dtype=np.float32)

0 commit comments

Comments
 (0)