Source code for pycif.plugins.models.wrfchem.io.inputs.make_auxiliary
import os
import logging
import shutil
from ......utils.path import link
from .params import update_namelist_file
[docs]
def make_auxiliary(self, ddi, runsubdir,
onlyinit=False, do_simu=True, mode="fwd",
**kwargs):
"""Set up the WRF-Chem run directory and namelist for one sub-period.
Copies or links the WRF executable and updates the WRF namelist (``namelist.input``)
with the correct start/end date and output interval for this period, then
creates the required sub-directory structure under *runsubdir*.
Returns immediately when ``do_simu=False`` or ``onlyinit=True``.
Args:
self: WRF-Chem 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``.
do_simu (bool): skip if ``False``.
mode (str): ``'fwd'``, ``'tl'``, or ``'adj'``.
**kwargs: unused.
"""
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
# Make namelist
fp_nml = os.path.join(runsubdir, "namelist.input")
logging.info(f"Writing namelist to {fp_nml}")
# Copy namelist to runsubdir
shutil.copy2(self.namelist_input_file, fp_nml)
# Write settings for this run to namelist
ddf = self.tstep_dates[ddi][-1]
# Is this a restart?
fn_rst = ddi.strftime("wrfrst_d01_%Y-%m-%d_%H:%M:%S")
fp_rst = os.path.join(runsubdir, fn_rst)
is_restart = os.path.exists(fp_rst)
self.namelist = update_namelist_file(self.namelist,
ddi, ddf,
is_restart,
runsubdir)
# Link executable
msg = f"Linking model files to {runsubdir}"
logging.info(msg)
source_dir = os.path.join(self.workdir, "model")
source_files = os.listdir(source_dir)
for filename in source_files:
fp_source = os.path.join(source_dir, filename)
fp_destination = os.path.join(runsubdir, filename)
link(fp_source, fp_destination)