Skip to content

Commit 1f63b30

Browse files
Implementing changes suggested by @delandmeterp
1 parent 6fdb801 commit 1f63b30

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

parcels/field.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ class Field(object):
5050
(i.e. beyond the last available time snapshot)
5151
:param time_periodic: boolean whether to loop periodically over the time component of the Field
5252
This flag overrides the allow_time_interpolation and sets it to False
53-
:param netcdf_engine: engine to use for netcdf reading in xarray. Default is 'netcdf',
54-
but in cases where this doesn't work, setting netcdf_engine='scipy' could help
5553
"""
5654

5755
def __init__(self, name, data, lon=None, lat=None, depth=None, time=None, grid=None, mesh='flat',
@@ -150,6 +148,8 @@ def from_netcdf(cls, filenames, variable, dimensions, indices=None, grid=None,
150148
It is advised not to fully load the data, since in that case Parcels deals with
151149
a better memory management during particle set execution.
152150
full_load is however sometimes necessary for plotting the fields.
151+
:param netcdf_engine: engine to use for netcdf reading in xarray. Default is 'netcdf',
152+
but in cases where this doesn't work, setting netcdf_engine='scipy' could help
153153
"""
154154

155155
if not isinstance(filenames, Iterable) or isinstance(filenames, str):
@@ -202,7 +202,6 @@ def from_netcdf(cls, filenames, variable, dimensions, indices=None, grid=None,
202202
grid = CurvilinearSGrid(lon, lat, depth, time, time_origin=time_origin, mesh=mesh)
203203
grid.timeslices = timeslices
204204
kwargs['dataFiles'] = dataFiles
205-
kwargs['netcdf_engine'] = netcdf_engine
206205

207206
if 'time' in indices:
208207
logger.warning_once('time dimension in indices is not necessary anymore. It is then ignored.')
@@ -238,6 +237,7 @@ def from_netcdf(cls, filenames, variable, dimensions, indices=None, grid=None,
238237
kwargs['dimensions'] = dimensions.copy()
239238
kwargs['indices'] = indices
240239
kwargs['time_periodic'] = time_periodic
240+
kwargs['netcdf_engine'] = netcdf_engine
241241

242242
return cls(variable, data, grid=grid,
243243
allow_time_extrapolation=allow_time_extrapolation, **kwargs)
@@ -1151,8 +1151,8 @@ def parse_name(self, dimensions, variable):
11511151

11521152
@property
11531153
def read_lonlat(self):
1154-
lon = getattr(self.dataset, self.dimensions['lon'])
1155-
lat = getattr(self.dataset, self.dimensions['lat'])
1154+
lon = self.dataset[self.dimensions['lon']]
1155+
lat = self.dataset[self.dimensions['lat']]
11561156
xdim = lon.size if len(lon.shape) == 1 else lon.shape[-1]
11571157
ydim = lat.size if len(lat.shape) == 1 else lat.shape[-2]
11581158
self.indices['lon'] = self.indices['lon'] if 'lon' in self.indices else range(xdim)
@@ -1180,7 +1180,7 @@ def read_lonlat(self):
11801180
@property
11811181
def read_depth(self):
11821182
if 'depth' in self.dimensions:
1183-
depth = getattr(self.dataset, self.dimensions['depth'])
1183+
depth = self.dataset[self.dimensions['depth']]
11841184
depthsize = depth.size if len(depth.shape) == 1 else depth.shape[-3]
11851185
self.indices['depth'] = self.indices['depth'] if 'depth' in self.indices else range(depthsize)
11861186
if len(depth.shape) == 1:
@@ -1196,7 +1196,7 @@ def read_depth(self):
11961196

11971197
@property
11981198
def data(self):
1199-
data = getattr(self.dataset, self.name)
1199+
data = self.dataset[self.name]
12001200
if len(data.shape) == 2:
12011201
data = data[self.indices['lat'], self.indices['lon']]
12021202
elif len(data.shape) == 3:
@@ -1222,7 +1222,7 @@ def time(self):
12221222
time_da.attrs['units'] = time_da.attrs['Unit']
12231223
ds = xr.Dataset({self.dimensions['time']: time_da})
12241224
ds = xr.decode_cf(ds)
1225-
da = getattr(ds, self.dimensions['time'])
1225+
da = ds[self.dimensions['time']]
12261226
time = np.array([da]) if len(da.shape) == 0 else np.array(da)
12271227
if isinstance(time[0], datetime.datetime):
12281228
raise NotImplementedError('Parcels currently only parses dates ranging from 1678 AD to 2262 AD, which are stored by xarray as np.datetime64. If you need a wider date range, please open an Issue on the parcels github page.')

parcels/fieldset.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ def from_netcdf(cls, filenames, variables, dimensions, indices=None,
173173
It is advised not to fully load the data, since in that case Parcels deals with
174174
a better memory management during particle set execution.
175175
full_load is however sometimes necessary for plotting the fields.
176+
:param netcdf_engine: engine to use for netcdf reading in xarray. Default is 'netcdf',
177+
but in cases where this doesn't work, setting netcdf_engine='scipy' could help
176178
"""
177179

178180
fields = {}

0 commit comments

Comments
 (0)