Skip to content

Commit 429d3ae

Browse files
Merge pull request #1835 from OceanParcels/fix_croco_multifiles_csw
Support for Fields in multiple files without a `time` dimension
2 parents 4603797 + 16c249c commit 429d3ae

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

parcels/field.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -691,12 +691,17 @@ def from_netcdf(
691691
if grid is None:
692692
# Concatenate time variable to determine overall dimension
693693
# across multiple files
694-
time, time_origin, timeslices, dataFiles = cls._collect_timeslices(
695-
timestamps, data_filenames, _grid_fb_class, dimensions, indices, netcdf_engine
696-
)
697-
grid = Grid.create_grid(lon, lat, depth, time, time_origin=time_origin, mesh=mesh)
698-
grid.timeslices = timeslices
699-
kwargs["dataFiles"] = dataFiles
694+
if "time" in dimensions or timestamps is not None:
695+
time, time_origin, timeslices, dataFiles = cls._collect_timeslices(
696+
timestamps, data_filenames, _grid_fb_class, dimensions, indices, netcdf_engine
697+
)
698+
grid = Grid.create_grid(lon, lat, depth, time, time_origin=time_origin, mesh=mesh)
699+
grid.timeslices = timeslices
700+
kwargs["dataFiles"] = dataFiles
701+
else: # e.g. for the CROCO CS_w field, see https://github.com/OceanParcels/Parcels/issues/1831
702+
grid = Grid.create_grid(lon, lat, depth, np.array([0.0]), time_origin=TimeConverter(0.0), mesh=mesh)
703+
grid.timeslices = [[0]]
704+
data_filenames = [data_filenames[0]]
700705
elif grid is not None and ("dataFiles" not in kwargs or kwargs["dataFiles"] is None):
701706
# ==== means: the field has a shared grid, but may have different data files, so we need to collect the
702707
# ==== correct file time series again.

0 commit comments

Comments
 (0)