Wrapper to handle importing MPAS files into xarray (https://github.com/pydata/xarray). Module can be installed via
pip -v install git+ssh://git@github.com/pwolfram/mpas_xarray
The module does the following:
- Converts MPAS "xtime" to xarray time. Time dimension is
assigned via
preprocess_mpas. - Converts MPAS "timeSinceStartOfSim"
to xarray time for MPAS fields coming from the timeSeriesStatsAM. Time
dimension is assigned via
preprocess_mpas(...,timeSeriesStats=True). - Allows generalized selection of variables via
preprocess_mpas(..., onlyvars=['var1','var2'])and slicing viapreprocess_mpas(..., iselvals={'nVertLevels':1})andpreprocess_mpas(..., selvals={'lonCell':180.0}). - Provides capability to remove redundant time entries from reading of
multiple netCDF datasets via
remove_repeated_time_index.
Example Usage:
import xarray
from mpas_xarray import preprocess_mpas, remove_repeated_time_index
ds = xarray.open_mfdataset('globalStats*nc', preprocess=preprocess_mpas)
ds = remove_repeated_time_index(ds)
To test:
tar xzvf globalStatsShort.tgz python mpas_xarray.py -f "globalStats*nc"
This outputs a simple time-series plot of Time vs. Time to test functionality.
Example Usage for timeSeriesStatsAM fields:
import xarray
from mpas_xarray import preprocess_mpas, remove_repeated_time_index
def preprocess(x, timestr='timeSeriesStatsMonthly_avg_daysSinceStartOfSim_1'):
return preprocess_mpas(x, timeSeriesStats=True, timestr=timestr)
ds = xarray.open_mfdataset('am.mpas-cice*nc', preprocess=preprocess)
ds = remove_repeated_time_index(ds)
To test:
tar xzvf am.mpas-ciceShort.tgz python mpas_xarray.py -f "am.mpas-cice*nc" --istimeavg "true"
This plots a short time series of global average ice concentration, showing the correctly centered curve (derived using preprocess_mpas_timeSeriesStats) and the curve incorrectly shifted toward the end of the time averaging period (derived using preprocess_mpas).