Source code for pycif.plugins.datastreams.fluxes.VPRM_nc.read
import datetime
import os
import numpy as np
import xarray as xr
from netCDF4 import Dataset
from .....utils.netcdf import readnc
from logging import info, debug
[docs]
def read(
self,
name,
varnames,
dates,
files,
interpol_flx=False,
comp_type=None,
tracer=None,
**kwargs
):
"""Get fluxes from VPRM files and load them into a pyCIF
variables
"""
# list of the various fields read:
data = []
outdate = []
for dd, ff in zip(dates, files):
debug('Here put the reading of {} in {} for {}'
.format([varnames], ff, dd))
nc = xr.open_dataset(ff[0], decode_times=False)
read_field = nc[varnames][dd[0].hour].values
debug('e.g. get a 3d array read_field')
data.append(read_field)
outdate.append(dd[0])
debug("check")
debug(dates)
debug(len(data[0]))
debug(np.array(data).shape)
# if only one level for emissions, create the axis:
xmod = xr.DataArray(
np.array(data)[:, np.newaxis, ...],
coords={"time": outdate},
dims=("time", "lev", "lat", "lon"),
)
return xmod