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
configdict.
- 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:
- 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.
- openairclim.core.write_output.gen_sim_metadata(config: dict) dict[source]
Generate simulation metadata.
- 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:
spec (str) – Name of the species
resp (xarray.Dataset) – Response xarray Dataset
inv (xarray.Dataset) – Emission inventory xarray Dataset
- 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:
spec (str) – Name of the species
resp (xarray.Dataset) – Response xarray
inv (xarray.Dataset) – Emission inventory
cache_file (str) – Path to cache file
- 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:
- 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:
- Returns:
Dictionary of concentration changes (time, lat, plev), keys are species
- Return type:
- 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}}, whereacis the aircraft identifier,varis a variable, e.g. “RF_CO2” andnumpy.ndarrayis 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