Skip to content

Commit e006cb2

Browse files
authored
Merge pull request #437 from OceanParcels/indices_debug
field.from_netcdf: indices argument in read-only
2 parents 1a4251c + 2917b1b commit e006cb2

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

parcels/field.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ def from_netcdf(cls, filenames, variable, dimensions, indices=None, grid=None,
152152
if not isinstance(filenames, Iterable) or isinstance(filenames, str):
153153
filenames = [filenames]
154154
dimension_filename = dimension_filename if dimension_filename else filenames[0]
155-
if indices is None:
156-
indices = {}
155+
indices = {} if indices is None else indices.copy()
157156
with NetcdfFileBuffer(dimension_filename, dimensions, indices) as filebuffer:
158157
lon, lat = filebuffer.read_lonlat
159158
depth = filebuffer.read_depth

tests/test_fieldset.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ def test_fieldset_from_file_subsets(indslon, indslat, tmpdir, filename='test_sub
9292
fieldsetfull = FieldSet.from_data(data, dimensions)
9393
fieldsetfull.write(filepath)
9494
indices = {'lon': indslon, 'lat': indslat}
95+
indices_back = indices.copy()
9596
fieldsetsub = FieldSet.from_parcels(filepath, indices=indices)
97+
assert indices == indices_back
9698
assert np.allclose(fieldsetsub.U.lon, fieldsetfull.U.grid.lon[indices['lon']])
9799
assert np.allclose(fieldsetsub.U.lat, fieldsetfull.U.grid.lat[indices['lat']])
98100
assert np.allclose(fieldsetsub.V.lon, fieldsetfull.V.grid.lon[indices['lon']])

0 commit comments

Comments
 (0)