openghg_inversions.postprocessing.make_paris_outputs#

class openghg_inversions.postprocessing.make_paris_outputs.ParisTemplateFiles(concentration: Path, concentration_version: str, flux: Path, flux_version: str)#

Bases: NamedTuple

CDL templates used for one PARIS output schema version.

concentration: Path#

Alias for field number 0

concentration_version: str#

Alias for field number 1

flux: Path#

Alias for field number 2

flux_version: str#

Alias for field number 3

openghg_inversions.postprocessing.make_paris_outputs.add_variable_attrs(ds: Dataset, attrs: dict[str, dict[str, Any]], units: float | None = None) Dataset#

Update data variables and coordinates of Dataset based on attributes dictionary.

If units provided, data variables with “units” attribute will be rescaled by units. This is to convert e.g. from 1e-9 mol/mol to mol/mol.

openghg_inversions.postprocessing.make_paris_outputs.convert_time_to_unix_epoch(x: Dataset, units: str = '1s') Dataset#

Convert time coordinate of xarray Dataset or DataArray to number of “units” since 1 Jan 1970 (the “UNIX epoch”).

openghg_inversions.postprocessing.make_paris_outputs.get_data_var_attrs(template_file: str | Path, species: str | None = None) dict[str, dict[str, Any]]#

Extract data variable attributes from template file.

openghg_inversions.postprocessing.make_paris_outputs.get_data_var_dtypes(template_file: str | Path) dict[str, str]#

Extract numeric variable dtypes from a CDL template file.

openghg_inversions.postprocessing.make_paris_outputs.infer_flux_frequency(flux: DataArray) str#

Attempt to infer flux frequency.

This does not work in all cases. If the flux has a “time_period” attribute, then that will be used. Otherwise, we try to infer the period by looking at the differences between timestamps. If only one timestamp is found, then a default value of “yearly” is returned.

Parameters:

flux – flux DataArray

Returns:

frequency string that can be parsed by pd.to_timedelta, or is “yearly” or “monthly”

Raises:

ValueError – if inferred frequency is not “yearly” or “monthly”, and cannot be parsed by pd.to_timedelta

openghg_inversions.postprocessing.make_paris_outputs.make_global_attrs(output_type: Literal['flux', 'conc'], author: str | None = None, species: str = 'inert', domain: str = 'EUROPE', apriori_description: str = 'EDGAR 8.0', history: str | None = None, comment: str | None = None) dict[str, str]#
openghg_inversions.postprocessing.make_paris_outputs.make_paris_outputs(inv_out: InversionOutput, country_file: str | Path | None = None, time_point: Literal['start', 'midpoint'] = 'midpoint', report_mode: bool = False, inversion_grid: bool = True, obs_avg_period: str = '4h', domain: str | None = None, template_version: Literal['legacy', 'latest'] = 'legacy', country_selections: Iterable[str] | None = ('AUT', 'BEL', 'CHE', 'CZE', 'DEU', 'DNK', 'ESP', 'FIN', 'FRA', 'GBR', 'HRV', 'HUN', 'IRL', 'ITA', 'LUX', 'NLD', 'NOR', 'POL', 'PRT', 'SVK', 'SVN', 'SWE')) tuple[Dataset, Dataset]#

Create matching PARIS flux and concentration products.

Parameters:
  • inv_out – Inversion output containing observations, model traces, retained basis functions, and prior fluxes.

  • country_file – Optional country-definition NetCDF file.

  • time_point – Flux timestamp convention.

  • report_mode – If true, report KDE modes instead of means as central estimates.

  • inversion_grid – If true, include reduced inversion-grid flux variables.

  • obs_avg_period – Averaging period recorded in concentration metadata.

  • domain – Optional domain override for concentration metadata.

  • template_version – PARIS template version to emit. "latest" selects concentration v04 and flux v03.

  • country_selections – Optional latest-template country names or codes. The default emits the canonical 22-country EUROPE v03 schema; pass None to include all countries from another domain file.

Returns:

A tuple containing the flux dataset followed by the concentration dataset.

Raises:

ValueError – If required inversion metadata is missing or template constraints are not satisfied.

openghg_inversions.postprocessing.make_paris_outputs.paris_concentration_outputs(inv_out: InversionOutput, report_mode: bool = False, obs_avg_period: str = '4h', template_version: Literal['legacy', 'latest'] = 'legacy') Dataset#

Create PARIS concentration outputs.

TODO: add offset

openghg_inversions.postprocessing.make_paris_outputs.paris_concentration_outputs_latest(inv_out: InversionOutput, report_mode: bool = False, obs_avg_period: str = '4h') Dataset#

Create single-sector PARIS concentration outputs for the latest CDL template.

openghg_inversions.postprocessing.make_paris_outputs.paris_flux_output(inv_out: InversionOutput, country_file: str | Path | None = None, time_point: Literal['start', 'midpoint'] = 'midpoint', report_mode: bool = False, inversion_grid: bool = True, flux_frequency: Literal['monthly', 'yearly'] | str = 'yearly', template_version: Literal['legacy', 'latest'] = 'legacy', country_selections: Iterable[str] | None = ('AUT', 'BEL', 'CHE', 'CZE', 'DEU', 'DNK', 'ESP', 'FIN', 'FRA', 'GBR', 'HRV', 'HUN', 'IRL', 'ITA', 'LUX', 'NLD', 'NOR', 'POL', 'PRT', 'SVK', 'SVN', 'SWE')) Dataset#

Create a flux product using a selected PARIS template version.

Parameters:
  • inv_out – Inversion output with retained basis functions and flux traces.

  • country_file – Optional country-definition NetCDF file.

  • time_point – Flux timestamp convention.

  • report_mode – If true, report KDE modes instead of means as central estimates.

  • inversion_grid – If true, include reduced inversion-grid variables.

  • flux_frequency – Frequency used to construct output flux intervals.

  • template_version – PARIS template version to emit. The default preserves the legacy output contract; "latest" selects flux v03.

  • country_selections – Optional country names or codes for the latest template. The default emits the canonical 22-country EUROPE v03 schema; pass None to include all countries from another domain file. The legacy template ignores this option.

Returns:

PARIS flux dataset using the selected template’s variable names, dimensions, dtypes, units, and attributes.

Raises:

ValueError – If required inversion metadata is missing or a latest-only time or frequency option is invalid.

openghg_inversions.postprocessing.make_paris_outputs.paris_flux_output_latest(inv_out: InversionOutput, country_file: str | Path | None = None, time_point: Literal['start', 'midpoint'] = 'midpoint', report_mode: bool = False, inversion_grid: bool = True, flux_frequency: Literal['monthly', 'yearly'] | str = 'yearly', country_selections: Iterable[str] | None = ('AUT', 'BEL', 'CHE', 'CZE', 'DEU', 'DNK', 'ESP', 'FIN', 'FRA', 'GBR', 'HRV', 'HUN', 'IRL', 'ITA', 'LUX', 'NLD', 'NOR', 'POL', 'PRT', 'SVK', 'SVN', 'SWE')) Dataset#

Create single- or multisector flux output using the latest PARIS template.

Multisector output contains total and per-sector spatial and country statistics. Sector fluxes are reconstructed with their own prior fluxes, while total flux is calculated by summing those reconstructed traces. Country covariance variables use the repeated country and sector dimensions required verbatim by the supplied CDL schema.

Parameters:
  • inv_out – Inversion output with retained basis functions and flux traces.

  • country_file – Optional country-definition NetCDF file. If omitted, the country helper resolves its configured default for the inversion domain.

  • time_point – Flux timestamp convention. The latest template supports only "midpoint" because it also reports interval bounds.

  • report_mode – If true, report KDE modes instead of means as central flux estimates.

  • inversion_grid – If true, include the optional reduced inversion-grid variables.

  • flux_frequency – Frequency used to construct output intervals. Supported values are "monthly" and "yearly".

  • country_selections – Optional country names or codes to include. The default emits the canonical 22-country EUROPE v03 product; pass None to include every country from another domain file.

Returns:

Latest-template PARIS flux dataset with template dtypes and attributes.

Raises:

ValueError – If midpoint times are not requested, required inversion or sector metadata is missing or invalid, the flux frequency is not supported, or no valid flux interval falls within the inversion.

openghg_inversions.postprocessing.make_paris_outputs.paris_template_files(template_version: Literal['legacy', 'latest']) ParisTemplateFiles#

Return CDL template paths for a PARIS output schema version.

openghg_inversions.postprocessing.make_paris_outputs.shift_measurement_time_to_midpoint(ds: Dataset, period: str = '4h') Dataset#

Adjust time coordinate of concentrations to represent half averaging “period”.