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

import copy
import os
from logging import debug, warning

import xarray as xr

from .ensemble import ensemble_trid


[docs] def make_fluxes(self, datastore, ddi, ddf, runsubdir, mode): """Write LMDZ-ACC flux input files for one sub-simulation period. For each emitted species, fetches the CIF flux field from *datastore*, regrid/reformat as needed, and writes the result to the expected LMDZ flux file location under *runsubdir*. Args: self: LMDZ-ACC model plugin instance. datastore (dict): tracer-ID-keyed CIF data-store entries. ddi (datetime): period start date. ddf (datetime): period end date. runsubdir (str): path to the period run directory. mode (str): ``'fwd'``, ``'tl'``, or ``'adj'``. """ for spec in self.chemistry.emis_species.attributes: trid = ensemble_trid(self, ('flux', spec), datastore) if trid not in datastore: continue debug(f"Generating {spec} flux inputs for LMDZ") data = datastore[trid]['data'][ddi] # If not determined by the control vector if 'spec' not in data: data['spec'] = self.flux.read( spec, datastore[trid]['varname'], datastore[trid]['input_dates'][ddi], datastore[trid]['input_files'][ddi], ) # Adds empty increments if not available if 'incr' not in data: data['incr'] = 0.0 * data['spec'] if mode == 'tl': warning( f"Setting LMDZ tangent-linear flux to zeros for {spec}.") # Put in dataset for writing by 'write' ds = xr.Dataset({'fwd': data['spec'], 'tl': data['incr']}) # Write to FORTRAN binary flx_file = os.path.join(runsubdir, f"mod_{spec}.bin") self.emis_species.write(spec, flx_file, ds)