Source code for pycif.plugins.datastreams.fields.noaa_glob_avg.read
import datetime
import os
import numpy as np
import xarray as xr
from netCDF4 import Dataset
from .....utils.netcdf import readnc
[docs]
def read(
self,
name,
varnames,
dates,
files,
interpol_flx=False,
comp_type=None,
**kwargs
):
"""Get NOAA global-average values and load them into a pyCIF variable.
Reads ``self.varname_init`` from each file in ``files`` and converts
the values from ppb to ppm.
Args:
self: the fields Plugin
name: the name of the component
varnames: unused, accepted for interface compatibility
dates: list of ``[start, end]`` date pairs to extract; only the
start of each pair is used as the output time coordinate
files: list of file paths matching ``dates``
interpol_flx: unused, accepted for interface compatibility
comp_type: unused, accepted for interface compatibility
Returns:
xarray.DataArray with dims ``(time, lev, lat, lon)``, in ppm.
"""
trcr_data = []
trcr_dates = []
for dd, ff in zip(dates, files):
tmp = readnc(ff, [self.varname_init])
trcr_data.append(tmp[0])
trcr_dates.append(dd[0])
# Putting in DataArray
xmod = xr.DataArray(
trcr_data, coords={"time": trcr_dates}, dims=("time", "lev", "lat", "lon")
)
# Converting ppb to ppm for pycif
xmod /= 1e3
return xmod