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

""" 
Reads the data in the orignal files. Is called for each key in dictionary list_dates/list_files provided by fetch.

Args:
------
- name: name of the component
- dates: list of the dates matching the files
- files: list of the files matching the dates
 -> dates and files as provided by fetch.py
- varnames: original names of variables to read
- comp_type: type of boundary conditions to generate. Useful to distinguish lateral from top from initial conditions.

Returns:
---------
- a DataArray with the actual data: 4 dimensional (time, vertical levels, latitude, longitude) with coordinates in increasing order (see also get_domain).

"""


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 BCs from raw files and load them into a pyCIF variables """ print('If relevant, check here the component type') # Example: if comp_type == "inicond": ... # elif comp_type in ["latcond", "topcond"]: ... print('Loop on the dates and files') for dd, ff in zip(dates, files): print('Here put the reading of ', [varnames],' in ',ff,' for ',dd) print('e.g. get a 3d array') print('may require some manipulations on dates to get the right index in the file') # Putting in DataArray # Put here the required reversing of axis to get coordinates in increasing order xmod = xr.DataArray( np.array(data)[:,:,:,:], coords={"time": dates}, dims=("time", "lev", "lat", "lon") ) return xmod