xgcm icon indicating copy to clipboard operation
xgcm copied to clipboard

validation of input dimensions sizes

Open rabernat opened this issue 7 years ago • 4 comments

It is currently possible to create Grid and Axis objects whose sizes are not compatible with xgcm's data model.

This should not be allowed

>>> ds = xr.Dataset(coords={'x_c': (['x_c',], np.arange(1,10)),
                            'x_g': (['x_g',], np.arange(0.5,9))})
>>> ds
<xarray.Dataset>
Dimensions:  (x_c: 9, x_g: 9)
Coordinates:
  * x_c      (x_c) int64 1 2 3 4 5 6 7 8 9
  * x_g      (x_g) float64 0.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5
Data variables:
    *empty*
>>> grid = Grid(ds, coords={'X': {'center': 'x_c', 'outer': 'x_g'}})
>>> grid
<xgcm.Grid>
X Axis (periodic):
  * center   x_c (9) --> outer
  * outer    x_g (9) --> center

According to our own docs, the outer position should have a length of 10. So this (and all similarly erroneous Grid / Axis creation operations) should raise errors.

rabernat avatar Jul 30 '18 14:07 rabernat

I think this is relevant to #208. We should fix both with one PR.

jbusecke avatar Sep 18 '20 16:09 jbusecke

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

github-actions[bot] avatar Jun 11 '21 12:06 github-actions[bot]

This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.

github-actions[bot] avatar Jun 18 '21 12:06 github-actions[bot]

This definitely needs fixing.

jbusecke avatar Jun 22 '21 23:06 jbusecke