Skip to content

Commit 6c5f89e

Browse files
Merge pull request #1936 from OceanParcels/1844-data-full-zdim
Remove data_full_zdim from fieldfilebuffer
2 parents e38d5c3 + b7f71d6 commit 6c5f89e

5 files changed

Lines changed: 22 additions & 24 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ jobs:
7777
environment-file: environment.yml
7878
- name: Integration test
7979
# TODO v4: Re-enable `tutorial_periodic_boundaries`, `tutorial_timevaryingdepthdimensions` and `tutorial_croco_3D` notebooks
80+
# TODO v4: Re-enable `tutorial_nemo_3D` notebook once 3D grids are implemented (https://github.com/OceanParcels/Parcels/pull/1936#issuecomment-2717666705)
8081
run: |
81-
coverage run -m pytest -v -s --nbval-lax -k "not documentation and not tutorial_periodic_boundaries and not tutorial_timevaryingdepthdimensions and not tutorial_croco_3D" --html="${{ matrix.os }}_${{ matrix.python-version }}_integration_test_report.html" --self-contained-html docs/examples
82+
coverage run -m pytest -v -s --nbval-lax -k "not documentation and not tutorial_periodic_boundaries and not tutorial_timevaryingdepthdimensions and not tutorial_croco_3D and not tutorial_nemo_3D" --html="${{ matrix.os }}_${{ matrix.python-version }}_integration_test_report.html" --self-contained-html docs/examples
8283
coverage xml
8384
- name: Codecov
8485
uses: codecov/codecov-action@v5.3.1

parcels/field.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,13 +390,9 @@ def from_netcdf(
390390
) as filebuffer:
391391
filebuffer.name = variable[1]
392392
depth = filebuffer.depth
393-
data_full_zdim = filebuffer.data_full_zdim
394393
else:
395394
indices["depth"] = np.array([0])
396395
depth = np.zeros(1)
397-
data_full_zdim = 1
398-
399-
kwargs["data_full_zdim"] = data_full_zdim
400396

401397
if len(data_filenames) > 1 and "time" not in dimensions:
402398
raise RuntimeError("Multiple files given but no time dimension specified")
@@ -421,7 +417,6 @@ def from_netcdf(
421417
dimensions,
422418
indices,
423419
interp_method=interp_method,
424-
data_full_zdim=data_full_zdim,
425420
) as filebuffer:
426421
# If Field.from_netcdf is called directly, it may not have a 'data' dimension
427422
# In that case, assume that 'name' is the data dimension

parcels/fieldfilebuffer.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ def __init__(
1717
indices,
1818
*,
1919
interp_method: InterpMethodOption = "linear",
20-
data_full_zdim=None,
2120
gridindexingtype="nemo",
2221
):
2322
self.filename: PathLike | list[PathLike] = filename
@@ -26,7 +25,6 @@ def __init__(
2625
self.dataset = None
2726
self.interp_method = interp_method
2827
self.gridindexingtype = gridindexingtype
29-
self.data_full_zdim = data_full_zdim
3028

3129
def __enter__(self):
3230
self.dataset = open_xarray_dataset(self.filename)
@@ -58,6 +56,8 @@ def ydim(self):
5856

5957
@property
6058
def zdim(self):
59+
if "depth" not in self.dimensions:
60+
return 1
6161
depth = self.dataset[self.dimensions["depth"]]
6262
zdim = depth.size if len(depth.shape) == 1 else depth.shape[-3]
6363
if self.gridindexingtype in ["croco"]:
@@ -84,23 +84,14 @@ def latlon(self):
8484

8585
@property
8686
def depth(self):
87+
self.indices["depth"] = range(self.zdim)
8788
if "depth" in self.dimensions:
88-
depth = self.dataset[self.dimensions["depth"]]
89-
self.data_full_zdim = self.zdim
90-
self.indices["depth"] = range(self.zdim)
91-
return depth
92-
else:
93-
self.indices["depth"] = [0]
94-
return np.zeros(1)
89+
return self.dataset[self.dimensions["depth"]]
90+
return np.zeros(1)
9591

9692
@property
97-
def depth_dimensions(self):
98-
if "depth" in self.dimensions:
99-
data = self.dataset[self.name]
100-
depthsize = data.shape[-3]
101-
self.data_full_zdim = depthsize
102-
self.indices["depth"] = range(depthsize)
103-
return np.empty((0, self.zdim) + data.shape[-2:])
93+
def data_full_zdim(self):
94+
return self.zdim
10495

10596
def _check_extend_depth(self, data, dim):
10697
return (

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ platforms = ["win-64", "linux-64", "osx-64", "osx-arm64"]
4646

4747
[tool.pixi.tasks]
4848
tests = "pytest"
49-
tests-notebooks = "pytest -v -s --nbval-lax -k 'not documentation and not tutorial_periodic_boundaries and not tutorial_timevaryingdepthdimensions and not tutorial_croco_3D'" # TODO v4: Re-enable `tutorial_periodic_boundaries`, `tutorial_timevaryingdepthdimensions`, and `tutorial_croco_3D` notebooks
49+
tests-notebooks = "pytest -v -s --nbval-lax -k 'not documentation and not tutorial_periodic_boundaries and not tutorial_timevaryingdepthdimensions and not tutorial_croco_3D and not tutorial_nemo_3D'" # TODO v4: Re-enable `tutorial_periodic_boundaries`, `tutorial_timevaryingdepthdimensions`, `tutorial_croco_3D`, `tutorial_nemo_3D` notebooks
5050
coverage = "coverage run -m pytest && coverage html"
5151
typing = "mypy parcels"
5252
pre-commit = "pre-commit run --all-files"

tests/test_grids.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,18 @@ def UpdateR(particle, fieldset, time): # pragma: no cover
873873
assert np.allclose(pset.radius, pset.radius_start, atol=10)
874874

875875

876-
@pytest.mark.parametrize("gridindexingtype", ["mom5"]) # TODO v4: add pop in params?
876+
@pytest.mark.parametrize(
877+
"gridindexingtype",
878+
[
879+
pytest.param(
880+
"mom5",
881+
marks=[
882+
pytest.mark.v4alpha,
883+
pytest.mark.xfail(reason="https://github.com/OceanParcels/Parcels/pull/1936#issuecomment-2717408483"),
884+
],
885+
)
886+
],
887+
) # TODO v4: add pop in params?
877888
@pytest.mark.parametrize("extrapolation", [True, False])
878889
def test_bgrid_interpolation(gridindexingtype, extrapolation):
879890
xi, yi = 3, 2

0 commit comments

Comments
 (0)