Source code for pycif.plugins.models.lmdz_ico.io.inputs.make_endconcs
from __future__ import annotations
import datetime
from os import PathLike
from pathlib import Path
from typing import Any, Literal
from ......utils import path
[docs]
def make_endconcs(
self,
datastore: dict[tuple[str, str], dict[str | datetime.datetime, Any]],
datei: datetime.datetime,
datef: datetime.datetime,
runsubdir: str | PathLike,
mode: Literal["fwd", "tl", "adj"],
onlyinit: bool,
) -> None:
"""Link LMDZ-ico restart files into the period run directory for chaining"""
# If adjoint and onlyinit, fetching initial concentrations from forward
# If forward or tangent and not onlyinit, fetch initial concentrations from end of previous simulation
if onlyinit:
return
# Fixed names for restart files
runsubdir = Path(runsubdir)
fileout = runsubdir / "start.nc"
if mode in ["fwd", "tl"]:
for trid in datastore:
# TODO: Maybe a bit convoluted, "dirorig" could be set in fetch_end
# as a workaround
dirorig = Path(self.adj_refdir)
ref_dict = datastore[trid]["data"][datei] # TODO: why "data" ???
fileorig = dirorig / ref_dict["fileorig"]
path.link(fileorig, fileout)
else:
for trid in datastore:
dirorig = runsubdir.parent
ref_dict = datastore[trid][datef]
fileorig = dirorig / ref_dict["fileorig"]
path.link(fileorig, fileout)