Skip to content

Commit b56aed0

Browse files
Adding TypeError when FieldSet.from_c_grid_datatset called with interp_method
Also added unit test.
1 parent c7504ad commit b56aed0

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

parcels/fieldset.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,8 @@ def from_c_grid_dataset(cls, filenames, variables, dimensions, indices=None, mes
587587
if 'U' in dimensions and 'W' in dimensions and dimensions['U'] != dimensions['W']:
588588
raise ValueError("On a C-grid, the dimensions of velocities should be the corners (f-points) of the cells, so the same for U, V and W. "
589589
"See also https://nbviewer.jupyter.org/github/OceanParcels/parcels/blob/master/parcels/examples/documentation_indexing.ipynb")
590+
if 'interp_method' in kwargs.keys():
591+
raise TypeError("On a C-grid, the interpolation method for velocities should not be overridden")
590592

591593
interp_method = {}
592594
for v in variables:

tests/test_fieldset.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,23 @@ def test_field_from_netcdf_fieldtypes():
172172
assert isinstance(fset.varU.units, GeographicPolar)
173173

174174

175+
def test_fieldset_from_cgrid_interpmethod():
176+
data_path = path.join(path.dirname(__file__), 'test_data/')
177+
178+
filenames = {'lon': data_path + 'mask_nemo_cross_180lon.nc',
179+
'lat': data_path + 'mask_nemo_cross_180lon.nc',
180+
'data': data_path + 'Uu_eastward_nemo_cross_180lon.nc'}
181+
variable = 'U'
182+
dimensions = {'lon': 'glamf', 'lat': 'gphif'}
183+
failed = False
184+
try:
185+
# should fail because FieldSet.from_c_grid_dataset does not support interp_method
186+
FieldSet.from_c_grid_dataset(filenames, variable, dimensions, interp_method='partialslip')
187+
except TypeError:
188+
failed = True
189+
assert failed
190+
191+
175192
@pytest.mark.parametrize('indslon', [range(10, 20), [1]])
176193
@pytest.mark.parametrize('indslat', [range(30, 60), [22]])
177194
def test_fieldset_from_file_subsets(indslon, indslat, tmpdir, filename='test_subsets'):

0 commit comments

Comments
 (0)