pycif.plugins.models.lmdz_old — API reference#

Configuration reference: lmdz_old plugin

pycif.plugins.models.lmdz_old.compile.compile(self)[source]#

Compile or copy LMDZ-old executables into the CIF work directory.

Attempts to copy pre-compiled binaries from self.direxec first (skipped if force-recompile is set), then falls back to running make inside the LMDZ source tree.

Parameters:

self – LMDZ-old model plugin instance with workdir and direxec (or dirsrc) set.

pycif.plugins.models.lmdz_old.flushrun.flushrun(self, rundir, mode, transform_id, full_flush=True)[source]#

Cleaning the simulation directories to limit space usage

pycif.plugins.models.lmdz_old.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-old (legacy structured-grid) model.

Functionally identical to the LMDZ-ACC mapper: declares flux, meteo, initial-condition, end-concentration, and optionally observation inputs, plus concentration and diagnostic outputs. Populates outputs2inputs for adjoint routing.

Parameters:
  • model – LMDZ-old 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, and outputs2inputs.

Return type:

dict

pycif.plugins.models.lmdz_old.ini_periods.ini_periods(self, **kwargs)[source]#

Compute temporal discretisation for the LMDZ-old model.

Identical in structure to the LMDZ-ACC ini_periods: splits the simulation window into monthly (or self.periods-based) sub-periods and derives time-step arrays from the domain’s dynamical/physical split and the meteorological offset time step.

Sets on self: subsimu_dates, tstep_dates, input_dates, flx_input_dates, tstep_all, iniobs, reset_obs, chain.

Parameters:
  • self – LMDZ-old model plugin instance with datei, datef, periods, domain, and meteo set.

  • **kwargs – unused.

pycif.plugins.models.lmdz_old.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_old.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_old.perturb_model.perturb_model(self, nsamples, transf_mapper)[source]#

Extend the LMDZ-old chemistry scheme to accommodate ensemble members.

Creates nsamples copies of each active, output, and emitted species using the __sample#NNN naming convention, then removes the original un-suffixed species. Records self.perturbed_species mapping sample names back to originals.

Parameters:
  • self – LMDZ-old model plugin instance.

  • nsamples (int) – number of ensemble members.

  • transf_mapper (dict) – unused; kept for API consistency.

pycif.plugins.models.lmdz_old.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_old.run.dump2nc(self, runsubdir)[source]#

Dumps simulated concentration field to a netCDF file

class pycif.plugins.models.lmdz_old.chemistry.chemical_scheme.Species(name: str, type: Literal['ac', 'pr'], index: int = -1, restart_id: int = -1)[source]#

Bases: object

A 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#
is_active() bool[source]#

Return True if this species is an active (transported) tracer.

is_prescribed() bool[source]#

Return True if this species is prescribed (fixed boundary condition).

class pycif.plugins.models.lmdz_old.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: object

A 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_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]#
rates(temp: DataArray, pmid: DataArray) DataArray[source]#

Compute reaction rates

Parameters:
  • temp (xr.DataArray) – temperature field [K]

  • pmid (xr.DataArray) – pressure field [Pa]

Returns:

rates [molec/cm2/s2]

Return type:

xr.DataArray

pycif.plugins.models.lmdz_old.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

Parameters:

self (Model)

Returns:

list of reactions, molar masses

Return type:

(list of Reaction, xr.DataArray)

pycif.plugins.models.lmdz_old.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_old.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_old.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_old.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_old.chemistry.read_inputs.read_kinetic(self: Any, ddi: datetime, runsubdir: str) Dataset[source]#

Read the LMDZ-old kinetic (pressure/temperature) field from the run directory.

Opens kinetic.nc, renames dimensions to CIF conventions, and trims to the month’s day count.

Parameters:
  • self – LMDZ-old model plugin instance.

  • ddi – period start date.

  • runsubdir – path to the period run directory.

Returns:

xr.Dataset with pmid and temp variables.

pycif.plugins.models.lmdz_old.chemistry.read_inputs.read_prescr(self: Any, ddi: datetime, runsubdir: str) DataArray[source]#

Read prescribed-concentration fields from the LMDZ-old run directory.

Reads prescr.nc for all prescribed species and aligns time to the month containing ddi.

Parameters:
  • self – LMDZ-old model plugin instance.

  • ddi – period start date.

  • runsubdir – path to the period run directory.

Returns:

xr.DataArray of prescribed concentrations.

pycif.plugins.models.lmdz_old.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_old.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_old.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_old.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_old.io.inputs.chemfields.make_chemfields(self, datastore, input_type, ddi, ddf, runsubdir, mode)[source]#

Write a chemical concentration field for LMDZ-old.

Reads the CIF data for input_type and writes it as a NetCDF input file in runsubdir. If no CIF modification, symlinks the original.

Parameters:
  • self – LMDZ-old model plugin instance.

  • datastore (dict) – tracer-ID-keyed CIF data-store entries.

  • input_type (str) – chemistry field 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_old.io.inputs.chemfields.make_kinetic(self, datastore, input_type, ddi, ddf, runsubdir, mode)[source]#

Write the LMDZ-old kinetic (pressure/temperature) field for one period.

Reads the CIF kinetic data-store and writes kinetic.nc in runsubdir.

Parameters:
  • self – LMDZ-old model plugin instance.

  • datastore (dict) – kinetic CIF data-store entries.

  • input_type (str) – 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_old.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_old.io.inputs.fluxes.make_fluxes(self, datastore, ddi, ddf, runsubdir, mode)[source]#

Write LMDZ-old flux input files for one sub-simulation period.

For each emitted species, fetches the CIF flux field from datastore and writes it to the LMDZ flux file under runsubdir.

Parameters:
  • self – LMDZ-old 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_old.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_id from the chemistry plugin. If restart_id is an int it is formatted as qNN; if a string it is used directly.

Parameters:
  • self – LMDZ-old model plugin instance.

  • spec (str) – active species name.

Returns:

variable name inside the LMDZ restart NetCDF file.

Return type:

str

pycif.plugins.models.lmdz_old.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-old 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_old.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_old.io.inputs.inicond.make_inicond(self, datastore, datei, datef, runsubdir, mode, onlyinit, ini_type='inicond')[source]#

Write or symlink the LMDZ-old 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. Updates the controle variable to align LMDZ’s internal clock with datei.

Parameters:
  • self – LMDZ-old 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.

  • ini_type (str) – datastore key prefix.

pycif.plugins.models.lmdz_old.io.inputs.make_auxiliary.make_auxiliary(self, ddi, runsubdir, onlyinit=False, do_simu=True, mode='fwd', **kwargs)[source]#

Set up the LMDZ-old executable and configuration for one sub-period.

Symlinks the correct LMDZ binary and calls make_totinput() to write the LMDZ total-input configuration file. Returns immediately when do_simu=False or onlyinit=True.

Parameters:
  • self – LMDZ-old 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.

pycif.plugins.models.lmdz_old.io.inputs.make_endconcs.make_endconcs(self, datastore, runsubdir, mode, datei, datef, onlyinit, check_transforms=False)[source]#

Link LMDZ-old restart files into the period run directory.

Handles period chaining: links the previous-period restart as initial conditions for forward / TL runs, or links the forward reference restart for adjoint initialisation.

Parameters:
  • self – LMDZ-old model plugin instance.

  • datastore (dict) – tracer-ID-keyed data-store entries.

  • 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) – True during adjoint initialisation.

  • check_transforms (bool) – unused.

pycif.plugins.models.lmdz_old.io.inputs.meteo.make_meteo(self, data, ddi, ddf, runsubdir, mode)[source]#

Link LMDZ-old meteorological input files into the period run directory.

Symlinks defstoke.nc and other required meteo files from the original source directory into runsubdir.

Parameters:
  • self – LMDZ-old model plugin instance.

  • data (dict) – meteo CIF data-store (carries dirorig path).

  • 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_old.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_old.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_old.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_old.io.outputs.fake_end.read_air_mass(self: Any, ddi: datetime, runsubdir: str) DataArray[source]#

Read the LMDZ-old air-mass field from the run directory.

Parameters:
  • self – LMDZ-old 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_old.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_old.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_old.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_old.io.outputs.fake_end.get_var_name(self: Any, spec: str) str[source]#

Return the restart NetCDF variable name for species spec.

Parameters:
  • self – LMDZ-old model plugin instance.

  • spec – active species name.

Returns:

NetCDF variable name.

Return type:

str

pycif.plugins.models.lmdz_old.io.outputs.fake_end.perturb_ref_restart(self: Any, ddi: datetime, restart_file: str, ref_restart: str) None[source]#

Write a perturbed LMDZ-old restart file by copying from a reference.

Copies ref_restart to restart_file and overwrites active-species variables with CIF-modified concentrations. Species in self.dont_perturb_species are left unchanged.

Parameters:
  • self – LMDZ-old model plugin instance.

  • ddi – period start date.

  • restart_file – output restart path.

  • ref_restart – reference restart path to copy from.

pycif.plugins.models.lmdz_old.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_old.io.outputs.fake_sim.write_sim(data, runsubdir)[source]#

Write mock obs_out.bin file

pycif.plugins.models.lmdz_old.io.outputs.fake_sim.write_obs(data, runsubdir)[source]#

Write mock obs.bin file

pycif.plugins.models.lmdz_old.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-old run.

For forward / TL mode: records the chain/restart_*.nc path in data2dump. For adjoint mode: optionally reads sensitivity fields back into the data store when check_transforms is active.

Parameters:
  • self – LMDZ-old 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_old.io.outputs.fetch_end.make_restart_adj(self, runsubdir, ddi, ref_fwd_dir)[source]#

Create a zeroed LMDZ-old 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.

Parameters:
  • self – LMDZ-old 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_old.io.outputs.make_mod_out.findspec(charspec, iallqmax, all_species)[source]#

Find the index of a species by name in the LMDZ-old 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, or -1 if not found.

Return type:

int

pycif.plugins.models.lmdz_old.io.outputs.make_mod_out.comp_rates(nreac, temp, pmid, idtyperate, tabrate)[source]#

Compute gas-phase reaction rates for the LMDZ-old chemistry scheme.

Parameters:
  • nreac (int) – number of reactions.

  • temp (np.ndarray) – temperature field (K).

  • pmid (np.ndarray) – mid-level pressure field (Pa).

  • idtyperate (np.ndarray) – integer rate-type codes, shape (nreac,).

  • tabrate (np.ndarray) – rate constant table.

Returns:

reaction rates, shape temp.shape + (nreac,).

Return type:

np.ndarray

pycif.plugins.models.lmdz_old.io.outputs.make_mod_out.make_chem_modout(self, runsubdir, ddi, inicond, inicond_ad)[source]#

Compute adjoint sensitivity of initial conditions through the LMDZ-old chemistry.

Integrates chemical production/loss and back-propagates inicond_ad through the chemistry operator to yield sensitivity w.r.t. initial mass mixing ratios.

Parameters:
  • self – LMDZ-old model plugin instance.

  • runsubdir (str) – path to the period run directory.

  • ddi (datetime) – period start date.

  • inicond (np.ndarray) – forward initial conditions.

  • inicond_ad (np.ndarray) – adjoint sensitivity at period end.

Returns:

adjoint sensitivity w.r.t. initial conditions.

Return type:

np.ndarray

pycif.plugins.models.lmdz_old.io.outputs.make_mod_out.make_mod_out(self, runsubdir, ddi, ref_fwd_dir)[source]#

Create a zeroed LMDZ-old adjoint-output restart file.

Reads the reference forward restart from ref_fwd_dir, copies it to the adjoint run directory, and zeros all active-species mass mixing ratios.

Parameters:
  • self – LMDZ-old 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_old.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.

Returns:

shape (nrows, ncols) float64 array.

Return type:

np.ndarray

pycif.plugins.models.lmdz_old.io.outputs.read_sim.read_obs(runsubdir)[source]#

Read LMDZ-old simulated observation binary output.

Reads obs.bin (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

pycif.plugins.models.lmdz_old.io.outputs.read_sim.read_sim(self, data2dump, runsubdir, mode, ddi, ddf)[source]#

Read the mod.txt file as simulated by LMDz