Skip to content

Commit

Permalink
Merge pull request #1778 from OceanParcels/grid_negate_depth
Browse files Browse the repository at this point in the history
Adding support for grid.negate_depth() method
  • Loading branch information
erikvansebille authored Nov 28, 2024
2 parents a1f7a56 + bb1a047 commit e709843
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions parcels/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ def lat(self):
def depth(self):
return self._depth

def negate_depth(self):
"""Method to flip the sign of the depth dimension of a Grid.
Note that this method does _not_ change the direction of the vertical velocity;
for that users need to add a fieldset.W.set_scaling_factor(-1.0)
"""
self._depth = -self._depth

@property
def mesh(self):
return self._mesh
Expand Down
10 changes: 10 additions & 0 deletions tests/test_grids.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ def test_time_format_in_grid():
RectilinearZGrid(lon, lat, time=time)


def test_negate_depth():
depth = np.linspace(0, 5, 10, dtype=np.float32)
fieldset = FieldSet.from_data(
{"U": np.zeros((10, 1, 1)), "V": np.zeros((10, 1, 1))}, {"lon": [0], "lat": [0], "depth": depth}
)
assert np.all(fieldset.gridset.grids[0].depth == depth)
fieldset.U.grid.negate_depth()
assert np.all(fieldset.gridset.grids[0].depth == -depth)


def test_avoid_repeated_grids():
lon_g0 = np.linspace(0, 1000, 11, dtype=np.float32)
lat_g0 = np.linspace(0, 1000, 11, dtype=np.float32)
Expand Down

0 comments on commit e709843

Please sign in to comment.