openairclim.core.attribution
Provides attribution functionality for non-linear species.
- class openairclim.core.attribution.AttributionFunc(*args, **kwargs)[source]
Bases:
ProtocolDefines type protocol for attribution function inputs.
- openairclim.core.attribution.apply_attribution(func: AttributionFunc, diff_func: AttributionFunc, method: str, species: str, sub_dict: dict[str, ndarray], full_dict: dict[str, ndarray], **kwargs) dict[str, ndarray][source]
Applies attribution methodology using the function func for sub_dict.
- Parameters:
func (AttributionFunc) – A callable that maps a dict of species arrays to another such dict. The first argument must be a dict[str, np.ndarray].
diff_func (AttributionFunc) – A callable that calculates the derivative of func with respect to the input. Must have the same shape as func. Can be None if no attribution method is used that requires a derivative.
method (str) – Attribution method. Choice of: “none”, “residual”, “marginal”, “proportional”, “differential”.
species (str) – Name of the species to consider (e.g. ‘CO2’).
sub_dict (dict[str, np.ndarray]) – Dict of species arrays representing a part of the full dict (e.g. one aircraft identifier).
full_dict (dict[str, np.ndarray]) – Dict of species arrays representing all sub-dicts. Must include `sub_dict`!
**kwargs – Additional keyword arguments to pass to func and diff_func.
- Raises:
ValueError – If an invalid method is given.
- Returns:
func value attributable to sub_dict
- Return type:
- openairclim.core.attribution.differential_attribution(diff_func: AttributionFunc, sub_dict: dict[str, ndarray], full_dict: dict[str, ndarray], species: str, **kwargs) dict[str, ndarray][source]
Calculates the func value for species species attributable to sub_dict using a differential methodology. The dict full_dict, representing all other sources (i.e. background plus other aircraft identifiers) must include sub_dict.
- Parameters:
diff_func (AttributionFunc) – A callable that calculates the derivative of func with respect to the input. Must have the same shape as func.
sub_dict (dict[str, np.ndarray]) – Dict of species arrays representing a part of the full dict (e.g. one aircraft identifier).
full_dict (dict[str, np.ndarray]) – Dict of species arrays representing all sub-dicts. Must include `sub_dict`!
species (str) – Name of the species to consider (e.g. ‘CO2’).
**kwargs – Additional keyword arguments to pass to func and diff_func.
- Returns:
func value attributable to sub_dict
- Return type:
- openairclim.core.attribution.marginal_attribution(diff_func: AttributionFunc, sub_dict: dict[str, ndarray], full_dict: dict[str, ndarray], species: str, **kwargs) dict[str, ndarray][source]
Calculates the func value for species species attributable to sub_dict using a marginal methodology. The dict full_dict, representing all other sources (i.e. background plus other aircraft identifiers) must include sub_dict.
- Parameters:
diff_func (AttributionFunc) – A callable that calculates the derivative of func with respect to the input. Must have the same shape as func.
sub_dict (dict[str, np.ndarray]) – Dict of species arrays representing a part of the full dict (e.g. one aircraft identifier).
full_dict (dict[str, np.ndarray]) – Dict of species arrays representing all sub-dicts. Must include `sub_dict`!
species (str) – Name of the species to consider (e.g. ‘CO2’).
**kwargs – Additional keyword arguments to pass to func and diff_func.
- Returns:
func value attributable to sub_dict
- Return type:
- openairclim.core.attribution.proportional_attribution(func: AttributionFunc, sub_dict: dict[str, ndarray], full_dict: dict[str, ndarray], species: str, **kwargs) dict[str, ndarray][source]
Calculates the func value for species species attributable to sub_dict using a proportional methodology. The dict full_dict, representing all other sources (i.e. background plus other aircraft identifiers) must include sub_dict.
- Parameters:
func (AttributionFunc) – A callable that maps a dict of species arrays to another such dict. The first argument must be a dict[str, np.ndarray].
sub_dict (dict[str, np.ndarray]) – Dict of species arrays representing a part of the full dict (e.g. one aircraft identifier).
full_dict (dict[str, np.ndarray]) – Dict of species arrays representing all sub-dicts. Must include `sub_dict`!
species (str) – Name of the species to consider (e.g. ‘CO2’).
**kwargs – Additional keyword arguments to pass to func.
- Returns:
func value attributable to sub_dict
- Return type:
- openairclim.core.attribution.residual_attribution(func: AttributionFunc, sub_dict: dict[str, ndarray], full_dict: dict[str, ndarray], species: str, **kwargs) dict[str, ndarray][source]
Calculates the func value for species species attributable to sub_dict using a residual methodology. The dict full_dict, representing all other sources (i.e. background plus other aircraft identifiers) must include sub_dict.
- Parameters:
func (AttributionFunc) – A callable that maps a dict of species arrays to another such dict. The first argument must be a dict[str, np.ndarray].
sub_dict (dict[str, np.ndarray]) – Dict of species arrays representing a part of the full dict (e.g. one aircraft identifier).
full_dict (dict[str, np.ndarray]) – Dict of species arrays representing all sub-dicts. Must include `sub_dict`!
species (str) – Name of the species to consider (e.g. ‘CO2’).
**kwargs – Additional keyword arguments to pass to func.
- Returns:
func value attributable to sub_dict
- Return type: