Skip to content

Commit

Permalink
Merge pull request #1733 from OceanParcels/bugfix_loaded_time_indices
Browse files Browse the repository at this point in the history
Fixing loaded_time_indices to support more advanced compute() functions
  • Loading branch information
erikvansebille authored Oct 22, 2024
2 parents aa716e4 + e7d818a commit bf615f8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion parcels/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def __init__(
else:
raise ValueError("Unsupported mesh type. Choose either: 'spherical' or 'flat'")
self.timestamps = timestamps
self._loaded_time_indices: Iterable[int] = [] # type: ignore
if isinstance(interp_method, dict):
if self.name in interp_method:
self.interp_method = interp_method[self.name]
Expand Down Expand Up @@ -265,6 +266,7 @@ def __init__(

if not self.grid.defer_load:
self.data = self._reshape(self.data, transpose)
self._loaded_time_indices = range(self.grid.tdim)

# Hack around the fact that NaN and ridiculously large values
# propagate in SciPy's interpolators
Expand All @@ -288,7 +290,6 @@ def __init__(
self._dataFiles = np.append(self._dataFiles, self._dataFiles[0])
self._field_fb_class = kwargs.pop("FieldFileBuffer", None)
self._netcdf_engine = kwargs.pop("netcdf_engine", "netcdf4")
self._loaded_time_indices: Iterable[int] = [] # type: ignore
self._creation_log = kwargs.pop("creation_log", "")
self.chunksize = kwargs.pop("chunksize", None)
self.netcdf_chunkdims_name_map = kwargs.pop("chunkdims_name_map", None)
Expand Down
1 change: 1 addition & 0 deletions parcels/fieldset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1538,6 +1538,7 @@ def computeTimeChunk(self, time=0.0, dt=1):
for f in self.get_fields():
if isinstance(f, (VectorField, NestedField)) or not f.grid.defer_load or f._dataFiles is None:
continue
f._loaded_time_indices = [] # reset loaded time indices
g = f.grid
if g._update_status == "first_updated": # First load of data
if f.data is not None and not isinstance(f.data, DeferredArray):
Expand Down

0 comments on commit bf615f8

Please sign in to comment.