Source code for pycif.plugins.models.chimere.io.native2inputs
from logging import warning
import pandas as pd
from .....utils import path
from .inputs.make_boundcond import make_boundcond
from .inputs.make_endconcs import make_endconcs
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_nml
[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'
datastore: data to convert
if input_type == 'flux',
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:
- CHIMERE expects hourly inputs;
"""
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 fluxes
# WARNING: Not specified emissions are set to zero??
if input_type in ["flux", "bioflux"]:
make_fluxes(self, datastore, runsubdir, ddi, mode)
elif input_type in ["latcond", "topcond"]:
make_boundcond(self, datastore, runsubdir, ddi, mode, input_type)
elif input_type in ["inicond", "restart_inicond"]:
make_inicond(self, datastore, runsubdir, mode, ddi, ddf, ini_type=input_type)
elif input_type == "endconcs":
make_endconcs(
self,
datastore,
runsubdir,
mode,
ddi,
ddf,
onlyinit,
check_transforms=check_transforms,
)
elif input_type == "meteo":
make_meteo(self, datastore, runsubdir, mode, ddi)
else:
warning(f"CHIMERE does not recognize required type: {input_type}")