Source code for pycif.plugins.models.lmdz_acc.io.inputs.make_auxiliary

from ......utils import path
from .params import make_totinput
from logging import info, warning
import os
import shutil
from ......utils.check.errclass import CifError


[docs] def make_auxiliary(self, ddi, runsubdir, onlyinit=False, do_simu=True, mode="fwd", **kwargs): """Set up the LMDZ-ACC executable and input configuration for one sub-period. Symlinks the correct LMDZ binary into *runsubdir* and calls :func:`make_totinput` to write the LMDZ total-input configuration file. Returns immediately when ``do_simu=False`` or ``onlyinit=True``. Args: self: LMDZ-ACC model plugin instance with ``workdir`` set. ddi (datetime): sub-simulation period start. runsubdir (str): path to the period run directory. onlyinit (bool): skip if ``True`` (adjoint initialisation pass). do_simu (bool): skip if ``False``. mode (str): ``'fwd'``, ``'tl'``, or ``'adj'``. **kwargs: unused. """ # 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 or onlyinit: return # Linking executable source = f"{self.workdir}/model/dispersion.e" target = f"{runsubdir}/dispersion.e" path.link(source, target) # Dump totinput depending on parameters make_totinput(self, runsubdir, ddi, mode) # Link to trajq from corresponding forward simulation if mode == "adj": if not hasattr(self, "adj_refdir"): info( "Adjoint LMDZ couldn't be initialized " "with forward trajq.bin files" ) raise CifError else: for spec in self.chemistry.acspecies.attributes: traj_file = f"trajq_{spec}_%Y%m%d%H%M.bin" source = ddi.strftime( f"{self.adj_refdir}/chain/{traj_file}" ) target = f"{runsubdir}/trajq_{spec}.bin" path.link(source, target) # TODO: at the moment, no satellite observation os.system(f"echo 0 > {runsubdir}/infousedsat.txt") # Remove restart TL if not running a tangent-linear run # TODO: Check whether it is still useful? if mode != "tl": shutil.rmtree( f"{runsubdir}/*start_tl.bin", ignore_errors=True ) # Deal with chemical scheme and deposition if hasattr(self, "chemistry"): # Linking to pre-computed INCA fields for deposition if hasattr(self.chemistry, "deposition"): warning("TODO: move deposition to the datavect paragraph") for spec in self.chemistry.deposition.attributes: tracer = getattr(self.chemistry.deposition, spec) source = ddi.strftime( f"{tracer.dir}/{tracer.file}" ) target = f"{runsubdir}/dep_{spec}.nc" path.link(source, target) finf = f"{self.chemistry.dirchem_ref}/chemical_scheme.nml" target = f"{runsubdir}/chemical_scheme.nml" path.link(finf, target) return
# # elif mod_input == "chem_fields": # if hasattr(self, "chemistry"): # # Linking to pre-computed INCA fields for deposition # if hasattr(self.chemistry, "deposition"): # for spec in self.chemistry.deposition.attributes: # tracer = getattr(self.chemistry.deposition, spec) # source = datei.strftime( # "{}/{}".format(tracer.dir, tracer.file) # ) # target = "{}/dep_{}.nc".format(runsubdir, spec) # path.link(source, target) # # finf = "{}/chemical_scheme.nml".format(self.chemistry.dirchem_ref) # target = "{}/chemical_scheme.nml".format(runsubdir) # path.link(finf, target)