openghg_inversions.rhime#
Public RHIME API.
- class openghg_inversions.rhime.RhimeModelSpec(species: str, domain: str, sectors: tuple[SectorSpec, ...], use_bc: bool = True, sigma_per_site: bool = True, add_offset: bool = False, pollution_events_from_obs: bool = False, no_model_error: bool = False, power: dict[str, Any] | float = 1.99, bc_prior: dict[str, Any] | None = None, sigma_prior: dict[str, Any] | None = None, offset_prior: dict[str, Any] | None = None, offset_args: dict[str, Any] | None = None)#
Bases:
objectModel options used to build a RHIME PyMC model.
- Parameters:
species – Primary gas or tracer name used for object-store lookup and output naming.
domain – Model domain name.
sectors – Flux sectors included in the model. Each sector is optimized separately and is normally backed by one OpenGHG flux
source.use_bc – Whether boundary-condition scaling is included.
sigma_per_site – Whether model-error terms vary by site.
add_offset – Whether model-data offsets are included.
pollution_events_from_obs – Whether model error scales with observed enhancements instead of modelled enhancements.
no_model_error – Whether explicit model-error terms are disabled.
power – Exponent or prior specification used in likelihood error scaling.
bc_prior – Prior specification for boundary-condition scaling factors.
sigma_prior – Prior specification for model-error terms.
offset_prior – Prior specification for optional offsets.
offset_args – Extra keyword arguments forwarded to the offset component.
- sectors: tuple[SectorSpec, ...]#
- class openghg_inversions.rhime.RhimeOutputSpec(output_format: Literal['none', 'inv_out', 'basic', 'paris', 'legacy'] = 'inv_out', output_path: str | None = None, output_name: str = 'rhime', save_trace: str | Path | bool = False, save_inversion_output: str | Path | bool = True, country_file: str | None = None, paris_postprocessing_kwargs: dict[str, Any] | None = None, output_filename_convention: Literal['rhime', 'legacy'] = 'rhime')#
Bases:
objectOutput settings for a RHIME run.
- Parameters:
output_format – Output mode.
"inv_out"saves/returns the modern inversion output,"basic"and"paris"additionally create derived outputs,"legacy"creates the old HBMCMC-compatible NetCDF product from modern RHIME output, and"none"skips output products.output_path – Directory for saved outputs.
output_name – Base output name.
save_trace – Trace save setting. If true, save to
output_pathusing the default trace file name; if a path, save there.save_inversion_output – Inversion-output save setting. Runner parameter normalization defaults this to true for
output_format="inv_out"and false for derived product formats.country_file – Optional country mask file used by derived outputs.
paris_postprocessing_kwargs – Extra keyword arguments for PARIS output creation.
output_filename_convention – Filename convention for derived products. Direct RHIME runs use
"rhime". Therun_hbmcmc.pycompatibility shim uses"legacy"for old SLURM/config workflows.
- class openghg_inversions.rhime.RhimeResult(run_spec: RhimeRunSpec, model_spec: RhimeModelSpec, output_spec: RhimeOutputSpec, inv_inputs: Dataset, idata: InferenceData, output_metadata: dict[str, ~typing.Any]=<factory>, outputs: dict[str, ~typing.Any]=<factory>, basis_functions: FluxWeightedBasis | None = None, model: Model | None = None, inv_out: InversionOutput | None = None, sampler: RhimeSampler = <factory>)#
Bases:
objectModern RHIME run result.
- Parameters:
run_spec – Top-level run metadata.
model_spec – Model specification used to build the PyMC model.
output_spec – Output settings used by the run.
inv_inputs – Canonical xarray inversion inputs consumed by the model.
idata – ArviZ
InferenceDatareturned by sampling.output_metadata – Paths and notes for generated outputs.
outputs – In-memory derived outputs keyed by output kind.
model – Built PyMC model.
inv_out – Modern inversion output object when created.
basis_functions – Retained flux basis functions from preparation.
sampler – Sampler settings used by the run.
- basis_functions: FluxWeightedBasis | None = None#
- idata: InferenceData#
- inv_out: InversionOutput | None = None#
- model_spec: RhimeModelSpec#
- output_spec: RhimeOutputSpec#
- run_spec: RhimeRunSpec#
- sampler: RhimeSampler#
- class openghg_inversions.rhime.RhimeRunSpec(start_date: str, end_date: str, sites: tuple[str, ...], averaging_period: tuple[str | None, ...], model: RhimeModelSpec, output: RhimeOutputSpec, split_by_sectors: bool = False)#
Bases:
objectTop-level run metadata for a RHIME run.
- Parameters:
start_date – Inclusive inversion start date.
end_date – Exclusive inversion end date.
sites – Sites included after data preparation and filtering.
averaging_period – Observation averaging period per retained site.
model – Mathematical model specification.
output – Output settings.
split_by_sectors – Whether flux data were prepared in sector-resolved mode. Single-sector and multi-sector RHIME are runner/model modes; this flag records the prepared data layout.
- model: RhimeModelSpec#
- output: RhimeOutputSpec#
- class openghg_inversions.rhime.RhimeSampler(*, draws: int = 1000, burn: int = 0, tune: int = 1000, chains: int = 4, nuts_sampler: Literal['pymc', 'nutpie', 'numpyro', 'blackjax'] | str = 'pymc', progressbar: bool = False, sample_kwargs: dict[str, Any] | None = None, sample_prior_predictive: bool | int = True, sample_posterior_predictive: bool | Sequence[str] = ('y',), posterior_predictive_kwargs: dict[str, Any] | None = None)#
Bases:
objectPyMC sampler configuration and execution for RHIME models.
- Parameters:
draws – Number of post-tuning draws requested from PyMC.
burn – Number of draws to discard from each chain after sampling.
tune – Number of PyMC tuning draws.
chains – Number of MCMC chains.
nuts_sampler – PyMC NUTS backend name.
progressbar – Whether PyMC progress output should be shown.
sample_kwargs – Extra keyword arguments forwarded to
pm.sample.sample_prior_predictive – Whether to append prior predictive draws.
sample_posterior_predictive – Whether to append posterior predictive draws, or variable names to sample.
posterior_predictive_kwargs – Extra keyword arguments forwarded to
pm.sample_posterior_predictive.
- class openghg_inversions.rhime.SectorSpec(name: str, flux_source: str, x_prior: dict[str, Any], variable_suffix: str)#
Bases:
objectConfiguration for one separately optimised flux sector.
- Parameters:
name – User-facing sector name.
flux_source – OpenGHG flux
sourceused to retrieve this sector.x_prior – Prior specification for this sector’s flux scaling factors.
variable_suffix – PyMC-safe suffix used in multi-sector model variable names. Standard single-sector RHIME uses plain
x/munames.
- openghg_inversions.rhime.params_from_config(config_file: str | Path, *, start_date: str | None = None, end_date: str | None = None, output_path: str | None = None, extra_kwargs: Mapping[str, Any] | None = None) dict[str, Any]#
Load RHIME run parameters from an INI config file.
- Parameters:
config_file – Path to an INI configuration file.
start_date – Optional command-line start-date override.
end_date – Optional command-line end-date override.
output_path – Optional command-line output-path override.
extra_kwargs – Optional keyword overrides, normally parsed from CLI JSON.
- Returns:
Normalized RHIME run parameters using snake-case public names.
- Raises:
ValueError – If deprecated unsupported parameters are present or a structured RHIME option has an invalid type.
- openghg_inversions.rhime.resolve_flux_sources(*, flux_sources: str | Sequence[str] | None = None, emissions_name: str | Sequence[str] | None = None) list[str]#
Resolve new
flux_sourcesand legacyemissions_namearguments.- Parameters:
flux_sources – Preferred RHIME field containing OpenGHG flux
sourcemetadata values.emissions_name – Legacy compatibility spelling accepted only when
flux_sourcesis absent.
- Returns:
Resolved flux source names.
- Raises:
ValueError – If no usable flux source is supplied.
- openghg_inversions.rhime.run_rhime(*, config_file: str | Path | None = None, **kwargs: Any) RhimeResult#
Run a standard single-sector RHIME inversion.
- Parameters:
config_file – Optional INI configuration file. Values in
kwargsoverride values read from this file.**kwargs – RHIME run parameters using snake-case names, such as
output_path,output_name,flux_sources, andx_prior.speciesnames the primary gas or tracer used for object-store lookup and output naming.flux_sourcescontains OpenGHG fluxsourcevalues. Legacyemissions_nameis accepted only as a compatibility alias whenflux_sourcesis absent.
- Returns:
Modern RHIME result containing canonical inputs, InferenceData, specs, output metadata, and generated outputs.
- Raises:
ValueError – If required parameters are missing, unsupported parameters are supplied, or the flux-source count is invalid.
- openghg_inversions.rhime.run_rhime_multisector(*, config_file: str | Path | None = None, **kwargs: Any) RhimeResult#
Run a shared-basis multi-sector RHIME inversion.
- Parameters:
config_file – Optional INI configuration file. Values in
kwargsoverride values read from this file.**kwargs – RHIME run parameters using snake-case names. Multi-sector runs require at least two
flux_sourcesand may includesector_priorskeyed by sector name. When model sector labels differ from OpenGHG source values, passsector_sourcesas a mapping from sector name to one value influx_sources. Legacyemissions_nameis accepted only as a compatibility alias whenflux_sourcesis absent.
- Returns:
Modern RHIME result containing canonical inputs, InferenceData, specs, output metadata, and sector diagnostics.
- Raises:
ValueError – If required parameters are missing, unsupported parameters are supplied, or fewer than two flux sources are provided.
- openghg_inversions.rhime.outputs
- openghg_inversions.rhime.params
RhimeRunnerSetupas_list()coerce_simple_param_types()is_missing_required_value()make_rhime_runner_setup()normalise_optional_mapping()normalise_output_format_alias()normalise_param_aliases()normalise_rhime_params()normalise_sector_priors()normalise_sector_sources()params_from_config()required_run_params()resolve_flux_sources()validate_multisector_x_prior()validate_required_params()validate_rhime_param_types()validate_supported_params()
- openghg_inversions.rhime.runner
RhimeModelSpecRhimeModelSpec.add_offsetRhimeModelSpec.bc_priorRhimeModelSpec.domainRhimeModelSpec.no_model_errorRhimeModelSpec.offset_argsRhimeModelSpec.offset_priorRhimeModelSpec.pollution_events_from_obsRhimeModelSpec.powerRhimeModelSpec.sectorsRhimeModelSpec.sigma_per_siteRhimeModelSpec.sigma_priorRhimeModelSpec.speciesRhimeModelSpec.use_bc
RhimeOutputSpecRhimeResultRhimeRunSpecRhimeSamplerSectorSpecparams_from_config()resolve_flux_sources()run_rhime()run_rhime_multisector()
- openghg_inversions.rhime.sampling
- openghg_inversions.rhime.specs