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

import os
from logging import warning

from ......utils import path


[docs] def make_endconcs( self, datastore, runsubdir, mode, datei, datef, onlyinit, check_transforms=False ): """Link LMDZ-ACC restart files into the period run directory. Handles period chaining for all three execution modes: * **Forward / TL** (not onlyinit) — links the previous-period restart as initial conditions for the current period. * **Adjoint, onlyinit** — links the forward restart as the adjoint starting state. * **Adjoint, not onlyinit** — links the adjoint restart initialised to zero sensitivities. Args: self: LMDZ-ACC model plugin instance (carries ``adj_refdir``). datastore (dict): tracer-ID-keyed data-store entries with ``fileorig`` paths. runsubdir (str): path to the period run directory. mode (str): ``'fwd'``, ``'tl'``, or ``'adj'``. datei (datetime): period start date. datef (datetime): period end date. onlyinit (bool): ``True`` during adjoint initialisation. check_transforms (bool): unused; kept for API compatibility. """ # If adjoint and only init, fetching initial concentrations from forward # If fwd or tl and not only init, fetch initial concentrations from end # of previous simulation # LMDZ does not need initial conditions from TL in ADJ as they are taken from trajq.bin if onlyinit: return # Fixed names for restart files fileout = os.path.join(runsubdir, "start.nc") fileout_tl = os.path.join(runsubdir, "start_tl.bin") if mode != "adj": for trid in datastore: dirorig = self.adj_refdir ref_dict = datastore[trid]['data'][datei] fileorig = os.path.join(dirorig, ref_dict['fileorig']) path.link(fileorig, fileout) if mode == "tl": fileorig_tl = os.path.join(dirorig, ref_dict['fileorig_tl']) # Check whether a file was created by a previous sub-period if os.path.isfile(fileorig_tl): path.link(fileorig_tl, fileout_tl) else: warning( f"The file {fileorig_tl} from previous month was not generated " f"by the tangent-linear. This happens when no increment is " f"specified. Ignoring the propagation of increments for {datei}" ) else: date = max(datei, datef) for trid in datastore: dirorig = os.path.join(runsubdir, "..") ref_dict = datastore[trid][date] fileorig = os.path.join(dirorig, ref_dict['fileorig']) path.link(fileorig, fileout)