Skip to content

Add checking that Fields have expected number of dimensions when calling an interpolation method #2590

@erikvansebille

Description

@erikvansebille

What version of Parcels are you running?

v4alpha

Is your feature request related to a problem?

Due to a bug in convert.nemo_to_sgrid(), the MOi-benchmark resulted in a DataSet with dimensions (depth: 1, time: 3, x: 4322, y_center: 3059, depth_center: 50, x_center: 4322, y: 3059) and a variable U with dimensions (depth, time, depth_center, y_center, x) (so five dimensions, instead of four)

This then breaks e.g. the interpolator code that expects exactly four dimensions (and in order time, depth, lat, lon) at

tdim, zdim, ydim, xdim = U.shape[0], U.shape[1], U.shape[2], U.shape[3]

Describe the solution you'd like

It would be good to put some guarding in place so that Fields have the expected number of dimensions when passed to an interpolator. Perhaps this can be done with typing?

We could expect users to write interpolators for other numbers of dimensions; so I wouldn't hard-code a check on four dimensions. But a bit more guarding would be useful

Also, perhaps the code in _xinterpolators.py above could be a bit more robust against the order of the dimensions?

Describe alternatives you've considered

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageIssue that has not been reviewed by a Parcels team member

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions