Source code for pycif.plugins.models.TM5.io.native2inputs

import logging

import pandas as pd

from .....utils import path
from .inputs.make_chemistry import make_chemistry
from .inputs.make_fluxes import make_fluxes
from .inputs.make_inicond import make_inicond
from .inputs.make_meteo import make_meteo
from .inputs.params import make_config

MODULE_NAME = __name__[__name__.index('TM5') :] if 'TM5' in __name__ else __name__
logger = logging.getLogger(MODULE_NAME)


[docs] def native2inputs( self, datastore, input_type, datei, datef, runsubdir, mode="fwd", onlyinit=False, do_simu=True, check_transforms=False, **kwargs, ): """Converts data at the model data resolution to model compatible input files. Input types should be consistent with the ones specified in the mapper. Calls sub-functions dealing with individual input types The datastore provided to this function is a pyCIF Plugin, whose main interesting attribute is "datastore.datastore". This attribute is a dictionary of which each key is a tuple (input_type, parameter). Associated values are the following: - spec: an xarray.Dataset including the corresponding input data - incr: same for increments - dirorig: directory where to find original files for that input - fileorig: file format for that input Args: self: the model Plugin input_type (str): one of 'fluxes' datastore (Plugin): data to convert datei, datef: date interval of the sub-simulation mode (str): running mode: one of 'fwd', 'adj' and 'tl' runsubdir (str): sub-directory for the current simulation workdir (str): the directory of the whole pyCIF simulation VERSION HISTORY 1.2 02-02-2021 by J.C.A. van Peet. Updated the path to the TM5 executable. 1.1 18-01-2021 by J.C.A. van Peet. Renamed tm5.exe to tm5.x 1.0 ??-??-???? by A. Berchet. """ logger.debug("NATIVE2INPUTS => Start info") logger.debug(f" input_type = {input_type}") logger.debug(f" datei = {datei}") logger.debug(f" datef = {datef}") logger.debug(f" runsubdir = {runsubdir}") ddi = min(datei, datef) ddf = max(datei, datef) # Hour steps of the sub-run hour_dates = pd.date_range(ddi, ddf, freq="1h") if datastore is None: datastore = {} sdc = ddi.strftime("%Y%m%d%H") # If mode is "fwd" or "tl" but onlyinit is True, # it means that we are initializing an adjoint by running backward # the adjoint pipeline if mode in ["tl", "fwd"] and onlyinit: mode = "adj" if not do_simu: return # Deals with other inputs if input_type in "flux": make_fluxes(self, datastore, runsubdir, ddi, mode) if input_type == "inicond": make_inicond(self, datastore, runsubdir, mode, ddi, ddf) if input_type == "chemistry": make_chemistry(self, datastore, runsubdir, mode, ddi, ddf) if input_type == "meteo": make_meteo(self, datastore, runsubdir, mode, ddi, ddf)