Source code for pycif.plugins.datastreams.fluxes.VPRM1km_nc.read

import datetime
import os
from logging import debug, info

import numpy as np
import pandas as pd
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, tracer=None, **kwargs, ): """Get fluxes from VPRM files and load them into a pyCIF variables """ # list of the various fields read: data = [] outdate = [] nc = None opened_file = "" for dd, ff in zip(dates, files): debug('Here put the reading of {} in {} for {}'.format([varnames], ff, dd)) if ff != opened_file or nc is None: opened_file = ff nc = xr.open_dataset(ff, decode_times=False) read_field = nc[varnames][:].values data.extend(read_field) period = pd.date_range(dd[0], periods=24, freq="1h") outdate.extend(period) # 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