Skip to content

Commit b3dc1e0

Browse files
Also adding support for zarr backend in describe()
1 parent d8aeae0 commit b3dc1e0

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/parcels/_reprs.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import numpy as np
1010
import xarray as xr
11+
import zarr
1112
from dask.base import is_dask_collection
1213

1314
from parcels._core._windowed_array import WindowedArray
@@ -223,6 +224,8 @@ def _field_backend(field: Field | VectorField) -> str | None:
223224
return "WindowedArray"
224225
elif is_dask_collection(field.data.data):
225226
return "Dask"
227+
elif isinstance(field.data.variable._data, zarr.Array):
228+
return "Zarr"
226229
elif isinstance(field.data.data, np.ndarray):
227230
return "NumPy"
228231
else:

tests/test_fieldset.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import pytest
99

1010
import parcels.tutorial
11-
from parcels import Field, ParticleFile, ParticleSet, XGrid, convert
11+
from parcels import Field, ParticleFile, ParticleSet, XGrid, convert, open_raw_zarr
1212
from parcels._core.fieldset import FieldSet, _datetime_to_msg
1313
from parcels._core.model import _default_vector_field_components
1414
from parcels._datasets.structured.generic import datasets as datasets_structured
@@ -420,7 +420,7 @@ def test_fieldset_describe(fieldset_two_models: FieldSet):
420420
assert actual == expected
421421

422422

423-
def test_fieldset_describe_backends():
423+
def test_fieldset_describe_backends(tmp_path):
424424
ds_u = parcels.tutorial.open_dataset("NemoNorthSeaORCA025-N006_data/U")
425425
ds_v = parcels.tutorial.open_dataset("NemoNorthSeaORCA025-N006_data/V")
426426
ds_w = parcels.tutorial.open_dataset("NemoNorthSeaORCA025-N006_data/W")
@@ -462,6 +462,27 @@ def test_fieldset_describe_backends():
462462
| UV | VectorField | 0 | CGrid_Velocity(...) | - |
463463
| UVW | VectorField | 0 | CGrid_Velocity(...) | - |
464464
465+
mesh: spherical
466+
time interval: (np.datetime64('2000-01-02T12:00:00.000000000'), np.datetime64('2000-01-27T12:00:00.000000000'))
467+
"""
468+
fieldset.describe(io)
469+
actual = io.getvalue()
470+
assert actual == expected
471+
472+
path = tmp_path / "ds.zarr"
473+
ds_fset.to_zarr(path)
474+
ds_zarr = open_raw_zarr(path)
475+
fieldset = FieldSet.from_sgrid_conventions(ds_zarr)
476+
io = StringIO()
477+
expected = """\
478+
| Name | Type | Grid number | Interp method / value | Parcels backend |
479+
|:-------|:------------|--------------:|:------------------------|:------------------|
480+
| U | Field | 0 | XLinear(...) | Zarr |
481+
| V | Field | 0 | XLinear(...) | Zarr |
482+
| W | Field | 0 | XLinear(...) | Zarr |
483+
| UV | VectorField | 0 | CGrid_Velocity(...) | - |
484+
| UVW | VectorField | 0 | CGrid_Velocity(...) | - |
485+
465486
mesh: spherical
466487
time interval: (np.datetime64('2000-01-02T12:00:00.000000000'), np.datetime64('2000-01-27T12:00:00.000000000'))
467488
"""

0 commit comments

Comments
 (0)