openghg_inversions.models.rhime#

RHIME model builders.

These builders are the modern public model-construction names. They reuse the component-based PyMC helpers, while keeping the legacy inferpymc adapter out of the RHIME runtime path.

The standard builder optimizes one flux scaling component. The multi-sector builder optimizes one component per sector, where each sector is normally backed by one OpenGHG flux source coordinate in inv_inputs["H"]. When sector labels differ from OpenGHG source values, the builder selects data by source and names PyMC variables by sector.

class openghg_inversions.models.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: object

Model 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.

add_offset: bool = False#
bc_prior: dict[str, Any] | None = None#
domain: str#
no_model_error: bool = False#
offset_args: dict[str, Any] | None = None#
offset_prior: dict[str, Any] | None = None#
pollution_events_from_obs: bool = False#
power: dict[str, Any] | float = 1.99#
sectors: tuple[SectorSpec, ...]#
sigma_per_site: bool = True#
sigma_prior: dict[str, Any] | None = None#
species: str#
use_bc: bool = True#
class openghg_inversions.models.rhime.SectorSpec(name: str, flux_source: str, x_prior: dict[str, Any], variable_suffix: str)#

Bases: object

Configuration for one separately optimised flux sector.

Parameters:
  • name – User-facing sector name.

  • flux_source – OpenGHG flux source used 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/mu names.

flux_source: str#
name: str#
variable_suffix: str#
x_prior: dict[str, Any]#
openghg_inversions.models.rhime.build_rhime_model(inv_inputs: Dataset, *, x_prior: dict | None = None, bc_prior: dict | None = None, sigma_prior: dict | None = None, sigma_per_site: bool = True, offset_prior: dict | None = None, add_offset: bool = False, use_bc: bool = True, pollution_events_from_obs: bool = False, no_model_error: bool = False, offset_args: dict | None = None, power: dict | float = 1.99) Model#

Build the standard single-sector RHIME model.

Parameters:
  • inv_inputs – Canonical inversion-input dataset produced by make_inv_inputs.

  • x_prior – Prior specification for flux scaling factors.

  • bc_prior – Prior specification for boundary-condition scaling factors.

  • sigma_prior – Prior specification for model-error terms.

  • sigma_per_site – Whether model-error terms vary by site.

  • offset_prior – Prior specification for optional offsets.

  • add_offset – Whether to include an offset term.

  • use_bc – Whether to include boundary-condition terms.

  • pollution_events_from_obs – Whether to derive pollution-event scaling from observations rather than modelled concentrations.

  • no_model_error – Whether to suppress the explicit model-error term.

  • offset_args – Extra keyword arguments forwarded to the offset component.

  • power – Exponent or prior specification used in likelihood error scaling.

Returns:

Built PyMC model.

openghg_inversions.models.rhime.build_rhime_model_from_spec(inv_inputs: Dataset, model_spec: RhimeModelSpec) Model#

Build the standard single-sector RHIME model from a model spec.

Parameters:
  • inv_inputs – Canonical inversion-input dataset produced by make_inv_inputs.

  • model_spec – Normalized RHIME model specification.

Returns:

Built PyMC model.

Raises:

ValueError – If the model spec does not describe exactly one sector.

openghg_inversions.models.rhime.build_rhime_multisector_model(inv_inputs: Dataset, *, sectors: Sequence[str] | None = None, sector_sources: Mapping[str, str] | None = None, sector_variable_suffixes: Mapping[str, str] | None = None, sector_priors: Mapping[str, dict] | None = None, x_prior: dict | None = None, bc_prior: dict | None = None, sigma_prior: dict | None = None, sigma_per_site: bool = True, offset_prior: dict | None = None, add_offset: bool = False, use_bc: bool = True, pollution_events_from_obs: bool = False, no_model_error: bool = False, offset_args: dict | None = None, power: dict | float = 1.99) Model#

Build the first shared-basis multi-sector RHIME model.

Each sector receives its own state vector x_<sector> and forward-model contribution mu_<sector>. The total mu is the sum of sector contributions and is passed to the standard RHIME likelihood.

Parameters:
  • inv_inputs – Canonical inversion-input dataset with H(region, nmeasure, source).

  • sectors – Ordered model sector labels to optimize. Defaults to sector_sources keys when supplied, otherwise all inv_inputs.H.source values, where each source becomes one separately optimized sector.

  • sector_sources – Optional mapping from sector label to OpenGHG source value in inv_inputs.H.

  • sector_variable_suffixes – Optional mapping from sector label to PyMC-safe suffix used in x_<suffix> and mu_<suffix> names.

  • sector_priors – Optional per-sector flux-scaling priors.

  • x_prior – Shared fallback flux-scaling prior.

  • bc_prior – Prior specification for boundary-condition scaling factors.

  • sigma_prior – Prior specification for model-error terms.

  • sigma_per_site – Whether model-error terms vary by site.

  • offset_prior – Prior specification for optional offsets.

  • add_offset – Whether to include an offset term.

  • use_bc – Whether to include boundary-condition terms.

  • pollution_events_from_obs – Whether to derive pollution-event scaling from observations rather than modelled concentrations.

  • no_model_error – Whether to suppress explicit model-error terms.

  • offset_args – Extra keyword arguments forwarded to the offset component.

  • power – Exponent or prior specification used in likelihood error scaling.

Returns:

Built PyMC model.

openghg_inversions.models.rhime.build_rhime_multisector_model_from_spec(inv_inputs: Dataset, model_spec: RhimeModelSpec) Model#

Build the shared-basis multi-sector RHIME model from a model spec.

Parameters:
  • inv_inputs – Canonical inversion-input dataset with H(region, nmeasure, source).

  • model_spec – Normalized RHIME model specification.

Returns:

Built PyMC model.

openghg_inversions.models.rhime.safe_pymc_name(value: str) str#

Return a stable PyMC-safe suffix for a user-facing sector/source name.

Parameters:

value – User-facing sector or source name.

Returns:

Lowercase snake-case suffix safe to use in PyMC variable names.