openairclim.core.write_output

Writes output: results netCDF file and diagnostics files.

openairclim.core.write_output.config_hash(config: dict, length: int = 10) → str[source]

Create deterministic short hash of a resolved config dict.

Parameters:
  • config (dict) – Configuration dictionary (including default values)

  • length (int, optional) – Hash length. Defaults to 10 (~10^6 unique runs)

Returns:

Deterministic short hash

Return type:

str

openairclim.core.write_output.fig_metadata(c_hash: str, v_oac: str, created: str) → dict[source]

Create PNG metadata for generated figures.

Parameters:
  • c_hash (str) – Config hash generated by config_hash()

  • v_oac (str) – OpenAirClim version

  • created (str) – Datetime of simulation

Returns:

Metadata to add to a generated figure.

Return type:

dict

openairclim.core.write_output.filter_parametric_output(variables: list[str]) → list[str][source]

Prevent non-CO2 emissions and concentrations from being written to output.

Only applies if the parametric module is enabled.

Parameters:

variables (list[str]) – List of strings, calculated variables, e.g. “RF_CO2”

Returns:

List of strings, filtered variables

Return type:

list[str]

openairclim.core.write_output.gen_sim_metadata(config: dict) → dict[source]

Generate simulation metadata.

Parameters:

config (dict) – Configuration dictionary

Returns:

Simulation metadata

Return type:

dict

openairclim.core.write_output.query_checksum_table(spec: str, resp: Dataset, inv: Dataset) → tuple[Dataset | None, int][source]

Look up in checksum table whether pre-calculated data exists.

For the particular spec/resp/inv combination.

Parameters:
Returns:

xarray Dataset with weight parameters, Number of rows in checksum table

Return type:

xarray.Dataset or None, int

openairclim.core.write_output.update_checksum_table(spec: str, resp: Dataset, inv: Dataset, cache_file: str) → DataFrame[source]

Add a row to the existing checksum table.

Includes hashes of resp and inv, and path to cache_file.

Parameters:
Returns:

Representation of the current checksum table

Return type:

pd.DataFrame

openairclim.core.write_output.update_output_dict(output_dict: dict, ac: str, result_type: str, val_arr_dict: dict) → None[source]

Update output_dict for a given aircraft with a new result type.

Parameters:
  • output_dict (dict) – The main output dictionary to update. Format: {ac: {var: numpy.ndarray}}

  • ac (str) – Aircraft identifier from config file

  • result_type (str) – Prefix for variable names, e.g. “RF”

  • val_arr_dict (dict) – Dictionary of {species: numpy.ndarray} results. Each array shold be 1D and represent a time series.

Returns:

Modifies output_dict in-place.

Return type:

None

openairclim.core.write_output.write_climate_metrics(config: dict, metrics_dict: dict, mode: Literal['w', 'a'] = 'w', metadata: dict | None = None) → Dataset[source]

Writes climate metrics to netCDF file.

Parameters:
  • config (dict) – Configuration from config file

  • metrics_dict (dict) – Dictionary of climate metrics, keys are metric types

  • mode (str, optional) – Can be “w” for write or “a” for append. Defaults to “w”

  • metadata (dict, optional) – Metadata to add to the output file

Returns:

xarray Dataset of climate metrics

Return type:

xr.Dataset

openairclim.core.write_output.write_concentrations(config: dict, resp_dict: dict, conc_dict: dict) → dict[source]

Output of concentration changes.

Converts dictionary of time series numpy arrays into dictionary of xarray Datasets, and writes to netCDF files, one per species.

Parameters:
  • config (dict) – Configuration from config file

  • resp_dict (dict) – Dictionary of response xarray Datasets, keys are species

  • conc_dict (dict) – Dictionary of time series numpy arrays (time, lat, plev), keys are species

Returns:

Dictionary of concentration changes (time, lat, plev), keys are species

Return type:

dict

openairclim.core.write_output.write_output_dict_to_netcdf(config: dict, output_dict: dict, mode: Literal['w', 'a'] = 'w', metadata: dict | None = None) → Dataset[source]

Convert nested output dictionary into xarray Dataset and write to netCDF file.

Parameters:
  • config (dict) – Configuration from config file

  • output_dict (dict) – Nested output dictionary. Levels are {ac: {var: numpy.ndarray}}, where ac is the aircraft identifier, var is a variable, e.g. “RF_CO2” and numpy.ndarray is of length time (as defined in config)

  • mode (str, optional) – Options: “a” (append) and “w” (write).

  • metadata (dict, optional) – Metadata to add to output file

Returns:

OpenAirClim results

Return type:

xr.Dataset