openairclim.interpolate_time
Interpolation methods in the time domain
- openairclim.interpolate_time.adjust_inventories(config: dict, inv_dict: dict) dict[source]
 Determine evolution_type: norm, scaling or no evolution, and adjust inventories depending on type, data variables to be adjusted: fuel, species emissions and distance
- Parameters:
 - Raises:
 ValueError – if no valid evolution_type in evolution file
- Returns:
 - normalized/scaled/unmodified dictionary of xarray Datasets,
 keys are years of input inventories
- Return type:
 
- openairclim.interpolate_time.apply_evolution(config: dict, val_dict: dict, inv_dict: dict, inventories_adjusted: bool = False) tuple[ndarray, dict][source]
 Determine evolution_type, apply normalization, scaling or no evolution
- Parameters:
 config (dict) – Configuration dictionary from config
val_dict (dict) – Dictionary with time series numpy arrays, keys are species
inv_dict (dict) – Dictionary of xarray Datasets, keys are years of input inventories
inventories_adjusted (bool) – True if inventories have been adjusted beforehand through adjust_inventories(config, inv_dict), defaults to False
- Raises:
 ValueError – if no valid evolution_type in evolution file
- Returns:
 - time_range and normalized/scaled/unmodified dictionary,
 np.ndarray, {spec: np.ndarray}
- Return type:
 array, dict
- openairclim.interpolate_time.apply_no_evolution(config, val_dict, inv_dict)[source]
 Apply interpolation only on time series data over time_range
- Parameters:
 - Returns:
 time_range and dictionary of time series data
- Return type:
 array, dict
- openairclim.interpolate_time.apply_norm(config, val_dict, inv_dict)[source]
 Apply normalization on time series, get data from evolution file and inventories, interpolate time series and evolution data over time_range, calculate normalization factors and apply (multiplication)
- openairclim.interpolate_time.apply_scaling(config: dict, val_dict: dict, inv_dict: dict, inventories_adjusted: bool) tuple[ndarray, dict][source]
 Apply scaling on dictionary of time series, scaling factors are from evolution file, time series and scaling factors are interpolated on time_range before multiplication TODO: implement scaling for individual species
- Parameters:
 config (dict) – Configuration dictionary from config
val_dict (dict) – Dictionary with time series numpy arrays, keys are species
inv_dict (dict) – Dictionary of xarray Datasets, keys are years of input inventories
inventories_adjusted (bool) – True if inventories have been adjusted beforehand through adjust_inventories(config, inv_dict), False otherwise
- Returns:
 time_range and scaled dictionary
- Return type:
 array, dict
- openairclim.interpolate_time.calc_inv_quantities(config, inv_dict)[source]
 Calculate inventory quantities: fuel sums, emission sums and emission indices, Sums and emission indices are only calculated from species included in config
- Parameters:
 - Returns:
 - Array of inventory years,
 Dictionary of arrays of summed inventory emissions, keys are species Dictionary of arrays of fuel sums and inventory emission indices, keys are data variable names of evolution file
- Return type:
 
- openairclim.interpolate_time.calc_norm(evo_dict, ei_inv_dict)[source]
 Calculate normalization factors, either by fuel use only, or combined with evolution of emission index of species
- Parameters:
 - Returns:
 - Dictionary of normalization factors, keys are “fuel” and species
 - {“fuel”: np.ndarray (norm_fuel = evo_fuel / inv_fuel),
 ”CO2”: np.ndarray (norm_fuel * evo_EI / inv_EI), ..}
- Return type:
 
- openairclim.interpolate_time.filter_dict_to_evo_keys(config: dict, inp_dict: dict) dict[source]
 Filter input dictionary to items matching with keys from time evolution file
This function loads the time evolution file as an xarray dataset, and iterates over its keys. An item from the input dictionary is transferred to the output dictionary if the corresponding input key matches with a key from the time evolution.
- Parameters:
 - Returns:
 Dictionary with filtered items
- Return type:
 
- Raises:│
 KeyError: If no matches are found between both sets of keys.
- openairclim.interpolate_time.filter_to_inv_years(inv_years, time_range: ndarray, interp_dict: dict) dict[source]
 Filters dictionary of interpolated arrays to items for inventory years only
- Parameters:
 inv_years (np.ndarray) – Array of inventory years
time_range (np.ndarray) – time_range from config
interp_dict (dict) – Dictionary of arrays, interpolated over time_range, keys are e.g. evolution keys or species names
- Returns:
 Dictionary of arrays, filtered to inventory years, same keys as interp_dict
- Return type:
 
- openairclim.interpolate_time.interp_evolution(config)[source]
 Interpolate values in evolution file over time_range
- openairclim.interpolate_time.interp_linear(config: dict, years: ndarray, val_dict: dict, bounds_error=True, fill_value=nan) tuple[ndarray, dict][source]
 Interpolate linearly values from discrete years to time_range set in config
- Parameters:
 config (dict) – Configuration dictionary from config
years (array) – Numpy array with discrete years
val_dict (dict) – Dictionary with time series numpy arrays, keys are species
bounds_error (bool, optional) – See documentation of scipy.interpolate.interp1d
fill_value (float or None, optional) – See documentation of scipy.interpolate.RegularGridInterpolator
- Raises:
 IndexError – if too few discrete years or inappropriate options set
- Returns:
 - Time range over which interpolation takes place,
 and interpolated values, keys are the same as in val_dict
- Return type:
 array, dict
- openairclim.interpolate_time.interpolate(config: dict, years: ndarray, val_dict: dict) tuple[ndarray, dict][source]
 Interpolate values from discrete years to time_range set in config
- Parameters:
 - Returns:
 - Time range over which interpolation takes place,
 and interpolated values, keys are the same as in val_dict
- Return type:
 array, dict
- openairclim.interpolate_time.norm_inv(inv_dict: dict, norm_dict: dict) dict[source]
 Multiply data variables in emission inventories by normalization factors, depending on available keys in norm_dict, data variables are multiplied by norm_fuel or (norm_fuel * norm_EI), with norm_EI = evo_EI / inv_EI
- openairclim.interpolate_time.norm_inventories(config: dict, inv_dict: dict) dict[source]
 Applies normalization to a dictionary of emission inventories. This function first interpolates evolution data variables to time_range from config. It then gets inventory years, calculates inventory sums and emission indices (dictionaries with spec keys and arrays over inventory years). The emission indices dictionary is filtered to those species specified in time evolution. The arrays in evolution data are filtered to inventory years only. Next, the multipliers used for normalization are calculated. Finally, the normalization is performed by multiplying the inventory data variables with the normalization factors.
- openairclim.interpolate_time.scale_inv(inv_dict: dict, scale_dict: dict) dict[source]
 Multiply data variables in emission inventories by scaling factors
- openairclim.interpolate_time.scale_inventories(config: dict, inv_dict: dict) dict[source]
 Applies scaling to a dictionary of emission inventories. This function first interpolates evolution data variables to time_range from config. It then gets inventory years. The array in evolution data is filtered to inventory years only. Finally, the scaling is performed by multiplying the inventory data variables with the scaling factors in the filtered evolution data.