openghg_inversions.experimental.ramsden2022#
Historical Ramsden et al. (2022) methane/ethane inversion.
This experimental module preserves the paper’s shared-state two-gas model
without porting the obsolete data loading, custom Metropolis-Hastings sampler,
or postprocessing from origin/adding_multi_gas_model. Pass independently
prepared, canonical RHIME datasets to build_ramsden_model() to build a
PyMC graph or run_ramsden_from_prepared_inputs() to build and sample it.
The gases may use different observation axes, but coupled sector state
coordinates must match exactly.
Ratios may either be direct molar ratios applied to a ratio-free tracer design or multipliers applied to a design that already includes a declared reference ratio. Values must already share each channel’s declared observation units; the module validates supported unit declarations but does not convert values.
- class openghg_inversions.experimental.ramsden2022.RamsdenChannelSpec(species: str, observation_units: str, sigma_prior: dict[str, Any], sigma_per_site: bool = True, sigma_frequency: str | None = None, sigma_frequency_anchor: str | datetime | datetime64 | Timestamp | None = None, use_bc: bool = False, bc_prior: dict[str, Any] | None = None)#
Bases:
objectLikelihood and boundary settings for one observed gas.
- Parameters:
species – Gas name used to namespace model variables.
observation_units – Units shared by observations, measurement errors, minimum errors, forward-model outputs, and the model-error prior. Supported dataset unit attributes are checked by mol/mol scale; values are not converted.
sigma_prior – PyMC prior mapping accepted by
parse_prior()for absolute model error. The prior is expanded by site and period, not multiplied by the modelled enhancement.sigma_per_site – Whether model error is independent by observation site.
sigma_frequency – Optional pandas-compatible frequency for model-error periods.
sigma_frequency_anchor – Optional anchor for fixed-duration periods.
use_bc – Whether this channel has an independent boundary component.
bc_prior – Prior mapping for the state that scales this channel’s
H_bcdesign.
- sigma_frequency_anchor: str | datetime | datetime64 | Timestamp | None = None#
- class openghg_inversions.experimental.ramsden2022.RamsdenModelSpec(primary: RamsdenChannelSpec, tracer: RamsdenChannelSpec, sectors: tuple[RamsdenSectorSpec, ...])#
Bases:
objectComplete specification for the historical two-gas model.
- Parameters:
primary – Primary-gas likelihood settings.
tracer – Tracer-gas likelihood settings.
sectors – Ordered primary sectors. At least one sector must also emit the tracer. Sanitized channel names must be distinct, and sanitized sector names must be non-empty and unique.
- primary: RamsdenChannelSpec#
- sectors: tuple[RamsdenSectorSpec, ...]#
- tracer: RamsdenChannelSpec#
- class openghg_inversions.experimental.ramsden2022.RamsdenPreparedInputs(primary: Dataset, tracer: Dataset, tracer_design_reference_ratios: Mapping[str, float | None], primary_basis_functions: FluxWeightedBasis | None = None, tracer_basis_functions: FluxWeightedBasis | None = None)#
Bases:
objectCanonical primary-gas and tracer inputs for one joint inversion.
Each dataset requires
H,mf,mf_error,min_error, andsite_indicatoronnmeasure;H_bcis required when that channel’s boundary component is enabled. Observation axes may differ. Coupled sector designs must have exactly matching labelled state coordinates and, for positional numeric labels, retained basis objects.- Parameters:
primary – Canonical RHIME-style dataset for the primary gas.
tracer – Canonical RHIME-style dataset for the tracer gas. Its
Hmatrix must use the same labelled state layout asprimary.H.tracer_design_reference_ratios – Reference ratio already included in each tracer
Hsource, keyed by tracer source label. UseNonefor a ratio-free design. These declarations are checked against each sector specification to prevent applying a ratio twice or omitting it.primary_basis_functions – Retained basis used to construct
primary.H. Required together withtracer_basis_functionswhen state labels are positional numbers.tracer_basis_functions – Retained basis used to construct
tracer.H. Its source-specific spatial map must equal the primary map for every coupled sector.
- primary_basis_functions: FluxWeightedBasis | None = None#
- tracer_basis_functions: FluxWeightedBasis | None = None#
- class openghg_inversions.experimental.ramsden2022.RamsdenResult(prepared_inputs: RamsdenPreparedInputs, model_spec: RamsdenModelSpec, model: Model, idata: InferenceData, sampler: RhimeSampler)#
Bases:
objectResult returned by
run_ramsden_from_prepared_inputs().- Parameters:
prepared_inputs – Labelled inputs consumed by the model.
model_spec – Historical model specification.
model – Built PyMC model.
idata – Joint inference data preserving shared-state/ratio covariance and the two namespaced likelihood and predictive variables.
sampler – Modern RHIME sampler used for the run.
- idata: InferenceData#
- model_spec: RamsdenModelSpec#
- prepared_inputs: RamsdenPreparedInputs#
- sampler: RhimeSampler#
- class openghg_inversions.experimental.ramsden2022.RamsdenSectorSpec(name: str, primary_flux_source: str, x_prior: dict[str, Any], tracer_flux_source: str | None = None, ratio_prior: dict[str, Any] | None = None, fixed_ratio: float | None = None, ratio_resolution: Literal['scalar', 'spatial'] = 'spatial', reference_ratio: float | None = None)#
Bases:
objectShared primary-gas state and optional tracer coupling for one sector.
- Parameters:
name – Semantic sector name.
primary_flux_source – Source-provenance label selected from
primary.H.x_prior – Prior mapping for the primary-gas scaling state. It must broadcast to the selected state dimension.
tracer_flux_source – Source-provenance label selected from
tracer.H.Nonemeans this sector contributes no tracer, as for the non-fossil methane sector in Ramsden et al. (2022).ratio_prior – Prior for a sampled direct emission ratio or historical ratio multiplier. Exactly one of
ratio_priorandfixed_ratiois required for a tracer-emitting sector. The distribution must have non-negative support.fixed_ratio – Fixed direct emission ratio or historical multiplier.
ratio_resolution –
"spatial"creates one sampled/fixed ratio value per state element, so its prior must broadcast to that state;"scalar"shares one value across the sector.reference_ratio –
Noneselects the paper’s direct-ratio contract:tracer.Hmust be ratio-free and the ratio parameter is applied directly. A positive value selects historical compatibility:tracer.Hmust already include this reference ratio, the sampled parameter is a dimensionless multiplier, andemission_ratio = reference_ratio * ratio_multiplieris exposed for interpretation. Direct and reference ratios are dimensionless molar ratios (moles tracer per mole primary).
- openghg_inversions.experimental.ramsden2022.build_ramsden_model(prepared_inputs: RamsdenPreparedInputs, model_spec: RamsdenModelSpec) Model#
Build the historical Ramsden methane/ethane model with modern PyMC.
- Parameters:
prepared_inputs – Two canonical gas datasets. Each requires
H,mf,mf_error,min_error, andsite_indicatoronnmeasure;H_bcis required for enabled boundary states. Observation coordinates may differ, but coupled sector state coordinates must match exactly.model_spec – Shared-state, ratio, likelihood, unit, and boundary metadata. Direct ratios require ratio-free tracer sensitivities; reference-ratio mode requires tracer sensitivities that already include the declared reference ratio.
- Returns:
Built PyMC model ready for
RhimeSampler.- Raises:
ValueError – If model metadata, required input variables, source labels, or shared state coordinates are invalid.
Notes
This function builds a PyMC graph only. It performs no data retrieval, sampling, unit conversion, or postprocessing. Observation, error, sigma-prior, and forward-model values must already use each channel’s declared
observation_units.
- openghg_inversions.experimental.ramsden2022.run_ramsden_from_prepared_inputs(*, prepared_inputs: RamsdenPreparedInputs, model_spec: RamsdenModelSpec, sampler: RhimeSampler | None = None) RamsdenResult#
Build and sample a historical two-gas model from canonical inputs.
- Parameters:
prepared_inputs – Canonical primary and tracer datasets.
model_spec – Historical model specification.
sampler – Modern RHIME sampling configuration controlling seeds, chains, draws, and predictive output. When omitted, the standard sampler is used with both namespaced gas observations included in posterior predictive sampling.
- Returns:
Joint result containing the built model and labelled inference data.
- Raises:
ValueError – If model metadata or prepared inputs are invalid.
Notes
This function samples the model and may run multiple chains. It does not retrieve data, convert units, or write postprocessed products. Sampling exceptions raised by
RhimeSamplerare propagated.