Once you have loaded your data, you can analyze it using all the capabilities available in xarray. Here are a few quick examples.
xmitgcm simply reads the MDS data directly for the disk; it does not attempt to
mask land points, which are usually filled with zero values. To mask land, you
can use xarray’s
where function together the the
hFac variables related
partially filled cells.
For example, with the
global_oce_latlon dataset, an unmasked average of
ds.S.mean() >>> <xarray.DataArray 'S' ()> array(18.85319709777832, dtype=float32)
This value is unrealistically low because it includes all of the zeros inside the land which shold be masked. To take the masked average, instead do:
ds.S.where(ds.hFacC>0).mean() >>> <xarray.DataArray ()> array(34.73611831665039)
This is a more correct value.
However, it is still not properly volume weighted. To take a volume-weighted average, you can do:
volume = ds.hFacC * ds.drF * ds.rA (ds.S * volume).sum() / volume.sum() >>> <xarray.DataArray ()> array(34.779126627139945)
This represents the correct mean ocean salinity. A different land mask and volume weighting is required for variables located at the u and v points.
Thanks to xarray, it is trivial to convert our dataset to netCDF:
It can then be reloaded directly with xarray:
import xarray as xr ds = xr.open_dataset('myfile.nc')
This is an attractive option for archiving MDS data in a self-contained way.