Source code for pycif.plugins.models.lmdz_acc.io.native2inputs
import os
from .....utils import path
from .inputs.chemfields import make_chemfields, make_kinetic
from .inputs.fluxes import make_fluxes
from .inputs.inicond import make_inicond
from .inputs.make_endconcs import make_endconcs
from .inputs.meteo import make_meteo
from .....utils.check.errclass import CifValueError
[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 'fluxes', 'obs'
datastore: data to convert
if input_type == 'fluxes', 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:
- LMDZ expects daily inputs; if the periods in the control vector are
longer than one day, period values are uniformly de-aggregated to the
daily scale; this is done with pandas function 'asfreq' and the option
'ffill' as 'forward-filling'
See Pandas page for details:
https://pandas.pydata.org/pandas-docs/stable/generated/pandas
.DataFrame.asfreq.html
"""
if datastore is None:
datastore = {}
# Switching datei and datef if adj
ddi = min(datei, datef)
ddf = max(datei, datef)
# 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 fluxes
# Not specified emissions are set to zero by LMDZ
if input_type == "flux":
make_fluxes(self, datastore, ddi, ddf, runsubdir, mode)
# Deals with 3D chemical production and loss
elif input_type in ["prodloss3d", "prescrconcs"]:
make_chemfields(self, datastore, input_type, ddi, ddf, runsubdir, mode)
# Deals with initial conditions
elif input_type in ["inicond", "restart_inicond"]:
make_inicond(
self, datastore, datei, datef, runsubdir, mode, onlyinit,
ini_type=input_type
)
# Initial conditions from previous simulations
elif input_type == "endconcs":
make_endconcs(
self, datastore, runsubdir, mode, ddi, ddf, onlyinit,
check_transforms=check_transforms
)
# Deals with photolysis rates
elif input_type == "kinetic":
make_kinetic(self, datastore, input_type, ddi, ddf, runsubdir, mode)
elif input_type == "meteo":
make_meteo(self, datastore, ddi, ddf, runsubdir, mode)
# vcoord file
target = os.path.join(runsubdir, "vcoord.nc")
path.link(self.vcoord_path, target)
else:
raise CifValueError("Un-recognized input type. Should not happen")