openairclim.core.read_netcdf

Methods for reading netCDF input.

openairclim.core.read_netcdf.check_evolution_attributes(evolution: Dataset) → None[source]

Check the “fuel” variable’s units in a time evolution file, if present.

“fuel” may be declared as a mass (e.g. “Tg”) or a mass accumulated per year (e.g. “Tg yr-1”).

Parameters:

evolution (xarray.Dataset) – Loaded time evolution dataset.

Raises:

KeyError – if “fuel” is present but its units are missing or not mass-compatible.

openairclim.core.read_netcdf.check_spec_attributes(config: dict, inv_dict: dict) → None[source]

Check emission attributes in inventories for given species in config.

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

  • inv_dict (dict) – Dictionary of xarray Datasets, keys are years of input inventories

Raises:

KeyError – if incorrect units found

openairclim.core.read_netcdf.get_evolution_type(config: dict) → str | bool[source]

Get evolution type.

Parameters:

config (dict) – Configuration dictionary from config

Raises:

ValueError – if type attribute in evolution file is invalid

Returns:

evolution_type: norm or scaling or False

Return type:

str, bool

openairclim.core.read_netcdf.get_results(config: dict, ac: str = 'TOTAL') → tuple[dict, dict, dict, dict][source]

Get the simulation results from the output netCDF file.

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

  • ac (str, optional) – Aircraft identifier, defaults to TOTAL

Returns:

dictionaries of numpy arrays containing the simulation results, keys are species.

Return type:

dict

openairclim.core.read_netcdf.open_inventories(config: dict, base: bool = False) → dict[source]

Open inventories from config, check attribute sections and time constraints.

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

  • base (bool) – If True, loads base inventory, else input inventory

Raises:
  • IndexError – if no inv_year is within time_range, for evolution_type = “norm” or “scaling” or False

  • IndexError – if time_range is not within evolution_time, for evolution_type = “norm” or “scaling”

  • IndexError – if no inv_year is within evolution_time, for evolution_type = “norm” or “scaling”

  • IndexError – if time_range first and last year are not in inv_years, for evolution_type = “scaling”

Returns:

Dictionary of xarray Datasets, keys are years of input inventories

Return type:

dict

openairclim.core.read_netcdf.open_netcdf(netcdf: str | Path | Sequence[str | Path]) → dict[source]

Converts netCDF file or list of netCDF files to dictionary of xarray Datasets.

Parameters:

netcdf (str or list) – (List of) netCDF file names

Returns:

Dictionary of xarray.Datasets, keys are basenames of input netCDF

Return type:

dict

openairclim.core.read_netcdf.open_netcdf_from_config(config: dict, section: str, species: list[str], resp_type: str) → dict[source]

Open netcdf files and convert to xarray Datasets.

For a given section in config and given species.

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

  • section (str) – Section in config

  • species (list[str]) – List of considered species

  • resp_type (str) – Response type, e.g. “conc”, “rf”

Returns:

Dictionary of xarray Datasets, one Dataset for each species, keys are species names

Return type:

dict

openairclim.core.read_netcdf.split_inventory_by_aircraft(config: dict, inv_dict: dict, base: bool = False) → dict[source]

Split dictionary of emission inventories by aircraft identifiers.

Aircraft identifiers are defined in the config file.

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

  • inv_dict (dict) – Dictionary of emission inventory xarrays, keys are inventory years.

  • base (bool, optional) – Whether an input or base emission inventory is to be split. If True, "BASE_" is added before the aircraft identifiers. Defaults to False.

Returns:

Nested dictionary of emission inventories. Keys are aircraft identifier, followed by year.

Return type:

dict