Source code for pycif.plugins.models.chimere.flushrun
from glob import glob
from ....utils import path
[docs]
def flushrun(self, rundir, mode, transform_id, full_flush=True):
"""Cleaning the simulation directories to limit space usage"""
list_subdirs = glob(f"{rundir}/*/")
# Removing big files in CHIMERE directories
for subdir in list_subdirs:
flush_rundir(
subdir, mode, final=True, full_flush=full_flush,
keep_out_files=self.keep_out_files,
keep_emission_files=self.keep_emission_files
)
[docs]
def flush_rundir(runsubdir, mode, final=False, full_flush=True, keep_out_files=False, keep_emission_files=False):
"""Remove large temporary CHIMERE files from one sub-simulation directory.
Deletes the bulky input/output NetCDF files that are no longer needed
once a sub-simulation period has completed (or once the full run is done).
Files always removed: ``BOUN_CONCS``, ``INI_CONCS``, ``METEO``, ``par``,
deposition, end, ``TMPconc*``, and ``obs.txt`` files. ``AEMISSIONS`` and
``BEMISSIONS`` are also removed unless ``keep_emission_files=True``, and
``out.nc`` is removed unless ``keep_out_files=True``.
Additionally for **adjoint** runs: ``.txt`` files.
Additionally when ``final=True``: ``aout``, ``aini``, ``aend``, and
(again) ``.txt`` files.
Additionally when ``mode='adj'`` and ``full_flush=True`` (only checked
when ``final=True``): ``end.*.nc`` concentration restart files.
Args:
runsubdir (str): path to the sub-simulation directory to clean.
mode (str): execution mode (``'fwd'``, ``'tl'``, or ``'adj'``).
final (bool): if ``True``, also remove ``aout``, ``aini``, ``aend``
files (called at end of full run, not between chained periods).
full_flush (bool): if ``True`` and ``mode='adj'`` and ``final=True``,
also remove ``end.*.nc`` restart files (disables period chaining
restart capability).
keep_out_files (bool): if ``True``, do not remove ``out.nc``.
keep_emission_files (bool): if ``True``, do not remove
``AEMISSIONS``/``BEMISSIONS`` files.
"""
path.remove(f"{runsubdir}/AEMISSIONS.*nc")
path.remove(f"{runsubdir}/BEMISSIONS.*nc")
path.remove(f"{runsubdir}/BOUN_CONCS.*nc")
path.remove(f"{runsubdir}/INI_CONCS.0.*nc")
path.remove(f"{runsubdir}/METEO.nc")
path.remove(f"{runsubdir}/par.nc")
path.remove(f"{runsubdir}/dep.nc")
path.remove(f"{runsubdir}/end.nc")
if not keep_out_files:
path.remove(f"{runsubdir}/out.nc")
if not keep_emission_files:
path.remove(f"{runsubdir}/AEMISSIONS.*nc")
path.remove(f"{runsubdir}/BEMISSIONS.*nc")
path.remove(f"{runsubdir}/TMPconc*")
path.remove(f"{runsubdir}/obs.txt")
if mode == "adj":
path.remove(f"{runsubdir}/*.txt")
if not final:
return
path.remove(f"{runsubdir}/aout.*.nc")
path.remove(f"{runsubdir}/aini.nc")
path.remove(f"{runsubdir}/*.txt")
path.remove(f"{runsubdir}/aend.*.nc")
if mode == "adj" and full_flush:
path.remove(f"{runsubdir}/end.*.nc")