From 89f6b1e952fa7f23dd34d69e013502ac58229232 Mon Sep 17 00:00:00 2001 From: Jemma Jeffree <98864717+jemmajeffree@users.noreply.github.com> Date: Sun, 15 Nov 2026 14:59:45 +1100 Subject: [PATCH 1/8] Allow windowed array to hold a wider window --- src/parcels/_core/_windowed_array.py | 33 +++++++++++++++++++--------- src/parcels/_core/fieldset.py | 4 ++-- src/parcels/_core/model.py | 4 ++-- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/parcels/_core/_windowed_array.py b/src/parcels/_core/_windowed_array.py index f330268af..8d19297f3 100644 --- a/src/parcels/_core/_windowed_array.py +++ b/src/parcels/_core/_windowed_array.py @@ -10,6 +10,7 @@ (``dt > 0``) or backward (``dt < 0``). Eviction keeps only the levels each ``isel`` actually requests, which is symmetric in time -- so direction never enters the logic and no integration-direction flag is needed. + * Time coordinate of U/V data/files is monotonic (ie, grabbing slice(i,i+10) is 10 sequential times) """ from __future__ import annotations @@ -29,12 +30,13 @@ class WindowedArray: """Wrap a lazy DataArray so ``isel`` loads/caches/evicts time levels as NumPy.""" - def __init__(self, data: xr.DataArray, time_dim: str = "time", max_levels: int | None = None): + def __init__(self, data: xr.DataArray, time_dim: str = "time", max_levels: int | None = None, time_chunk: int = 1): if data.dims[0] != time_dim: raise ValueError(f"WindowedArray expects {time_dim!r} as the leading dimension, got {data.dims}") self._data = data self._tdim = time_dim self._max = max_levels + self._tchunk = time_chunk # Let us load a bunch of stuff in at once (e.g. 1 day, or 1 month) self._cache: xr.DataArray = xr.DataArray( np.empty((0, *data.shape[1:]), dtype=data.dtype), dims=data.dims, @@ -43,7 +45,7 @@ def __init__(self, data: xr.DataArray, time_dim: str = "time", max_levels: int | # diagnostics self.loads = 0 self.bytes_read = 0 - self._slab_bytes = int(np.prod(data.isel({time_dim: 0}).shape)) * data.dtype.itemsize + self._slab_bytes = int(np.prod(data.isel({time_dim: 0}).shape)) * data.dtype.itemsize * self._tchunk # If I understand this variable correctly # -- transparency: forward everything we don't override ------------------- def __getattr__(self, name): @@ -57,9 +59,12 @@ def __repr__(self): ) # -- window management ---------------------------------------------------- - def _read_level(self, lvl: int) -> np.ndarray: + def _read_level(self, min_lvl: int, max_lvl: int) -> np.ndarray: """Bulk, sequential read of one time level into NumPy (the dask->NumPy step).""" - return np.asarray(self._data.isel({self._tdim: int(lvl)}).values) + + + #return self._data.isel({self._tdim: slice(min_lvl, min_lvl+self._tchunk)}).compute() # Pass back as an array, and keep new dimensions? + return np.asarray(self._data.isel({self._tdim: slice(min_lvl, max_lvl)}).values) # Concerned there was a reason for using np.asarray though. Using it was messing up putting the old coordinates back on, because we now might have time. def _ensure(self, levels: np.ndarray) -> None: if self._max is not None and levels.size > self._max: @@ -79,8 +84,12 @@ def _ensure(self, levels: np.ndarray) -> None: ) lo, hi = int(np.min(levels)), int(np.max(levels)) + # Expand these out for the full number of chunks we're keeping + lo = lo//self._tchunk * self._tchunk + hi = hi//self._tchunk * self._tchunk + self._tchunk # Suggest using [ ) rather than [ ] sets with a -1? coord = self._cache[self._tdim].values - keep = (coord >= lo) & (coord <= hi) + keep = (coord >= lo) & (coord < hi) + # print(lo, hi) if self._max is not None: cached_in_span = np.flatnonzero(keep) @@ -100,10 +109,14 @@ def _ensure(self, levels: np.ndarray) -> None: if lvl in self._cache[self._tdim].values: continue - slab = self._read_level(lvl) + # What are the bounds of the chunk that this lvl goes into? + min_lvl = lvl//self._tchunk * self._tchunk + max_lvl = min(min_lvl+self._tchunk, len(self._data[self._tdim])) # pretty sure this is fine but would appreciate a second pair of eyes for off-by-one errors and not grabbing the end of the array + # print(min_lvl,max_lvl) + slab = self._read_level(min_lvl,max_lvl) # I've changed read_level to return an xarray dataset wrapped around numpy arrays self.loads += 1 self.bytes_read += self._slab_bytes - slab_as_xr = xr.DataArray(slab[None], dims=self._data.dims, coords={self._tdim: [lvl]}) + slab_as_xr = xr.DataArray(slab, dims=self._data.dims, coords={self._tdim: np.arange(min_lvl,max_lvl,dtype=int)}) #Turns out the numpy wrapper is about throwing away bonus coordinates. Fair # Have replaced slab[None] with slab because read_level now keeps dimensions with the slice # The cache is ordered based on time index coord = self._cache[self._tdim].values @@ -112,7 +125,7 @@ def _ensure(self, levels: np.ndarray) -> None: self._cache = xr.concat( [ self._cache.isel({self._tdim: slice(0, pos)}), - slab_as_xr, + slab_as_xr, # With modified _read_level to give multiple timesteps at once this is multiple timesteps, but .concat should still be fine self._cache.isel({self._tdim: slice(pos, None)}), ], dim=self._tdim, @@ -146,7 +159,7 @@ def isel(self, indexers: dict | None = None, **kwargs): return self._cache.isel(sel) # return the requested isel directly from the cached DataArray -def maybe_windowed(data: xr.DataArray, max_levels: int | None = None): +def maybe_windowed(data: xr.DataArray, max_levels: int | None = None, time_chunk: int = 1): """Wrap dask-backed, field data in a ``WindowedArray``; else pass through. NumPy-backed fields (already resident) and fields without a leading ``time`` @@ -156,7 +169,7 @@ def maybe_windowed(data: xr.DataArray, max_levels: int | None = None): if isinstance(data, WindowedArray): return data if data.dims and data.dims[0] == "time" and is_dask_collection(data.data): - return WindowedArray(data, max_levels=max_levels) + return WindowedArray(data, max_levels=max_levels, time_chunk=time_chunk) elif data.dims and data.dims[0] == "mockT" and is_dask_collection(data.data): return data.compute() return data diff --git a/src/parcels/_core/fieldset.py b/src/parcels/_core/fieldset.py index c87575ae5..2b526d8b4 100644 --- a/src/parcels/_core/fieldset.py +++ b/src/parcels/_core/fieldset.py @@ -161,7 +161,7 @@ def time_interval(self): return overlap - def to_windowed_arrays(self, *, max_levels: int | None = None): + def to_windowed_arrays(self, *, max_levels: int | None = None, time_chunk: int = 1): """Wrap dask-backed field data in rolling time-window caches. Opt-in optimization for forward-marching simulations where all particles @@ -191,7 +191,7 @@ def to_windowed_arrays(self, *, max_levels: int | None = None): ``self``, to allow chaining. """ for model in self.models: - model.to_windowed_arrays(max_levels=max_levels) + model.to_windowed_arrays(max_levels=max_levels, time_chunk=time_chunk) return self def to_chunk_cached_arrays(self, *, max_cache_bytes: int = 600_000_000): diff --git a/src/parcels/_core/model.py b/src/parcels/_core/model.py index e1c44de30..6b876f5ab 100644 --- a/src/parcels/_core/model.py +++ b/src/parcels/_core/model.py @@ -84,7 +84,7 @@ def field_data(self, name: str) -> Any: return windowed[name] return self.data[name] - def to_windowed_arrays(self, *, max_levels: int | None = None) -> Self: + def to_windowed_arrays(self, *, max_levels: int | None = None, time_chunk: int = 1) -> Self: """Wrap dask-backed field data in rolling time-window caches. Opt-in optimization for forward-marching simulations where all particles @@ -117,7 +117,7 @@ def to_windowed_arrays(self, *, max_levels: int | None = None) -> Self: self.data[dim].load() for name in self.scalar_field_names: current = windowed.get(name, self.data[name]) - windowed[name] = maybe_windowed(current, max_levels=max_levels) + windowed[name] = maybe_windowed(current, max_levels=max_levels, time_chunk=time_chunk) return self def to_chunk_cached_arrays(self, *, max_cache_bytes: int = 600_000_000) -> Self: From 31bf4e34a3aba9f226b1302fd98ccb519e571116 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 15 Nov 2026 04:49:25 +0000 Subject: [PATCH 2/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/parcels/_core/_windowed_array.py | 36 +++++++++++++++++----------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/parcels/_core/_windowed_array.py b/src/parcels/_core/_windowed_array.py index 8d19297f3..7c230169c 100644 --- a/src/parcels/_core/_windowed_array.py +++ b/src/parcels/_core/_windowed_array.py @@ -36,7 +36,7 @@ def __init__(self, data: xr.DataArray, time_dim: str = "time", max_levels: int | self._data = data self._tdim = time_dim self._max = max_levels - self._tchunk = time_chunk # Let us load a bunch of stuff in at once (e.g. 1 day, or 1 month) + self._tchunk = time_chunk # Let us load a bunch of stuff in at once (e.g. 1 day, or 1 month) self._cache: xr.DataArray = xr.DataArray( np.empty((0, *data.shape[1:]), dtype=data.dtype), dims=data.dims, @@ -45,7 +45,9 @@ def __init__(self, data: xr.DataArray, time_dim: str = "time", max_levels: int | # diagnostics self.loads = 0 self.bytes_read = 0 - self._slab_bytes = int(np.prod(data.isel({time_dim: 0}).shape)) * data.dtype.itemsize * self._tchunk # If I understand this variable correctly + self._slab_bytes = ( + int(np.prod(data.isel({time_dim: 0}).shape)) * data.dtype.itemsize * self._tchunk + ) # If I understand this variable correctly # -- transparency: forward everything we don't override ------------------- def __getattr__(self, name): @@ -61,10 +63,10 @@ def __repr__(self): # -- window management ---------------------------------------------------- def _read_level(self, min_lvl: int, max_lvl: int) -> np.ndarray: """Bulk, sequential read of one time level into NumPy (the dask->NumPy step).""" - - - #return self._data.isel({self._tdim: slice(min_lvl, min_lvl+self._tchunk)}).compute() # Pass back as an array, and keep new dimensions? - return np.asarray(self._data.isel({self._tdim: slice(min_lvl, max_lvl)}).values) # Concerned there was a reason for using np.asarray though. Using it was messing up putting the old coordinates back on, because we now might have time. + # return self._data.isel({self._tdim: slice(min_lvl, min_lvl+self._tchunk)}).compute() # Pass back as an array, and keep new dimensions? + return np.asarray( + self._data.isel({self._tdim: slice(min_lvl, max_lvl)}).values + ) # Concerned there was a reason for using np.asarray though. Using it was messing up putting the old coordinates back on, because we now might have time. def _ensure(self, levels: np.ndarray) -> None: if self._max is not None and levels.size > self._max: @@ -85,8 +87,8 @@ def _ensure(self, levels: np.ndarray) -> None: lo, hi = int(np.min(levels)), int(np.max(levels)) # Expand these out for the full number of chunks we're keeping - lo = lo//self._tchunk * self._tchunk - hi = hi//self._tchunk * self._tchunk + self._tchunk # Suggest using [ ) rather than [ ] sets with a -1? + lo = lo // self._tchunk * self._tchunk + hi = hi // self._tchunk * self._tchunk + self._tchunk # Suggest using [ ) rather than [ ] sets with a -1? coord = self._cache[self._tdim].values keep = (coord >= lo) & (coord < hi) # print(lo, hi) @@ -109,14 +111,20 @@ def _ensure(self, levels: np.ndarray) -> None: if lvl in self._cache[self._tdim].values: continue - # What are the bounds of the chunk that this lvl goes into? - min_lvl = lvl//self._tchunk * self._tchunk - max_lvl = min(min_lvl+self._tchunk, len(self._data[self._tdim])) # pretty sure this is fine but would appreciate a second pair of eyes for off-by-one errors and not grabbing the end of the array + # What are the bounds of the chunk that this lvl goes into? + min_lvl = lvl // self._tchunk * self._tchunk + max_lvl = min( + min_lvl + self._tchunk, len(self._data[self._tdim]) + ) # pretty sure this is fine but would appreciate a second pair of eyes for off-by-one errors and not grabbing the end of the array # print(min_lvl,max_lvl) - slab = self._read_level(min_lvl,max_lvl) # I've changed read_level to return an xarray dataset wrapped around numpy arrays + slab = self._read_level( + min_lvl, max_lvl + ) # I've changed read_level to return an xarray dataset wrapped around numpy arrays self.loads += 1 self.bytes_read += self._slab_bytes - slab_as_xr = xr.DataArray(slab, dims=self._data.dims, coords={self._tdim: np.arange(min_lvl,max_lvl,dtype=int)}) #Turns out the numpy wrapper is about throwing away bonus coordinates. Fair # Have replaced slab[None] with slab because read_level now keeps dimensions with the slice + slab_as_xr = xr.DataArray( + slab, dims=self._data.dims, coords={self._tdim: np.arange(min_lvl, max_lvl, dtype=int)} + ) # Turns out the numpy wrapper is about throwing away bonus coordinates. Fair # Have replaced slab[None] with slab because read_level now keeps dimensions with the slice # The cache is ordered based on time index coord = self._cache[self._tdim].values @@ -125,7 +133,7 @@ def _ensure(self, levels: np.ndarray) -> None: self._cache = xr.concat( [ self._cache.isel({self._tdim: slice(0, pos)}), - slab_as_xr, # With modified _read_level to give multiple timesteps at once this is multiple timesteps, but .concat should still be fine + slab_as_xr, # With modified _read_level to give multiple timesteps at once this is multiple timesteps, but .concat should still be fine self._cache.isel({self._tdim: slice(pos, None)}), ], dim=self._tdim, From f25c2e476e48e8bd5919ae146201bf6b96f8bdf5 Mon Sep 17 00:00:00 2001 From: Jemma Jeffree <98864717+jemmajeffree@users.noreply.github.com> Date: Sun, 15 Nov 2026 16:02:26 +1100 Subject: [PATCH 3/8] Add some documentation --- src/parcels/_core/_windowed_array.py | 8 +++----- src/parcels/_core/fieldset.py | 7 +++++++ src/parcels/_core/model.py | 7 +++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/parcels/_core/_windowed_array.py b/src/parcels/_core/_windowed_array.py index 8d19297f3..268839757 100644 --- a/src/parcels/_core/_windowed_array.py +++ b/src/parcels/_core/_windowed_array.py @@ -60,11 +60,9 @@ def __repr__(self): # -- window management ---------------------------------------------------- def _read_level(self, min_lvl: int, max_lvl: int) -> np.ndarray: - """Bulk, sequential read of one time level into NumPy (the dask->NumPy step).""" + """Bulk, sequential read of self._tchunk time levels into NumPy (the dask->NumPy step).""" - - #return self._data.isel({self._tdim: slice(min_lvl, min_lvl+self._tchunk)}).compute() # Pass back as an array, and keep new dimensions? - return np.asarray(self._data.isel({self._tdim: slice(min_lvl, max_lvl)}).values) # Concerned there was a reason for using np.asarray though. Using it was messing up putting the old coordinates back on, because we now might have time. + return np.asarray(self._data.isel({self._tdim: slice(min_lvl, max_lvl)}).values) def _ensure(self, levels: np.ndarray) -> None: if self._max is not None and levels.size > self._max: @@ -116,7 +114,7 @@ def _ensure(self, levels: np.ndarray) -> None: slab = self._read_level(min_lvl,max_lvl) # I've changed read_level to return an xarray dataset wrapped around numpy arrays self.loads += 1 self.bytes_read += self._slab_bytes - slab_as_xr = xr.DataArray(slab, dims=self._data.dims, coords={self._tdim: np.arange(min_lvl,max_lvl,dtype=int)}) #Turns out the numpy wrapper is about throwing away bonus coordinates. Fair # Have replaced slab[None] with slab because read_level now keeps dimensions with the slice + slab_as_xr = xr.DataArray(slab, dims=self._data.dims, coords={self._tdim: np.arange(min_lvl,max_lvl,dtype=int)}) # Have replaced slab[None] with slab because read_level now keeps dimensions with the slice # The cache is ordered based on time index coord = self._cache[self._tdim].values diff --git a/src/parcels/_core/fieldset.py b/src/parcels/_core/fieldset.py index 2b526d8b4..9c49aff4d 100644 --- a/src/parcels/_core/fieldset.py +++ b/src/parcels/_core/fieldset.py @@ -185,6 +185,13 @@ def to_windowed_arrays(self, *, max_levels: int | None = None, time_chunk: int = spread across many time levels) does the window grow beyond that, and ``max_levels`` then bounds its size. + time_chunk: int, optional + The number of timesteps to be called into memory each time another + time level is needed. If using dask, this should be at least the + chunksize used by xr.open_(mf)dataset times the number of cores, + but should be a number of timesteps that takes less than half the + available memory. + Returns ------- FieldSet diff --git a/src/parcels/_core/model.py b/src/parcels/_core/model.py index 6b876f5ab..fb0ee0f18 100644 --- a/src/parcels/_core/model.py +++ b/src/parcels/_core/model.py @@ -109,6 +109,13 @@ def to_windowed_arrays(self, *, max_levels: int | None = None, time_chunk: int = Only when a single call requests a wider time span (e.g. particles spread across many time levels) does the window grow beyond that, and ``max_levels`` then bounds its size. + + time_chunk: int, optional + The number of timesteps to be called into memory each time another + time level is needed. If using dask, this should be at least the + chunksize used by xr.open_(mf)dataset times the number of cores, + but should be a number of timesteps that takes less than half the + available memory. """ windowed = self.__dict__.setdefault("_windowed", {}) for dim in ["lon", "lat", "depth"]: From e80bb49a4d81aa34821c5df22b3337def8310646 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 15 Nov 2026 05:07:25 +0000 Subject: [PATCH 4/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/parcels/_core/fieldset.py | 4 ++-- src/parcels/_core/model.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/parcels/_core/fieldset.py b/src/parcels/_core/fieldset.py index 9c49aff4d..a0d325c0f 100644 --- a/src/parcels/_core/fieldset.py +++ b/src/parcels/_core/fieldset.py @@ -187,8 +187,8 @@ def to_windowed_arrays(self, *, max_levels: int | None = None, time_chunk: int = time_chunk: int, optional The number of timesteps to be called into memory each time another - time level is needed. If using dask, this should be at least the - chunksize used by xr.open_(mf)dataset times the number of cores, + time level is needed. If using dask, this should be at least the + chunksize used by xr.open_(mf)dataset times the number of cores, but should be a number of timesteps that takes less than half the available memory. diff --git a/src/parcels/_core/model.py b/src/parcels/_core/model.py index fb0ee0f18..cc5fd666f 100644 --- a/src/parcels/_core/model.py +++ b/src/parcels/_core/model.py @@ -112,8 +112,8 @@ def to_windowed_arrays(self, *, max_levels: int | None = None, time_chunk: int = time_chunk: int, optional The number of timesteps to be called into memory each time another - time level is needed. If using dask, this should be at least the - chunksize used by xr.open_(mf)dataset times the number of cores, + time level is needed. If using dask, this should be at least the + chunksize used by xr.open_(mf)dataset times the number of cores, but should be a number of timesteps that takes less than half the available memory. """ From 7447c8abcdb89a843c5b80f96bd211a9d00f6d1b Mon Sep 17 00:00:00 2001 From: Jemma Jeffree <98864717+jemmajeffree@users.noreply.github.com> Date: Sun, 15 Nov 2026 16:07:50 +1100 Subject: [PATCH 5/8] Fix another merge conflict from hooks --- src/parcels/_core/_windowed_array.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/parcels/_core/_windowed_array.py b/src/parcels/_core/_windowed_array.py index 6e0111795..acf11965a 100644 --- a/src/parcels/_core/_windowed_array.py +++ b/src/parcels/_core/_windowed_array.py @@ -122,14 +122,9 @@ def _ensure(self, levels: np.ndarray) -> None: ) # I've changed read_level to return an xarray dataset wrapped around numpy arrays self.loads += 1 self.bytes_read += self._slab_bytes -<<<<<<< HEAD - slab_as_xr = xr.DataArray(slab, dims=self._data.dims, coords={self._tdim: np.arange(min_lvl,max_lvl,dtype=int)}) # Have replaced slab[None] with slab because read_level now keeps dimensions with the slice -======= slab_as_xr = xr.DataArray( slab, dims=self._data.dims, coords={self._tdim: np.arange(min_lvl, max_lvl, dtype=int)} - ) # Turns out the numpy wrapper is about throwing away bonus coordinates. Fair # Have replaced slab[None] with slab because read_level now keeps dimensions with the slice ->>>>>>> 31bf4e34a3aba9f226b1302fd98ccb519e571116 - + ) # Have replaced slab[None] with slab because read_level now keeps dimensions with the slice # The cache is ordered based on time index coord = self._cache[self._tdim].values pos = int(np.searchsorted(coord, lvl)) From 1a37402f6cdfefd08de9b315a962da95346f7968 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 15 Nov 2026 05:09:48 +0000 Subject: [PATCH 6/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/parcels/_core/_windowed_array.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/parcels/_core/_windowed_array.py b/src/parcels/_core/_windowed_array.py index acf11965a..8930cc805 100644 --- a/src/parcels/_core/_windowed_array.py +++ b/src/parcels/_core/_windowed_array.py @@ -63,10 +63,7 @@ def __repr__(self): # -- window management ---------------------------------------------------- def _read_level(self, min_lvl: int, max_lvl: int) -> np.ndarray: """Bulk, sequential read of self._tchunk time levels into NumPy (the dask->NumPy step).""" - - return np.asarray( - self._data.isel({self._tdim: slice(min_lvl, max_lvl)}).values - ) + return np.asarray(self._data.isel({self._tdim: slice(min_lvl, max_lvl)}).values) def _ensure(self, levels: np.ndarray) -> None: if self._max is not None and levels.size > self._max: From a5ccf79a41afe6fc19496e7dbc4bec3032d318d1 Mon Sep 17 00:00:00 2001 From: Jemma Jeffree <98864717+jemmajeffree@users.noreply.github.com> Date: Sun, 15 Nov 2026 16:26:30 +1100 Subject: [PATCH 7/8] Tidy up comments --- src/parcels/_core/_windowed_array.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/parcels/_core/_windowed_array.py b/src/parcels/_core/_windowed_array.py index 8930cc805..324ee909d 100644 --- a/src/parcels/_core/_windowed_array.py +++ b/src/parcels/_core/_windowed_array.py @@ -88,7 +88,6 @@ def _ensure(self, levels: np.ndarray) -> None: hi = hi // self._tchunk * self._tchunk + self._tchunk # Suggest using [ ) rather than [ ] sets with a -1? coord = self._cache[self._tdim].values keep = (coord >= lo) & (coord < hi) - # print(lo, hi) if self._max is not None: cached_in_span = np.flatnonzero(keep) @@ -113,10 +112,9 @@ def _ensure(self, levels: np.ndarray) -> None: max_lvl = min( min_lvl + self._tchunk, len(self._data[self._tdim]) ) # pretty sure this is fine but would appreciate a second pair of eyes for off-by-one errors and not grabbing the end of the array - # print(min_lvl,max_lvl) slab = self._read_level( min_lvl, max_lvl - ) # I've changed read_level to return an xarray dataset wrapped around numpy arrays + ) self.loads += 1 self.bytes_read += self._slab_bytes slab_as_xr = xr.DataArray( From 40afceaa19ce67daacdcb5114b73491cca400aa8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 15 Nov 2026 05:26:52 +0000 Subject: [PATCH 8/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/parcels/_core/_windowed_array.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/parcels/_core/_windowed_array.py b/src/parcels/_core/_windowed_array.py index 324ee909d..3bb5b065b 100644 --- a/src/parcels/_core/_windowed_array.py +++ b/src/parcels/_core/_windowed_array.py @@ -112,9 +112,7 @@ def _ensure(self, levels: np.ndarray) -> None: max_lvl = min( min_lvl + self._tchunk, len(self._data[self._tdim]) ) # pretty sure this is fine but would appreciate a second pair of eyes for off-by-one errors and not grabbing the end of the array - slab = self._read_level( - min_lvl, max_lvl - ) + slab = self._read_level(min_lvl, max_lvl) self.loads += 1 self.bytes_read += self._slab_bytes slab_as_xr = xr.DataArray(