Source code for pycif.plugins.datastreams.fields.tm5_ic.read
import xarray as xr
from netCDF4 import Dataset
from .....utils.hdf5 import _hdf5_lock
[docs]
def read(
self,
name,
tracdir,
tracfile,
varnames,
dates,
interpol_flx=False,
comp_type=None,
model=None,
tracer=None,
**kwargs
):
"""Get the TM5 initial condition and load it into a pyCIF variable.
Reads ``q{restart_id:02d}`` (using ``tracer.restart_id`` if set,
otherwise the ``restart_id`` of the species in the chemical scheme)
from the single file matching the earliest requested date.
Args:
self: the IC Plugin
name: the name of the component
tracdir, tracfile: restart file directory and file format
varnames: unused, accepted for interface compatibility
dates: list of dates to extract; only the earliest date is used
interpol_flx (bool): unused, accepted for interface compatibility
comp_type: unused, accepted for interface compatibility
model: the model Plugin, used to resolve the species'
``restart_id`` via ``model.chemistry.acspecies`` when
``tracer.restart_id`` is not set
tracer: may carry an explicit ``restart_id``, taking precedence
over the chemical scheme's
Returns:
xarray.DataArray with dims ``(time, lev, lat, lon)``.
"""
ic_file = min(dates).strftime(f"{tracdir}/{tracfile}")
with _hdf5_lock:
with Dataset(ic_file, "r") as f:
if hasattr(tracer, "restart_id"):
spec_id = f"q{tracer.restart_id:02d}"
else:
spec_id = f"q{getattr(model.chemistry.acspecies, name).restart_id:02d}"
data = f.variables[spec_id][:]
xmod = xr.DataArray(
data, coords={"time": [min(dates)]}, dims=("time", "lev", "lat", "lon")
)
return xmod