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

import filecmp
import os
import shutil
import pathlib
import numpy as np
from netCDF4 import Dataset
import xarray as xr
from logging import warning

from ......utils import path


[docs] def make_endconcs( self, datastore, runsubdir, mode, datei, datef, onlyinit, check_transforms=False ): """Link concentration restart files into the CHIMERE period run directory. Handles four cases depending on *mode* and *onlyinit*: * **Forward / TL, not onlyinit** — links the end-concentrations produced by the previous period as ``INI_CONCS.0.nc`` for the current period. * **Adjoint, onlyinit** — same as above (links forward end-concs as initial state for the backward adjoint). * **Adjoint, not onlyinit** — links the adjoint initial conditions (from the forward reference run stored in ``self.adj_refdir``) as ``aini.nc``. Args: self: CHIMERE model plugin instance (carries ``adj_refdir`` for adjoint runs). datastore (dict): mapping of tracer IDs to their data-store entries, each containing ``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 the adjoint initialisation pass. 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 if (onlyinit and mode == "adj") or (not onlyinit and mode != "adj"): for trid in datastore: fileout = f"{runsubdir}/INI_CONCS.0.nc" fileorig = f"{self.adj_refdir}/{datastore[trid]['data'][datei]['fileorig']}" path.link(fileorig, fileout) if not onlyinit and mode == "adj": # Fixed name for INI_CONCS files fileout = f"{runsubdir}/aini.nc" for trid in datastore: fileorig = f"{runsubdir}/../{datastore[trid][max(datei, datef)]['fileorig']}" path.link(fileorig, fileout)