openghg_inversions.postprocessing.make_outputs#

openghg_inversions.postprocessing.make_outputs.basic_output(inv_out: InversionOutput, country_file: str | Path | None = None, country_regions: str | Path | dict[str, list[str]] | Literal['paris'] | None = None, stats: list[str] | None = None, stats_args: dict | None = None) Dataset#

Create basic output with concentrations, flux totals, and country totals.

The dataset returned also contains the basis functions, and other data used to create the model, like “H matrices” and the flux used.

Parameters:
  • inv_out – InversionOutput to process

  • country_file – path to country file

  • country_regions – optional country regions to use. If “paris” is passed,

  • used. (then the PARIS regions will be)

  • stats – list of stats to use; if None, defaults to [“mean”,

  • "quantile"].

  • stats_args – optional arguments to pass to the stats functions.

Returns:

xr.Dataset containing statistics for concentrations, fluxes, and country totals.

openghg_inversions.postprocessing.make_outputs.convert_suffixes_to_dim(ds: Dataset, suffixes: list[str], new_dim: str) Dataset#
openghg_inversions.postprocessing.make_outputs.flatten_post_prior(ds: Dataset) Dataset#

Add a dimension when that is either “post” or “prior”.

This reduces the number of data variables in the outputs.

Note: do this before flattening suffixes.

openghg_inversions.postprocessing.make_outputs.make_concentration_outputs(inv_out: InversionOutput, stats: list[str] | None = None, stats_args: dict | None = None, combine_bc_and_offset: bool = False) Dataset#

Return dataset of stats for concentrations.

Parameters:
  • inv_out – InversionOutput containing MCMC traces.

  • stats – List of stats to use. If None, the default for calculate_stats is used, which is “mean” and “quantiles”. See the postprocessing.stats submodule for more options.

  • stats_args – Dict of arguments to be passed to stats functions. If a key in this dict is the name of an argument for a stats function, then the value for this key will be passed to the stats function. To pass an option to a specific stats function, write the key in the form “<stat function name>__<key>”, with a double underscore. For instance, stats_args = {“mode_kde__chunk_size”: 20} would pass the argument chunk_size = 20 to the stat function mode_kde, and no others.

  • combine_bc_and_offset – If True, the offset is added to the baseline (before stats are calculated).

Returns:

xr.Dataset with computed flux stats.

openghg_inversions.postprocessing.make_outputs.make_country_outputs(inv_out: InversionOutput, country_file: str | Path | None = None, country_regions: str | Path | dict[str, list[str]] | Literal['paris'] | None = None, stats: list[str] | None = None, stats_args: dict | None = None, country_code: Literal['alpha2', 'alpha3'] | None = 'alpha3') Dataset#

Calculate country emission stats.

Parameters:
  • inv_out – InversionOutput containing MCMC traces.

  • country_file – Path to country definition file. If None, the default country file location and the domain of the InversionOutput will be used to try to find a suitable country file.

  • country_regions – Dict mapping country region names (e.g. “BENELUX”) to a list of (country codes) of the countries comprising that regions (e.g. [“BEL”, “NLD”, “LUX”]).

  • stats – List of stats to use. If None, the default for calculate_stats is used, which is “mean” and “quantiles”. See the postprocessing.stats submodule for more options.

  • stats_args – Dict of arguments to be passed to stats functions. If a key in this dict is the name of an argument for a stats function, then the value for this key will be passed to the stats function. To pass an option to a specific stats function, write the key in the form “<stat function name>__<key>”, with a double underscore. For instance, stats_args = {“mode_kde__chunk_size”: 20} would pass the argument chunk_size = 20 to the stat function mode_kde, and no others.

  • country_code – If set to “alpha2” or “alpha3”, country names will be converted to two or three digit country codes, respectively. Country region definitions should use the same type of code as specified here.

Returns:

xr.Dataset containing statistics for the specified countries and regions.

openghg_inversions.postprocessing.make_outputs.make_flux_outputs(inv_out: InversionOutput, stats: list[str] | None = None, stats_args: dict | None = None, include_scale_factors: bool = True, report_flux_on_inversion_grid: bool = True) Dataset#

Return dataset of stats for fluxes and scaling factors.

Parameters:
  • inv_out – InversionOutput containing MCMC traces.

  • stats – List of stats to use. If None, the default for calculate_stats is used, which is “mean” and “quantiles”. See the postprocessing.stats submodule for more options.

  • stats_args – Dict of arguments to be passed to stats functions. If a key in this dict is the name of an argument for a stats function, then the value for this key will be passed to the stats function. To pass an option to a specific stats function, write the key in the form “<stat function name>__<key>”, with a double underscore. For instance, stats_args = {“mode_kde__chunk_size”: 20} would pass the argument chunk_size = 20 to the stat function mode_kde, and no others.

  • include_scale_factors – If True, report stats for scale factors, in addition to stats for fluxes (which are calculated by transforming the scale factor stats to the lat/lon grid using the prior flux).

  • report_flux_on_inversion_grid – If True, report fluxes by basis function, without incorporating the prior flux. Note: we do not actually optimise for this quantity, since the prior flux is used in the forward model.

Returns:

xr.Dataset with computed flux stats.

openghg_inversions.postprocessing.make_outputs.sort_data_vars(ds: Dataset) Dataset#

Sort data variables by variable name, then suffix.