Source code for pycif.plugins.datastreams.fields.lmdz_chemfield.read

import xarray as xr


[docs] def read( self, name, varnames, dates, files, interpol_flx=False, comp_type=None, ddi=None, **kwargs ): """Get fluxes from pre-computed fluxes and load them into a pyCIF variables Args: self: the fluxes Plugin name: the name of the component tracdir, tracfile: flux directory and file format dates: list of dates to extract interpol_flx (bool): if True, interpolates fluxes at time t from values of surrounding available files """ varnames = varnames if varnames else name da_list = [] file_ref = "" for dd, file_path in zip(dates, files): if file_path != file_ref: file_ref = file_path with xr.open_dataset(file_path) as ds: da = ds[varnames] day_index = (dd[0] - ddi).days da_list.append(da.isel(time_counter=[day_index])) xmod = xr.concat(da_list, dim='time_counter') xmod = xmod.rename({'time_counter': "time", 'presnivs': "lev"}) # Dropping coordinates for coord_name in xmod.coords: if coord_name != 'time': xmod = xmod.drop(coord_name) # Reordering dimensions xmod = xmod.transpose('time', 'lev', 'lat', 'lon') # Loop longitude coordinate to match LMDZ grid index = list(range(xmod.shape[3])) + [0] xmod = xmod.isel(lon=index) return xmod