Skip to content

Commit b7a7d38

Browse files
Moving lon/lat loading to to_windowed_arrays
1 parent f4c3f8d commit b7a7d38

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

src/parcels/_core/model.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import cf_xarray # noqa: F401
88
import uxarray as ux
99
import xarray as xr
10+
from dask import is_dask_collection
1011

1112
import parcels._sgrid as sgrid
1213
import parcels._typing as ptyping
@@ -102,6 +103,10 @@ def to_windowed_arrays(self, *, max_levels: int | None = None) -> Self:
102103
and ``max_levels`` then bounds its size.
103104
"""
104105
windowed = self.__dict__.setdefault("_windowed", {})
106+
for dim in ["lon", "lat", "depth"]:
107+
# ensure lon and lat are loaded into memory for dask-backed datasets
108+
if is_dask_collection(self.data[dim]):
109+
self.data[dim].load()
105110
for name in self.scalar_field_names:
106111
current = windowed.get(name, self.data[name])
107112
windowed[name] = maybe_windowed(current, max_levels=max_levels)

src/parcels/_core/xgrid.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import numpy.typing as npt
88
import xarray as xr
99
import xgcm
10-
from dask import is_dask_collection
1110

1211
import parcels._sgrid as sgrid
1312
import parcels._typing as ptyping
@@ -208,9 +207,6 @@ def lon(self):
208207
_ = self.xgcm_grid.axes["X"]
209208
except KeyError:
210209
return np.zeros(1)
211-
# ensure lon is loaded into memory for dask-backed datasets, as it is used in the search method
212-
if is_dask_collection(self._ds["lon"].data):
213-
self._ds["lon"].load()
214210
return self._ds["lon"].values
215211

216212
@property
@@ -225,9 +221,6 @@ def lat(self):
225221
_ = self.xgcm_grid.axes["Y"]
226222
except KeyError:
227223
return np.zeros(1)
228-
# ensure lat is loaded into memory for dask-backed datasets, as it is used in the search method
229-
if is_dask_collection(self._ds["lat"].data):
230-
self._ds["lat"].load()
231224
return self._ds["lat"].values
232225

233226
@property

0 commit comments

Comments
 (0)