pycif.plugins.models.lmdz_acc — API reference#
Configuration reference: lmdz_acc plugin
- pycif.plugins.models.lmdz_acc.compile.make_command(self)[source]#
Build the
makecommand list for compiling LMDZ-ACC.Assembles
makearguments from the plugin’s compile-time attributes: domain dimensions (DIM), compile mode (MODE), OpenACC target (TARGET), and optional Fortran compiler / NetCDF paths.- Parameters:
self – LMDZ-ACC model plugin instance.
- Returns:
the
makecommand and its arguments.- Return type:
list[str]
- pycif.plugins.models.lmdz_acc.compile.compile(self)[source]#
Compile or copy LMDZ-ACC executables into the CIF work directory.
Attempts to copy pre-compiled binaries from
self.direxecfirst (skipped ifforce-recompileis set), then falls back to runningmake_command()inside the LMDZ source tree.- Parameters:
self – LMDZ-ACC model plugin instance with
workdiranddirexec(ordirsrc) set.
- pycif.plugins.models.lmdz_acc.flushrun.flushrun(self, rundir, mode, transform_id, full_flush=True)[source]#
Cleaning the simulation directories to limit space usage
- pycif.plugins.models.lmdz_acc.ini_mapper.ini_mapper(model, transform_type, general_mapper={}, backup_comps={}, transforms_order=[], ref_transform='', transform_name='', **kwargs)[source]#
Build the data-flow mapper for the LMDZ-ACC model.
Declares flux, meteorology, initial-condition, end-concentration, and (optionally) observation inputs, plus concentration and diagnostic outputs. Also populates
outputs2inputslinking each output tracer to its source inputs for adjoint sensitivity routing.Two date grids are used:
input_dates— coarser grid for initial/end concentrations.flx_input_dates— finer grid for flux and meteo inputs.
- Parameters:
model – LMDZ-ACC model plugin instance.
transform_type (str) – unused; kept for API compatibility.
general_mapper (dict) – unused.
backup_comps (dict) – unused.
transforms_order (list) – unused.
ref_transform (str) – unused.
transform_name (str) – unused.
**kwargs – unused.
- Returns:
mapper with
inputs,outputs, andoutputs2inputs.- Return type:
dict
- pycif.plugins.models.lmdz_acc.ini_periods.ini_periods(self, **kwargs)[source]#
Compute temporal discretisation for the LMDZ-ACC model.
Splits the full simulation window into sub-simulation periods and builds time-step arrays at the resolution dictated by the LMDZ domain’s dynamical (
dsplit) and physical (psplit) sub-steps and the meteorological offset time step (meteo.offtstep).Sets on self:
subsimu_dates— period boundary dates.tstep_dates— per-period time-step arrays.input_dates— per-period initial/end-concentration date arrays.flx_input_dates— per-period flux/meteo input date arrays.tstep_all— sorted unique merge of all time steps.iniobs,reset_obs— per-period observation bookkeeping flags.chain— per-period flag indicating whether the period is chained from the previous one.
- Parameters:
self – LMDZ-ACC model plugin instance with
datei,datef,periods,domain, andmeteoset.**kwargs – unused.
- pycif.plugins.models.lmdz_acc.perturb_model.append_attribute(plugin: Any, key: str, attr: Any) None[source]#
Set attr as attribute key on plugin and append key to
plugin.attributes.
- pycif.plugins.models.lmdz_acc.perturb_model.remove_attribute(plugin: Any, key: str) None[source]#
Delete attribute key from plugin and remove it from
plugin.attributes.
- pycif.plugins.models.lmdz_acc.perturb_model.perturb_model(self, nsamples, transf_mapper)[source]#
Extend the LMDZ-ACC chemistry scheme to accommodate ensemble members.
Creates
nsamplescopies of each active, output, and emitted species using the__sample#NNNnaming convention, then removes the original un-suffixed species. Recordsself.perturbed_speciesmapping sample names back to originals.- Parameters:
self – LMDZ-ACC model plugin instance.
nsamples (int) – number of ensemble members.
transf_mapper (dict) – unused; kept for API consistency.
- pycif.plugins.models.lmdz_acc.run.run_dispersion(self, runsubdir)[source]#
Launch the LMDZ-ACC dispersion executable for one sub-simulation period.
Runs the LMDZ-ACC binary in runsubdir, optionally setting the
ACC_NUM_CORESenvironment variable for GPU/OpenACC thread control. Raises on non-zero exit code.- Parameters:
self – LMDZ-ACC model plugin instance.
runsubdir (str) – path to the period run directory.
- Raises:
subprocess.CalledProcessError – if the dispersion run fails.
- pycif.plugins.models.lmdz_acc.run.run(self, runsubdir, mode, workdir, ddi, do_simu=True, approx_transf=False, ref_fwd_dir='', overlap=False, **kwargs)[source]#
Run LMDZ model in forward or adjoint mode
- Parameters:
runsubdir (str) – working directory for the current run
mode (str) – forward or backward
workdir (str) – pycif working directory
do_simu (bool) – if False, considers that the simulation was already run
- pycif.plugins.models.lmdz_acc.run.check_approx_threshold(self, ddi, mode, runsubdir)[source]#
Decide whether to skip transport and approximate with linear chemistry.
If species concentrations from the forward run exceed a configured threshold (
self.approx_thresholds), marks the period for approximate treatment so that the expensive LMDZ transport is skipped and replaced by a local linear-chemistry approximation.- Parameters:
self – LMDZ-ACC model plugin instance.
ddi (datetime) – period start date.
mode (str) –
'fwd','tl', or'adj'.runsubdir (str) – path to the period run directory.
- class pycif.plugins.models.lmdz_acc.chemistry.chemical_scheme.Species(name: str, type: Literal['ac', 'pr'], index: int = -1, restart_id: int = -1)[source]#
Bases:
objectA class representing a species
- Parameters:
name (str) – species name
type ('ac' or 'pr') – species type, ‘ac’ (active) or ‘pr’ (prescribed)
index (int) – species index in arrays
restart_id (int) – species restart id (active species only)
- name: str#
- type: Literal['ac', 'pr']#
- index: int = -1#
- restart_id: int = -1#
- class pycif.plugins.models.lmdz_acc.chemistry.chemical_scheme.Reaction(active_reactants: List[Species], prescribed_reactants: List[Species], active_products: List[Species], active_product_stoi: List[int], reac_type: Literal[1, 2, 3, 4], rate_constants: List[float])[source]#
Bases:
objectA class representing a chemical reaction
- Parameters:
active_reactants (list of Species) – Active reactants
prescribed_reactants (list of Species) – Prescribed reactants
active_products (list of Species) – Active products
active_product_stoi (list of int) – Active product stoichiometric numbers
reac_type (int) – Reaction type
rate_constants (list of float)
- active_product_stoi: List[int]#
- reac_type: Literal[1, 2, 3, 4]#
- rate_constants: List[float]#
- pycif.plugins.models.lmdz_acc.chemistry.chemical_scheme.parse_chemical_scheme(self: Any) Tuple[List[Reaction], DataArray][source]#
Parse the chemical scheme, partial reimplementation of LMDZ’s “read_chemical_scheme” subroutine
- pycif.plugins.models.lmdz_acc.chemistry.compute_chemistry.compute_chemistry_step(reaction_list: List[Reaction], molar_masses: DataArray, dt: float, mmr: DataArray, mmr_tl: DataArray, prescr: DataArray, prescr_tl: DataArray, pmid: DataArray, temp: DataArray) Tuple[DataArray, DataArray][source]#
Reimplementation of LMDZ’s “compute_chem_tl” subroutine.
- Parameters:
reaction_list (list of Reaction) – list of reactions
molar_masses (xr.DataArray) – molar masses of active species
dt (float) – time step [s]
mmr (xr.DataArray) – mass ratio (forward) [kg/kg]
mmr_tl (xr.DataArray) – mass ratio (tangent) [kg/kg]
prescr (xr.DataArray) – prescribed species concentrations (forward) [molec/cm3]
prescr_tl (xr.DataArray) – prescribed species concentrations (tangent) [molec/cm3]
pmid (xr.DataArray) – pressure field [Pa]
temp (xr.DataArray) – temperature field [K]
- Returns:
losses [kg/kg] xr.DataArray: losses_tl [kg/kg]
- Return type:
xr.DataArray
- pycif.plugins.models.lmdz_acc.chemistry.read_inputs.strip_spatial_coords(data: DataType) DataType[source]#
Drop ‘lev’, ‘lat’ and ‘lon’ coordinates from a Dataset or DataArray to ensure taht futher operation between DataArrays will be index based (like numpy operation) and not coordinate based.
- Parameters:
data (xr.DataArray or xr.Dataset)
- Returns:
without spatial coordinates
- Return type:
xr.DataArray or xr.Dataset
- pycif.plugins.models.lmdz_acc.chemistry.read_inputs.read_inicond_file(self: Any, runsubdir: str, mode: Literal['fwd', 'tl']) DataArray[source]#
Read LMDZ initial conditions file (.nc or .bin) for a given mode (fwd or tl)
- Parameters:
self (Model) – LMDZ model plugin
runsubdir (str) – sub simulation run directory
mode (str) – ‘fwd’ (forward) or ‘tl’ (tangent-linear)
- pycif.plugins.models.lmdz_acc.chemistry.read_inputs.chemfield_time_coord(ddi: datetime) DataArray[source]#
Build the daily time coordinate for a chemistry-field input dataset.
Returns a 1-D DataArray of daily timestamps spanning the full calendar month that contains ddi.
- Parameters:
ddi – any date within the target month.
- Returns:
daily date range of length
days_in_month.- Return type:
xr.DataArray
- pycif.plugins.models.lmdz_acc.chemistry.read_inputs.read_kinetic(self: Any, ddi: datetime, runsubdir: str | PathLike) Dataset[source]#
Read the LMDZ kinetic (pressure/temperature) field from the run directory.
Opens
kinetic.nc, renames dimensions to CIF conventions, trims to the month’s day count, and strips spatial coordinate metadata.- Parameters:
self – LMDZ model plugin instance.
ddi – period start date (determines the target month).
runsubdir – path to the period run directory.
- Returns:
xr.Dataset with
pmidandtempvariables on(time, lev, lat, lon)coordinates.
- pycif.plugins.models.lmdz_acc.chemistry.read_inputs.read_prescr(self: Any, ddi: datetime, runsubdir: str | PathLike) DataArray[source]#
Read prescribed-concentration fields from the LMDZ run directory.
Reads concentration data for all prescribed species from
prescr.ncin runsubdir, aligns the time axis to the month containing ddi, and strips spatial coordinate metadata.- Parameters:
self – LMDZ model plugin instance (carries
chemistry.prescrconcs.attributes).ddi – period start date (determines the target month).
runsubdir – path to the period run directory.
- Returns:
xr.DataArray of prescribed concentrations on
(time, lev, lat, lon)coordinates.
- pycif.plugins.models.lmdz_acc.io.native2inputs.native2inputs(self, datastore, input_type, datei, datef, runsubdir, mode='fwd', onlyinit=False, do_simu=True, check_transforms=False, **kwargs)[source]#
Converts data at the model data resolution to model compatible input files.
- Parameters:
self – the model Plugin
input_type (str) – one of ‘fluxes’, ‘obs’
datastore – data to convert if input_type == ‘fluxes’, a dictionary with flux maps if input_type == ‘obs’, a pandas dataframe with the observations
datei – date interval of the sub-simulation
datef – date interval of the sub-simulation
mode (str) – running mode: one of ‘fwd’, ‘adj’ and ‘tl’
runsubdir (str) – sub-directory for the current simulation
workdir (str) – the directory of the whole pycif simulation
Notes
LMDZ expects daily inputs; if the periods in the control vector are
longer than one day, period values are uniformly de-aggregated to the daily scale; this is done with pandas function ‘asfreq’ and the option ‘ffill’ as ‘forward-filling’ See Pandas page for details: https://pandas.pydata.org/pandas-docs/stable/generated/pandas .DataFrame.asfreq.html
- pycif.plugins.models.lmdz_acc.io.native2inputs_adj.native2inputs_adj(self, datastore, input_type, datei, datef, runsubdir, mode='fwd', onlyinit=False, do_simu=True, check_transforms=False, **kwargs)[source]#
Converts data at the model data resolution to model compatible input files.
- Parameters:
self – the model Plugin
input_type (str) – one of ‘fluxes’, ‘obs’
datastore – data to convert if input_type == ‘fluxes’, a dictionary with flux maps if input_type == ‘obs’, a pandas dataframe with the observations
datei – date interval of the sub-simulation
datef – date interval of the sub-simulation
mode (str) – running mode: one of ‘fwd’, ‘adj’ and ‘tl’
runsubdir (str) – sub-directory for the current simulation
workdir (str) – the directory of the whole pycif simulation
Notes
LMDZ expects daily inputs; if the periods in the control vector are
longer than one day, period values are uniformly de-aggregated to the daily scale; this is done with pandas function ‘asfreq’ and the option ‘ffill’ as ‘forward-filling’ See Pandas page for details: https://pandas.pydata.org/pandas-docs/stable/generated/pandas .DataFrame.asfreq.html
- pycif.plugins.models.lmdz_acc.io.outputs2native.outputs2native(self, data2dump, input_type, di, df, runsubdir, mode='fwd', dump=True, onlyinit=False, check_transforms=False, **kwargs)[source]#
Reads outputs to pycif objects.
If the mode is ‘fwd’ or ‘tl’, only observation-like outputs are extracted. For the ‘adj’ mode, all outputs relative to model sensitivity are extracted.
Dumps to a NetCDF file with output concentrations if needed
- Parameters:
self (pycif.utils.classes.models.Model) – Model object
runsubdir (str) – current sub-sumilation directory
mode (str) – running mode; one of: ‘fwd’, ‘tl’, ‘adj’; default is ‘fwd’
dump (bool) – dumping outputs or not; default is True
- Returns:
dict
- pycif.plugins.models.lmdz_acc.io.outputs2native_adj.outputs2native_adj(self, data2dump, input_type, datei, datef, runsubdir, mode='fwd', dump=True, onlyinit=False, do_simu=True, check_transforms=False, **kwargs)[source]#
Reads outputs to pycif objects.
If the mode is ‘fwd’ or ‘tl’, only observation-like outputs are extracted. For the ‘adj’ mode, all outputs relative to model sensitivity are extracted.
Dumps to a NetCDF file with output concentrations if needed
- Parameters:
self (pycif.utils.classes.models.Model) – Model object
runsubdir (str) – current sub-sumilation directory
mode (str) – running mode; one of: ‘fwd’, ‘tl’, ‘adj’; default is ‘fwd’
dump (bool) – dumping outputs or not; default is True
- Returns:
dict
- pycif.plugins.models.lmdz_acc.io.inputs.chemfields.make_chemfields(self, datastore, input_type, ddi, ddf, runsubdir, mode)[source]#
Write a chemical concentration field (prescribed or boundary) for LMDZ-ACC.
Reads the CIF data for the given input_type (e.g.
'prescrconcs','lbc') and writes it as a NetCDF input file in runsubdir. Does nothing when the chemistry plugin does not define input_type.- Parameters:
self – LMDZ-ACC model plugin instance.
datastore (dict) – tracer-ID-keyed CIF data-store entries.
input_type (str) – chemistry input type (e.g.
'prescrconcs').ddi (datetime) – period start date.
ddf (datetime) – period end date.
runsubdir (str) – path to the period run directory.
mode (str) –
'fwd','tl', or'adj'.
- pycif.plugins.models.lmdz_acc.io.inputs.chemfields.make_kinetic(self, datastore, input_type, ddi, ddf, runsubdir, mode)[source]#
Write the LMDZ-ACC kinetic (pressure/temperature) field for one period.
Reads the CIF kinetic data-store and writes
kinetic.ncin runsubdir. If no modified data is present, symlinks the original file.- Parameters:
self – LMDZ-ACC model plugin instance.
datastore (dict) – kinetic CIF data-store entries.
input_type (str) – input type identifier (unused; kept for API consistency).
ddi (datetime) – period start date.
ddf (datetime) – period end date.
runsubdir (str) – path to the period run directory.
mode (str) –
'fwd','tl', or'adj'.
- pycif.plugins.models.lmdz_acc.io.inputs.ensemble.ensemble_trid(self: Any, trid: Tuple[str, str], datastore: Dict[Tuple[str, str], Any]) Tuple[str, str][source]#
Replace ‘spec’ in the tracer id ‘trid’ (component, spec) by the suitable species name when in ensemble mode or do nothing when not in ensemble mode
- Parameters:
self – Model
trid (str, str) – Tracer id (component, species)
datastore (dict (str, str) -> Any) – Datastore
- Returns:
New tracer id
- Return type:
(str, str)
- pycif.plugins.models.lmdz_acc.io.inputs.fluxes.make_fluxes(self, datastore, ddi, ddf, runsubdir, mode)[source]#
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.
- Parameters:
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'.
- pycif.plugins.models.lmdz_acc.io.inputs.inicond.get_spec_var_name(self, spec: str) str[source]#
Return the LMDZ restart-file variable name for species spec.
Reads
spec_obj.restart_idfrom the chemistry plugin. Ifrestart_idis a string it is used directly; otherwise the species name is returned as-is.- Parameters:
self – LMDZ-ACC model plugin instance.
spec (str) – active species name.
- Returns:
variable name inside the LMDZ restart NetCDF file.
- Return type:
str
- pycif.plugins.models.lmdz_acc.io.inputs.inicond.write_inicond(self, var_name: str, filename: str, data: Dataset) None[source]#
Write one species’ initial-condition array into a LMDZ restart file.
Validates that data contains no NaN values before delegating to
self.inicond.write.- Parameters:
self – LMDZ-ACC model plugin instance.
var_name (str) – variable name in the restart file.
filename (str) – path to the restart NetCDF file to write.
data (xr.Dataset) – concentration data to write.
- Raises:
ValueError – if data contains NaN values.
- pycif.plugins.models.lmdz_acc.io.inputs.inicond.update_controle_var(self, ddi: datetime, target_path: str, source_path: str | None = None) None[source]#
Update start file with the controle variable from the configuration file ‘model’ paragraph or the ‘controle’ variable in ‘source_path’ file
- Parameters:
ddi (datetime)
source_path (str)
target_path (str)
- pycif.plugins.models.lmdz_acc.io.inputs.inicond.make_inicond(self, datastore, datei, datef, runsubdir, mode, onlyinit, ini_type='inicond')[source]#
Write or symlink the LMDZ-ACC initial-condition restart file.
For the first sub-simulation period only (
datei == self.datei). If concentrations in datastore were not modified by CIF, symlinks the original restart file. Otherwise copies the file and overwrites the relevant species variables usingwrite_inicond().Also updates the
controlevariable in the restart file viaupdate_controle_var()to align LMDZ’s internal clock with datei.- Parameters:
self – LMDZ-ACC model plugin instance.
datastore (dict) – tracer-ID-keyed CIF data-store entries.
datei (datetime) – period start date.
datef (datetime) – period end date.
runsubdir (str) – path to the period run directory.
mode (str) –
'fwd','tl', or'adj'.onlyinit (bool) – skip if
True(adjoint init pass).ini_type (str) – datastore key prefix;
'inicond'or'restart_inicond'.
- pycif.plugins.models.lmdz_acc.io.inputs.make_auxiliary.make_auxiliary(self, ddi, runsubdir, onlyinit=False, do_simu=True, mode='fwd', **kwargs)[source]#
Set up the LMDZ-ACC executable and input configuration for one sub-period.
Symlinks the correct LMDZ binary into runsubdir and calls
make_totinput()to write the LMDZ total-input configuration file. Returns immediately whendo_simu=Falseoronlyinit=True.- Parameters:
self – LMDZ-ACC model plugin instance with
workdirset.ddi (datetime) – sub-simulation period start.
runsubdir (str) – path to the period run directory.
onlyinit (bool) – skip if
True(adjoint initialisation pass).do_simu (bool) – skip if
False.mode (str) –
'fwd','tl', or'adj'.**kwargs – unused.
- pycif.plugins.models.lmdz_acc.io.inputs.make_endconcs.make_endconcs(self, datastore, runsubdir, mode, datei, datef, onlyinit, check_transforms=False)[source]#
Link LMDZ-ACC restart files into the period run directory.
Handles period chaining for all three execution modes:
Forward / TL (not onlyinit) — links the previous-period restart as initial conditions for the current period.
Adjoint, onlyinit — links the forward restart as the adjoint starting state.
Adjoint, not onlyinit — links the adjoint restart initialised to zero sensitivities.
- Parameters:
self – LMDZ-ACC model plugin instance (carries
adj_refdir).datastore (dict) – tracer-ID-keyed data-store entries with
fileorigpaths.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) –
Trueduring adjoint initialisation.check_transforms (bool) – unused; kept for API compatibility.
- pycif.plugins.models.lmdz_acc.io.inputs.meteo.make_meteo(self, data, ddi, ddf, runsubdir, mode)[source]#
Link LMDZ-ACC meteorological input files into the period run directory.
Symlinks
defstoke.nc(mass fluxes) and other required meteo files from the original source directory (data[("meteo","")]["dirorig"]) into runsubdir.- Parameters:
self – LMDZ-ACC model plugin instance.
data (dict) – meteo CIF data-store (carries
dirorigpath).ddi (datetime) – period start date.
ddf (datetime) – period end date.
runsubdir (str) – path to the period run directory.
mode (str) –
'fwd','tl', or'adj'.
- pycif.plugins.models.lmdz_acc.io.inputs.obs.make_obs(self, ddi, datastore, runsubdir, mode, tracer, input_type, do_simu=True)[source]#
Dumps observation locations and time steps to obs.bin to let LMDZ know where to extract concentrations.
- pycif.plugins.models.lmdz_acc.io.inputs.params.make_totinput(self, runsubdir, datei, mode, footprint='F')[source]#
Makes a totinput file, storing the main simulation parameters: - number of effective tracers - using SACS (T) or not (F) - spliting of dynamic timestep - spliting of physical timestep - read start file (T) or not (F) - forward (T) or backward (F) - output diagnostics - output wfunc or not (T or F) - if footprint (to change number of days 28 to 30..) - ndayloc, number of days in the month - convOH = T if vmr or F if molec/cm3 - conv_scheme = - physic = T if run physics
- pycif.plugins.models.lmdz_acc.io.outputs.fake_end.read_obs(runsubdir: str) Tuple[int, ndarray, ndarray][source]#
Reads ‘tstep’ and species index columns from ‘obs.bin’ the binary file and convert from Fortran to Python indices (i = i - 1)
- Parameters:
runsubdir (str) – runsubdir (str): sub simulation run directory
- Returns:
number of observations, tstep, species index
- Return type:
(int, 1D array, 1D array)
- pycif.plugins.models.lmdz_acc.io.outputs.fake_end.read_air_mass(self: Any, ddi: datetime, runsubdir: str) DataArray[source]#
Read the LMDZ-ACC air-mass field from the run directory.
Opens the air-mass NetCDF file for the month containing ddi and returns a DataArray on the CIF domain grid.
- Parameters:
self – LMDZ-ACC model plugin instance.
ddi – period start date.
runsubdir – path to the period run directory.
- Returns:
air-mass field on
(time, lev, lat, lon)grid.- Return type:
xr.DataArray
- pycif.plugins.models.lmdz_acc.io.outputs.fake_end.read_emissions(self: Any, ddi: datetime, runsubdir: str) Tuple[DataArray, DataArray][source]#
Reads emissions ‘mod_*.bin’ binary files
- Parameters:
self (Model)
ddi (datetime.datetime) – sub simulation start datetime
runsubdir (str) – runsubdir (str): sub simulation run directory
- Returns:
emissions forward, emissions tangent
- Return type:
(xr.DataArray, xr.DataArray)
- pycif.plugins.models.lmdz_acc.io.outputs.fake_end.time_slice(da: DataArray, di: datetime64, df: datetime64, agg_method: Literal['mean', 'sum'] = 'mean') DataArray[source]#
Pick the values of a DataArray between ‘di’ and ‘df’ and aggregate along the time dimension
- Parameters:
da (xr.DataArray) – input DataArray with ‘time’ dimension and coordinate
di (np.datetime64) – slice start
df (np.datetime64) – slice end (NOT included)
agg_method ("mean" or "sum", optional) – aggregation method. Defaults to “mean”.
- Returns:
sliced and aggregated DataArray
- Return type:
xr.DataArray
- pycif.plugins.models.lmdz_acc.io.outputs.fake_end.restart_id_to_var_name(restart_id: int | str) str[source]#
Convert a LMDZ restart ID to a NetCDF variable name.
- Parameters:
restart_id – integer (→
'qNN') or string (used as-is).- Returns:
NetCDF variable name.
- Return type:
str
- pycif.plugins.models.lmdz_acc.io.outputs.fake_end.get_var_name(self: Any, spec: str) str[source]#
Return the restart NetCDF variable name for species spec.
Reads
restart_idfrom the chemistry plugin and delegates torestart_id_to_var_name().- Parameters:
self – LMDZ-ACC model plugin instance.
spec – active species name.
- Returns:
NetCDF variable name.
- Return type:
str
- pycif.plugins.models.lmdz_acc.io.outputs.fake_end.perturb_ref_restart(self: Any, ddi: datetime, restart_file: str, ref_restart: str) None[source]#
Write a perturbed LMDZ-ACC restart file by copying from a reference.
Copies ref_restart to restart_file and overwrites the active-species variables with the CIF-modified concentrations from
self.inicond. Species listed inself.dont_perturb_speciesare left unchanged.- Parameters:
self – LMDZ-ACC model plugin instance.
ddi – period start date.
restart_file – path to the output (perturbed) restart file.
ref_restart – path to the reference restart file to copy from.
- pycif.plugins.models.lmdz_acc.io.outputs.fake_end.make_end(self: Any, runsubdir: str, ddi: datetime, ref_fwd_dir: str) None[source]#
TODO
- Parameters:
self (Model)
ddi (datetime.datetime) – sub simulation start datetime
runsubdir (str) – sub simulation run directory
ref_fwd_dir (str) – reference forward run directory
- pycif.plugins.models.lmdz_acc.io.outputs.fake_sim.write_sim(data, runsubdir)[source]#
Write mock obs_out.bin file
- pycif.plugins.models.lmdz_acc.io.outputs.fake_sim.write_obs(data, runsubdir)[source]#
Write mock obs.bin file
- pycif.plugins.models.lmdz_acc.io.outputs.fetch_end.fetch_end(self, data2dump, runsubdir, mode, ddi, ddf, check_transforms=False, onlyinit=False)[source]#
Register end-concentration restart paths after a LMDZ-ACC run.
For forward / TL mode: records the restart file path (
chain/restart_YYYYMMDDHHMM.nc) in data2dump.For adjoint mode: records the adjoint restart path and optionally reads the sensitivity fields back into the data store when check_transforms is active.
- Parameters:
self – LMDZ-ACC model plugin instance.
data2dump (dict) – tracer-ID-keyed data-store entries to update.
runsubdir (str) – path to the period run directory.
mode (str) –
'fwd','tl', or'adj'.ddi (datetime) – period start date.
ddf (datetime) – period end date (unused).
check_transforms (bool) – if
True, also read sensitivity back.onlyinit (bool) – skip reading if
True.
- Returns:
updated data2dump.
- Return type:
dict
- pycif.plugins.models.lmdz_acc.io.outputs.fetch_end.make_restart_adj(self, runsubdir, ddi, ref_fwd_dir)[source]#
Create a zeroed LMDZ-ACC adjoint restart file for the current period.
Copies the reference forward restart to the adjoint run directory and zeros all active-species mass mixing ratios so the LMDZ-ACC adjoint can accumulate sensitivities.
- Parameters:
self – LMDZ-ACC model plugin instance.
runsubdir (str) – path to the period run directory.
ddi (datetime) – period start date.
ref_fwd_dir (str) – directory of the reference forward run.
- pycif.plugins.models.lmdz_acc.io.outputs.make_mod_out.findspec(charspec, iallqmax, all_species)[source]#
Find the index of a species by name in the LMDZ-ACC species list.
- Parameters:
charspec (str) – species name to search for.
iallqmax (int) – total number of species.
all_species (list[dict]) – list of species dicts with a
'name'key.
- Returns:
0-based index of charspec in all_species, or
-1if not found.- Return type:
int
- pycif.plugins.models.lmdz_acc.io.outputs.make_mod_out.comp_rates(nreac, temp, pmid, idtyperate, tabrate)[source]#
Compute gas-phase reaction rates for the LMDZ-ACC chemistry scheme.
Evaluates reaction rate expressions of multiple types (constant, Arrhenius, pressure-dependent, …) using lookup table tabrate and the atmospheric state (temp, pmid).
- Parameters:
nreac (int) – number of reactions.
temp (np.ndarray) – temperature field (K), shape
(...).pmid (np.ndarray) – mid-level pressure field (Pa), same shape.
idtyperate (np.ndarray) – integer reaction-type codes, shape
(nreac,).tabrate (np.ndarray) – rate constant table, shape
(nparams, nreac).
- Returns:
reaction rates, shape
temp.shape + (nreac,).- Return type:
np.ndarray
- pycif.plugins.models.lmdz_acc.io.outputs.make_mod_out.make_chem_modout(self, runsubdir, ddi, inicond, inicond_ad)[source]#
Compute adjoint sensitivity of initial conditions through the chemistry scheme.
Reads the chemical scheme (reactions, stoichiometry, rate parameters) from the LMDZ-ACC run directory, integrates chemical production/loss over the period using
comp_rates(), and propagates the adjoint sensitivity inicond_ad backward through the chemistry operator to produce sensitivity w.r.t. initial mass mixing ratios.- Parameters:
self – LMDZ-ACC model plugin instance (carries chemistry and domain).
runsubdir (str) – path to the period run directory.
ddi (datetime) – period start date.
inicond (np.ndarray) – forward initial conditions (mass mixing ratio).
inicond_ad (np.ndarray) – adjoint sensitivity at period end.
- Returns:
adjoint sensitivity w.r.t. initial conditions, same shape as inicond_ad.
- Return type:
np.ndarray
- pycif.plugins.models.lmdz_acc.io.outputs.make_mod_out.make_mod_out(self, runsubdir, ddi, ref_fwd_dir)[source]#
Create a zeroed LMDZ-ACC adjoint-output restart file for the current period.
Reads the reference forward restart file from ref_fwd_dir, copies it to the adjoint run directory, and zeros out all active-species mass mixing ratios so the LMDZ-ACC adjoint executable can accumulate sensitivities into it.
- Parameters:
self – LMDZ-ACC model plugin instance (carries domain and chemistry).
runsubdir (str) – path to the period run directory.
ddi (datetime) – period start date.
ref_fwd_dir (str) – directory of the reference forward run.
- pycif.plugins.models.lmdz_acc.io.outputs.read_sim.read_binary(path, ncols)[source]#
Read a Fortran-order binary float file into a 2-D NumPy array.
- Parameters:
path (str) – path to the binary file.
ncols (int) – number of columns in the output array.
- Returns:
shape
(nrows, ncols)float64 array.- Return type:
np.ndarray
- pycif.plugins.models.lmdz_acc.io.outputs.read_sim.read_obs(runsubdir)[source]#
Read LMDZ-ACC simulated observation binary output.
Reads
obs.binfrom runsubdir (6-column Fortran-order float binary). Returns a zero-row array when the file does not exist.- Parameters:
runsubdir (str) – path to the period run directory.
- Returns:
shape
(nobs, 6)observation array.- Return type:
np.ndarray