Source code for pycif.plugins.models.lagrangian.io.native2inputs
from logging import info, debug
import copy
from .....utils.check.errclass import CifError
[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.
Args:
self: the model Plugin
input_type (str): one of 'flux', 'obs'
datastore: data to convert
if input_type == 'flux', a dictionary with flux maps
if input_type == 'obs', a pandas dataframe with the observations
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
Notes:
Copied from LMDZ. We do not attempt to run the model at this point.
"""
ddi = min(datei, datef)
ddf = max(datei, datef)
if input_type not in self.required_inputs:
raise CifError(f"Lagrangian model received unexpected input type: {input_type}")
# Storing fluxes for later, copying to avoid erasing info elsewhere
if input_type == "flux":
if not hasattr(self, "dataflx"):
self.dataflx = {}
for trid in datastore:
if trid not in self.dataflx:
self.dataflx[trid] = copy.deepcopy(datastore[trid]["data"])
else:
self.dataflx[trid][ddi] = copy.deepcopy(
datastore[trid]["data"][ddi])
elif input_type == "inicond":
if not hasattr(self, "datainicond"):
self.datainicond = {}
for trid in datastore:
if trid not in self.datainicond:
self.datainicond[trid] = copy.deepcopy(datastore[trid]["data"])
else:
self.datainicond[trid][ddi] = copy.deepcopy(
datastore[trid]["data"][ddi])