Example Usage

Once you have loaded your data, you can analyze it using all the capabilities available in xarray. Here are a few quick examples.

Land Masks

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 to MITgcm’s partially filled cells. For example, with the global_oce_latlon dataset, an unmasked average of salinity gives:

>>> <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:

>>> <xarray.DataArray ()>

This is a more correct value.

Volume Weighting

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 ()>

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.

netCDF conversion

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.