Skip to content

convert.mitgcm_to_sgrid breaks on datasets_circulation_models["ds_MITgcm_netcdf"] #2484

Description

@erikvansebille

As mentioned, in #2483, the following code currently breaks:

ds = datasets_circulation_models["ds_MITgcm_netcdf"]
ds = ds.rename({"X": "XG", "Y": "YG", "Z": "depth", "T": "time"})
coords = ds[["XG", "YG", "depth", "time"]]

ds = convert.mitgcm_to_sgrid(fields={"U": ds["U"], "V": ds["V"]}, coords=coords)
fieldset = parcels.FieldSet.from_sgrid_conventions(ds)

with error

    def test_convert_mitgcm_offsets():
        ds = datasets_circulation_models["ds_MITgcm_netcdf"]
        ds = ds.rename({"X": "XG", "Y": "YG", "Z": "depth", "T": "time"})
        coords = ds[["XG", "YG", "depth", "time"]]
    
        ds = convert.mitgcm_to_sgrid(fields={"U": ds["U"], "V": ds["V"]}, coords=coords)
>       fieldset = parcels.FieldSet.from_sgrid_conventions(ds)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/test_convert.py:50: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/parcels/_core/fieldset.py:311: in from_sgrid_conventions
    fields["U"] = Field("U", ds["U"], grid, XLinear)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/parcels/_core/field.py:106: in __init__
    assert_all_field_dims_have_axis(data, grid.xgcm_grid)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

da = <xarray.DataArray 'U' (time: 13, depth: 90, lat: 60, Xp1: 31)> Size: 9MB
array([[[[0.8566365 , 0.50562197, 0.5710538 ,... 248B 0.0 136.7 273.3 ... 3.827e+03 3.963e+03 4.1e+03
Attributes:
    units:        m/s
    coordinates:  XU YU RC iter
xgcm_grid = <xgcm.Grid>
X Axis (not periodic, boundary='fill'):
  * left     lon
Y Axis (not periodic, boundary='fill'):
  * left ...'):
  * center   depth --> left
  * left     depth --> center
T Axis (not periodic, boundary='fill'):
  * center   time

    def assert_all_field_dims_have_axis(da: xr.DataArray, xgcm_grid: xgcm.Grid) -> None:
        ax_dims = [(get_axis_from_dim_name(xgcm_grid.axes, dim), dim) for dim in da.dims]
        for dim in ax_dims:
            if dim[0] is None:
>               raise ValueError(
                    f'Dimension "{dim[1]}" has no axis attribute. '
                    f'HINT: You may want to add an {{"axis": A}} to your DataSet["{dim[1]}"], where A is one of "X", "Y", "Z" or "T"'
                )
E               ValueError: Dimension "Xp1" has no axis attribute. HINT: You may want to add an {"axis": A} to your DataSet["Xp1"], where A is one of "X", "Y", "Z" or "T"

src/parcels/_core/xgrid.py:56: ValueError

This is despite an axis attribute X being added to Xp1 in

ds = _set_axis_attrs(ds, _MITGCM_AXIS_VARNAMES)
ds = _maybe_swap_depth_direction(ds)

_MITGCM_AXIS_VARNAMES = {
"XC": "X",
"XG": "X",
"Xp1": "X",
"lon": "X",
"YC": "Y",
"YG": "Y",
"Yp1": "Y",
"lat": "Y",
"Zu": "Z",
"Zl": "Z",
"Zp1": "Z",
"time": "T",
}

@VeckoTheGecko, could you have a look what's going on and how to fix?

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Backlog

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions