diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 75e1a995ba..48042e8da1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,8 +77,9 @@ jobs: environment-file: environment.yml - name: Integration test # TODO v4: Re-enable `tutorial_periodic_boundaries`, `tutorial_timevaryingdepthdimensions` and `tutorial_croco_3D` notebooks + # TODO v4: Re-enable `tutorial_nemo_3D` notebook once 3D grids are implemented (https://github.com/OceanParcels/Parcels/pull/1936#issuecomment-2717666705) run: | - 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 + 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 coverage xml - name: Codecov uses: codecov/codecov-action@v5.3.1 diff --git a/parcels/field.py b/parcels/field.py index e7f122edc5..3c88a76b32 100644 --- a/parcels/field.py +++ b/parcels/field.py @@ -390,13 +390,9 @@ def from_netcdf( ) as filebuffer: filebuffer.name = variable[1] depth = filebuffer.depth - data_full_zdim = filebuffer.data_full_zdim else: indices["depth"] = np.array([0]) depth = np.zeros(1) - data_full_zdim = 1 - - kwargs["data_full_zdim"] = data_full_zdim if len(data_filenames) > 1 and "time" not in dimensions: raise RuntimeError("Multiple files given but no time dimension specified") @@ -421,7 +417,6 @@ def from_netcdf( dimensions, indices, interp_method=interp_method, - data_full_zdim=data_full_zdim, ) as filebuffer: # If Field.from_netcdf is called directly, it may not have a 'data' dimension # In that case, assume that 'name' is the data dimension diff --git a/parcels/fieldfilebuffer.py b/parcels/fieldfilebuffer.py index b817e5c70c..c1a0e7dd12 100644 --- a/parcels/fieldfilebuffer.py +++ b/parcels/fieldfilebuffer.py @@ -17,7 +17,6 @@ def __init__( indices, *, interp_method: InterpMethodOption = "linear", - data_full_zdim=None, gridindexingtype="nemo", ): self.filename: PathLike | list[PathLike] = filename @@ -26,7 +25,6 @@ def __init__( self.dataset = None self.interp_method = interp_method self.gridindexingtype = gridindexingtype - self.data_full_zdim = data_full_zdim def __enter__(self): self.dataset = open_xarray_dataset(self.filename) @@ -58,6 +56,8 @@ def ydim(self): @property def zdim(self): + if "depth" not in self.dimensions: + return 1 depth = self.dataset[self.dimensions["depth"]] zdim = depth.size if len(depth.shape) == 1 else depth.shape[-3] if self.gridindexingtype in ["croco"]: @@ -84,23 +84,14 @@ def latlon(self): @property def depth(self): + self.indices["depth"] = range(self.zdim) if "depth" in self.dimensions: - depth = self.dataset[self.dimensions["depth"]] - self.data_full_zdim = self.zdim - self.indices["depth"] = range(self.zdim) - return depth - else: - self.indices["depth"] = [0] - return np.zeros(1) + return self.dataset[self.dimensions["depth"]] + return np.zeros(1) @property - def depth_dimensions(self): - if "depth" in self.dimensions: - data = self.dataset[self.name] - depthsize = data.shape[-3] - self.data_full_zdim = depthsize - self.indices["depth"] = range(depthsize) - return np.empty((0, self.zdim) + data.shape[-2:]) + def data_full_zdim(self): + return self.zdim def _check_extend_depth(self, data, dim): return ( diff --git a/pyproject.toml b/pyproject.toml index 272cad6a36..ad771f999e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,7 +46,7 @@ platforms = ["win-64", "linux-64", "osx-64", "osx-arm64"] [tool.pixi.tasks] tests = "pytest" -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 +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 coverage = "coverage run -m pytest && coverage html" typing = "mypy parcels" pre-commit = "pre-commit run --all-files" diff --git a/tests/test_grids.py b/tests/test_grids.py index 7a18010b21..59b6537dca 100644 --- a/tests/test_grids.py +++ b/tests/test_grids.py @@ -873,7 +873,18 @@ def UpdateR(particle, fieldset, time): # pragma: no cover assert np.allclose(pset.radius, pset.radius_start, atol=10) -@pytest.mark.parametrize("gridindexingtype", ["mom5"]) # TODO v4: add pop in params? +@pytest.mark.parametrize( + "gridindexingtype", + [ + pytest.param( + "mom5", + marks=[ + pytest.mark.v4alpha, + pytest.mark.xfail(reason="https://github.com/OceanParcels/Parcels/pull/1936#issuecomment-2717408483"), + ], + ) + ], +) # TODO v4: add pop in params? @pytest.mark.parametrize("extrapolation", [True, False]) def test_bgrid_interpolation(gridindexingtype, extrapolation): xi, yi = 3, 2