Skip to content

Commit ea00c4d

Browse files
Adding an error message to Field.from_netcdf() when dimensions are not in correct order
This fixes #1180
1 parent dd3ba5b commit ea00c4d

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

parcels/field.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,13 @@ def from_netcdf(cls, filenames, variable, dimensions, indices=None, grid=None,
427427
# In that case, assume that 'name' is the data dimension
428428
filebuffer.name = filebuffer.parse_name(variable[1])
429429
buffer_data = filebuffer.data
430+
if len(buffer_data.shape) == 4:
431+
errormessage = ('Field %s expecting a data shape of [tdim, zdim, ydim, xdim]. '
432+
'Flag transpose=True could help to reorder the data.' % filebuffer.name)
433+
assert buffer_data.shape[0] == grid.tdim, errormessage
434+
assert buffer_data.shape[2] == grid.ydim - 2 * grid.meridional_halo, errormessage
435+
assert buffer_data.shape[3] == grid.xdim - 2 * grid.zonal_halo, errormessage
436+
430437
if len(buffer_data.shape) == 2:
431438
data_list.append(buffer_data.reshape(sum(((len(tslice), 1), buffer_data.shape), ())))
432439
elif len(buffer_data.shape) == 3:

0 commit comments

Comments
 (0)