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:
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.models.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.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 contributionmu_<sector>. The totalmuis 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_sourceskeys when supplied, otherwise allinv_inputs.H.sourcevalues, where each source becomes one separately optimized sector.sector_sources – Optional mapping from sector label to OpenGHG
sourcevalue ininv_inputs.H.sector_variable_suffixes – Optional mapping from sector label to PyMC-safe suffix used in
x_<suffix>andmu_<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.