Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 depth(self):
return self._depth

def negate_depth(self):

Check warning on line 117 in parcels/grid.py

View check run for this annotation

Codecov / codecov/patch

parcels/grid.py#L117

Added line #L117 was not covered by tests
"""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

Check warning on line 122 in parcels/grid.py

View check run for this annotation

Codecov / codecov/patch

parcels/grid.py#L122

Added line #L122 was not covered by tests

@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
Loading