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: Any) dict[str, ndarray][source]
Applies attribution methodology using the function
func.Dispatches to the attribution function matching
methodforsub_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
funcwith respect to the input. Must have the same shape asfunc. 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
funcanddiff_func.
- Raises:
ValueError – If an invalid method is given.
- Returns:
funcvalue attributable tosub_dict- Return type:
- openairclim.core.attribution.differential_attribution(diff_func: AttributionFunc, sub_dict: dict[str, ndarray], full_dict: dict[str, ndarray], species: str, **kwargs: Any) dict[str, ndarray][source]
Calculates the
funcvalue attributable tosub_dict(differential).Uses a differential methodology for species
species. The dictfull_dict, representing all other sources (i.e. background plus other aircraft identifiers), must includesub_dict.- Parameters:
diff_func (AttributionFunc) – A callable that calculates the derivative of
funcwith respect to the input. Must have the same shape asfunc.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
funcanddiff_func.
- Returns:
funcvalue attributable tosub_dict- Return type:
- openairclim.core.attribution.marginal_attribution(diff_func: AttributionFunc, sub_dict: dict[str, ndarray], full_dict: dict[str, ndarray], species: str, **kwargs: Any) dict[str, ndarray][source]
Calculates the
funcvalue attributable tosub_dict(marginal).Uses a marginal methodology for species
species. The dictfull_dict, representing all other sources (i.e. background plus other aircraft identifiers), must includesub_dict.- Parameters:
diff_func (AttributionFunc) – A callable that calculates the derivative of
funcwith respect to the input. Must have the same shape asfunc.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
funcanddiff_func.
- Returns:
funcvalue attributable tosub_dict- Return type:
- openairclim.core.attribution.proportional_attribution(func: AttributionFunc, sub_dict: dict[str, ndarray], full_dict: dict[str, ndarray], species: str, **kwargs: Any) dict[str, ndarray][source]
Calculates the
funcvalue attributable tosub_dict(proportional).Uses a proportional methodology for species
species. The dictfull_dict, representing all other sources (i.e. background plus other aircraft identifiers), must includesub_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:
funcvalue attributable tosub_dict- Return type:
- openairclim.core.attribution.residual_attribution(func: AttributionFunc, sub_dict: dict[str, ndarray], full_dict: dict[str, ndarray], species: str, **kwargs: Any) dict[str, ndarray][source]
Calculates the
funcvalue attributable tosub_dict(residual).Uses a residual methodology for species
species. The dictfull_dict, representing all other sources (i.e. background plus other aircraft identifiers), must includesub_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:
funcvalue attributable tosub_dict- Return type: