diff --git a/icclim/ecad/ecad_indices.py b/icclim/ecad/ecad_indices.py index 75ed0640..416f094d 100644 --- a/icclim/ecad/ecad_indices.py +++ b/icclim/ecad/ecad_indices.py @@ -33,7 +33,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: TG = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.Average, + indicator=GenericIndicatorRegistry.Average, output_unit="degree_Celsius", definition="Mean of daily mean temperature", source=ECAD_ATBD, @@ -43,7 +43,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) TN = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.Average, + indicator=GenericIndicatorRegistry.Average, output_unit="degree_Celsius", definition="Mean of daily minimum temperature", source=ECAD_ATBD, @@ -53,7 +53,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) TX = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.Average, + indicator=GenericIndicatorRegistry.Average, output_unit="degree_Celsius", definition="Mean of daily maximum temperature", source=ECAD_ATBD, @@ -63,7 +63,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) DTR = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.MeanOfDifference, + indicator=GenericIndicatorRegistry.MeanOfDifference, output_unit="degree_Celsius", definition="Mean Diurnal Temperature Range", source=ECAD_ATBD, @@ -76,7 +76,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) ETR = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.DifferenceOfExtremes, + indicator=GenericIndicatorRegistry.DifferenceOfExtremes, output_unit="degree_Celsius", definition="Intra-period extreme temperature range", source=ECAD_ATBD, @@ -89,7 +89,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) VDTR = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.MeanOfAbsoluteOneTimeStepDifference, + indicator=GenericIndicatorRegistry.MeanOfAbsoluteOneTimeStepDifference, output_unit="degree_Celsius", definition="Mean day-to-day variation in Diurnal Temperature Range", source=ECAD_ATBD, @@ -103,7 +103,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: # Heat SU = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, output_unit="day", definition="Number of Summer Days (Tmax > 25C)", source=ECAD_ATBD, @@ -115,7 +115,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) TR = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, output_unit="day", definition="Number of Tropical Nights (Tmin > 20C)", source=ECAD_ATBD, @@ -127,7 +127,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) WSDI = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.SumOfSpellLengths, + indicator=GenericIndicatorRegistry.SumOfSpellLengths, output_unit="day", definition="Warm-spell duration index (days)", source=ECAD_ATBD, @@ -141,7 +141,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) TG90P = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, output_unit="day", definition="Days when Tmean > 90th percentile", threshold="> 90 doy_per", @@ -154,7 +154,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) TN90P = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, output_unit="day", definition="Days when Tmin > 90th percentile", threshold="> 90 doy_per", @@ -167,7 +167,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) TX90P = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, threshold="> 90 doy_per", output_unit="day", definition="Days when Tmax > 90th daily percentile", @@ -180,7 +180,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) TXX = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.Maximum, + indicator=GenericIndicatorRegistry.Maximum, output_unit="degree_Celsius", definition="Maximum daily maximum temperature", source=ECAD_ATBD, @@ -190,7 +190,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) TNX = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.Minimum, + indicator=GenericIndicatorRegistry.Minimum, output_unit="degree_Celsius", definition="Maximum daily minimum temperature", source=ECAD_ATBD, @@ -200,7 +200,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) CSU = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.MaxConsecutiveOccurrence, + indicator=GenericIndicatorRegistry.MaxConsecutiveOccurrence, threshold="> 25 degree_Celsius", output_unit="day", definition="Maximum number of consecutive summer days (Tmax >25 C)", @@ -213,7 +213,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: # Cold GD4 = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.Excess, + indicator=GenericIndicatorRegistry.Excess, threshold="4 degree_Celsius", output_unit="degree_Celsius day", definition="Growing degree days (sum of Tmean > 4 C)", @@ -225,7 +225,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) FD = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, threshold="< 0 degree_Celsius", output_unit="day", definition="Number of Frost Days (Tmin < 0C)", @@ -237,7 +237,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) CFD = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.MaxConsecutiveOccurrence, + indicator=GenericIndicatorRegistry.MaxConsecutiveOccurrence, threshold="< 0 degree_Celsius", output_unit="day", definition="Maximum number of consecutive frost days (Tmin < 0 C)", @@ -249,7 +249,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) HD17 = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.Deficit, + indicator=GenericIndicatorRegistry.Deficit, threshold="17 degree_Celsius", output_unit="degree_Celsius day", definition="Heating degree days (sum of Tmean < 17 C)", @@ -261,7 +261,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) ID = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, threshold="< 0 degree_Celsius", output_unit="day", definition="Number of sharp Ice Days (Tmax < 0C)", @@ -273,7 +273,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) TG10P = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, threshold="< 10 doy_per", output_unit="day", definition="Days when Tmean < 10th percentile", @@ -286,7 +286,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) TN10P = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, threshold="< 10 doy_per", output_unit="day", definition="Days when Tmin < 10th percentile", @@ -299,7 +299,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) TX10P = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, threshold="< 10 doy_per", output_unit="day", definition="Days when Tmax < 10th percentile", @@ -312,7 +312,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) TXN = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.Minimum, + indicator=GenericIndicatorRegistry.Minimum, output_unit="degree_Celsius", definition="Minimum daily maximum temperature", source=ECAD_ATBD, @@ -322,7 +322,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) TNN = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.Minimum, + indicator=GenericIndicatorRegistry.Minimum, output_unit="degree_Celsius", definition="Minimum daily minimum temperature", source=ECAD_ATBD, @@ -332,7 +332,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) CSDI = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.SumOfSpellLengths, + indicator=GenericIndicatorRegistry.SumOfSpellLengths, threshold="< 10 doy_per", output_unit="day", definition="Cold-spell duration index (days)", @@ -347,7 +347,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: # Drought CDD = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.MaxConsecutiveOccurrence, + indicator=GenericIndicatorRegistry.MaxConsecutiveOccurrence, threshold="< 1 mm/day", output_unit="day", definition="Maximum consecutive dry days (Precip < 1mm)", @@ -359,7 +359,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: # Rain PRCPTOT = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.Sum, + indicator=GenericIndicatorRegistry.Sum, threshold=">= 1 mm/day", output_unit="mm", definition="Total precipitation during Wet Days", @@ -370,7 +370,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) RR1 = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, threshold=">= 1 mm/day", output_unit="day", definition="Number of Wet Days (precip >= 1 mm)", @@ -381,7 +381,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) SDII = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.Average, + indicator=GenericIndicatorRegistry.Average, threshold=">= 1 mm/day", output_unit="mm/day", definition="Average precipitation during Wet Days (SDII)", @@ -392,7 +392,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) CWD = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.MaxConsecutiveOccurrence, + indicator=GenericIndicatorRegistry.MaxConsecutiveOccurrence, threshold=">= 1 mm/day", output_unit="day", definition="Maximum consecutive wet days (Precip >= 1mm)", @@ -403,7 +403,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) RR = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.Sum, + indicator=GenericIndicatorRegistry.Sum, output_unit="mm", definition="Precipitation sum (mm)", source=ECAD_ATBD, @@ -413,7 +413,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) R10MM = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, threshold=">= 10 mm/day", output_unit="day", definition="Number of heavy precipitation days (Precip >=10mm)", @@ -424,7 +424,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) R20MM = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, threshold=">= 20 mm/day", output_unit="day", definition="Number of very heavy precipitation days (Precip >= 20mm)", @@ -435,7 +435,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) RX1DAY = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.Maximum, + indicator=GenericIndicatorRegistry.Maximum, output_unit="mm/day", definition="maximum 1-day total precipitation", # from xclim source=ECAD_ATBD, @@ -445,7 +445,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) RX5DAY = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.MaxOfRollingSum, + indicator=GenericIndicatorRegistry.MaxOfRollingSum, output_unit="mm", definition="maximum 5-day total precipitation", # from xclim source=ECAD_ATBD, @@ -457,7 +457,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) R75P = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, threshold=build_threshold("> 75 period_per", threshold_min_value="1 mm/day"), output_unit="day", definition="Days with RR > 75th percentile of daily amounts (moderate wet days)" @@ -470,7 +470,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) R75PTOT = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.FractionOfTotal, + indicator=GenericIndicatorRegistry.FractionOfTotal, threshold=build_threshold("> 75 period_per", threshold_min_value="1 mm/day"), output_unit="%", definition="Precipitation fraction due to moderate wet days" @@ -483,7 +483,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) R95P = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, threshold=build_threshold("> 95 period_per", threshold_min_value="1 mm/day"), output_unit="day", definition="Days with RR > 95th percentile of daily amounts (very wet days)" @@ -496,7 +496,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) R95PTOT = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.FractionOfTotal, + indicator=GenericIndicatorRegistry.FractionOfTotal, threshold=build_threshold("> 95 period_per", threshold_min_value="1 mm/day"), output_unit="%", definition="Precipitation fraction due to very wet days (> 95th percentile)", @@ -508,7 +508,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) R99P = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, threshold=build_threshold("> 99 period_per", threshold_min_value="1 mm/day"), output_unit="day", definition="Days with RR > 99th percentile of daily amounts" @@ -521,7 +521,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) R99PTOT = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.FractionOfTotal, + indicator=GenericIndicatorRegistry.FractionOfTotal, threshold=build_threshold("> 99 period_per", threshold_min_value="1 mm/day"), output_unit="%", definition="Precipitation fraction due to extremely wet days" @@ -535,7 +535,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: # Snow SD = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.Average, + indicator=GenericIndicatorRegistry.Average, output_unit="cm", definition="Mean of daily snow depth", source=ECAD_ATBD, @@ -545,7 +545,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) SD1 = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, threshold=">= 1 cm", output_unit="day", definition="Snow days (SD >= 1 cm)", @@ -556,7 +556,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) SD5CM = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, output_unit="day", threshold=">= 5 cm", definition="Number of days with snow depth >= 5 cm", @@ -567,7 +567,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) SD50CM = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, threshold=">= 50 cm", output_unit="day", definition="Number of days with snow depth >= 50 cm", @@ -579,7 +579,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: # Compound (precipitation and temperature) CD = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, threshold=[ "< 25 doy_per", build_threshold("< 25 period_per", threshold_min_value="1 mm/day"), @@ -596,7 +596,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) CW = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, threshold=[ "< 25 doy_per", build_threshold("> 75 period_per", threshold_min_value="1 mm/day"), @@ -613,7 +613,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) WD = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, threshold=[ "> 75 doy_per", build_threshold("< 25 period_per", threshold_min_value="1 mm/day"), @@ -630,7 +630,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) WW = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, threshold=[ "> 75 doy_per", build_threshold("> 75 period_per", threshold_min_value="1 mm/day"), @@ -648,7 +648,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: # WIND FXX = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.Maximum, + indicator=GenericIndicatorRegistry.Maximum, output_unit="m s-1", definition="Maximum value of daily maximum wind gust", source=ECAD_ATBD, @@ -658,7 +658,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) FG6BFT = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, threshold=">= 10.8 m s-1", output_unit="day", definition="Days with daily averaged wind ≥ 6 Bft (10.8 m s-1)", @@ -669,7 +669,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) FGCALM = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, threshold="<= 2 m s-1", output_unit="day", definition="Calm days, days with daily averaged wind <= 2 m s-1", @@ -680,7 +680,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) FG = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.Average, + indicator=GenericIndicatorRegistry.Average, output_unit="m s-1", definition="Mean of daily mean wind strength", source=ECAD_ATBD, @@ -690,7 +690,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) DDNORTH = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, threshold="> 315 degree OR <= 45 degree", output_unit="day", definition="Days with northerly winds (DD > 315° or DD ≤ 45°)", @@ -701,7 +701,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) DDEAST = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, threshold="> 45 degree AND <= 135 degree", output_unit="day", definition="Days with easterly winds (45° < DD <= 135°)", @@ -712,7 +712,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) DDSOUTH = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, threshold="> 135 degree AND <= 225 degree", output_unit="day", definition="Days with southerly winds (135° < DD <= 225°)", @@ -723,7 +723,7 @@ def list(cls: EcadIndexRegistry) -> list[str]: ) DDWEST = StandardIndex( reference=ECAD_REFERENCE, - generic_indicator=GenericIndicatorRegistry.CountOccurrences, + indicator=GenericIndicatorRegistry.CountOccurrences, threshold="> 225 degree AND <= 315 degree", output_unit="day", definition="Days with westerly winds (225° < DD <= 315°)", diff --git a/icclim/generic_indices/generic_indicators.py b/icclim/generic_indices/generic_indicators.py index 3fbc61c9..cbc7332c 100644 --- a/icclim/generic_indices/generic_indicators.py +++ b/icclim/generic_indices/generic_indicators.py @@ -73,7 +73,7 @@ class Indicator(ABC): ] @abc.abstractmethod - def __call__(self, *args, **kwargs) -> DataArray: + def __call__(self, config: IndexConfig, *args, **kwargs) -> DataArray: ... @abc.abstractmethod @@ -253,8 +253,7 @@ def preprocess( # noqa signature != from super src_freq=src_freq, ) - def __call__(self, config: IndexConfig) -> DataArray: - # icclim wrapper + def __call__(self, config: IndexConfig, *args, **kwargs) -> DataArray: src_freq = config.climate_variables[0].source_frequency base_jinja_scope = { "np": numpy, @@ -372,7 +371,7 @@ def excess( resample_freq: Frequency, **kwargs, # noqa ) -> DataArray: - study, threshold = _get_single_var(climate_vars) + study, threshold = get_single_var(climate_vars) if threshold.operator is not OperatorRegistry.REACH: raise InvalidIcclimArgumentError("") excesses = threshold.compute(study, override_op=lambda da, th: da - th) @@ -387,7 +386,7 @@ def deficit( resample_freq: Frequency, **kwargs, # noqa ) -> DataArray: - study, threshold = _get_single_var(climate_vars) + study, threshold = get_single_var(climate_vars) deficit = threshold.compute(study, override_op=lambda da, th: th - da) res = deficit.clip(min=0).resample(time=resample_freq.pandas_freq).sum(dim="time") return to_agg_units(res, study, "delta_prod") @@ -399,7 +398,7 @@ def fraction_of_total( to_percent: bool, **kwargs, # noqa ) -> DataArray: - study, threshold = _get_single_var(climate_vars) + study, threshold = get_single_var(climate_vars) if threshold.threshold_min_value is not None: total = ( study.where(threshold.operator(study, threshold.threshold_min_value.m)) @@ -816,7 +815,7 @@ def _run_rolling_reducer( date_event: bool, source_freq_delta: timedelta, ) -> DataArray: - study, threshold = _get_single_var(climate_vars) + study, threshold = get_single_var(climate_vars) if threshold: exceedance = _compute_exceedance( study=study, @@ -845,7 +844,7 @@ def _run_simple_reducer( date_event: bool, must_convert_rate: bool = False, ): - study, threshold = _get_single_var(climate_vars) + study, threshold = get_single_var(climate_vars) if threshold is not None: exceedance = _compute_exceedance( study=study, @@ -887,7 +886,7 @@ def _compute_exceedances( return logical_link(exceedances) -def _get_single_var( +def get_single_var( climate_vars: list[ClimateVariable], ) -> tuple[DataArray, Threshold | None]: if climate_vars[0].threshold: diff --git a/icclim/main.py b/icclim/main.py index 3920a7b3..842d4002 100644 --- a/icclim/main.py +++ b/icclim/main.py @@ -360,7 +360,7 @@ def index( del indice_name, transfer_limit_Mbytes, user_indice, save_percentile, window_width # -- Choose index to compute interpolation = QuantileInterpolationRegistry.lookup(interpolation) - indicator: GenericIndicator + indicator: Indicator standard_index: StandardIndex | None logical_link: LogicalLink coef: float | None @@ -395,7 +395,7 @@ def index( rename = None output_unit = out_unit else: - indicator = standard_index.generic_indicator + indicator = standard_index.indicator threshold = standard_index.threshold rename = standard_index.short_name output_unit = out_unit or standard_index.output_unit @@ -555,7 +555,7 @@ def _get_unit(output_unit: str | None, da: DataArray) -> str | None: def _compute_climate_index( - climate_index: GenericIndicator | None, + climate_index: Indicator | None, config: IndexConfig, initial_history: str | None, initial_source: str, diff --git a/icclim/models/index_config.py b/icclim/models/index_config.py index 6267ea31..6289c2b5 100644 --- a/icclim/models/index_config.py +++ b/icclim/models/index_config.py @@ -20,14 +20,14 @@ class IndexConfig: ---------- frequency: Frequency The expected resampling frequency of the output. - cf_variables: + climate_variables: List of CfVariable necessary to compute the index. save_percentile: bool = False On percentile based indices, if True, this saves the percentile in the output netcdf. netcdf_version: Netcdf version to be used when creating the output - window: + rolling_window_width: On indices relying on a rolling window of days, configure the window width. scalar_thresholds: On indices relying on a threshold, configure the threshold value. Unit less. diff --git a/icclim/models/registry.py b/icclim/models/registry.py index 0eab0a3a..d9f59c99 100644 --- a/icclim/models/registry.py +++ b/icclim/models/registry.py @@ -1,5 +1,6 @@ from __future__ import annotations +from abc import ABC from copy import deepcopy from typing import Generic, TypeVar @@ -8,7 +9,7 @@ T = TypeVar("T") -class Registry(Generic[T]): +class Registry(Generic[T], ABC): """This class is a fancy enum to easily store and find constant items of similar type. It acts as a namespace so there is no need to instantiate it or any of @@ -22,9 +23,6 @@ class Registry(Generic[T]): _item_class: type # runtime type for the generic `T` - def __init__(self): - raise NotImplementedError("Don't instantiate Registry, use its class methods.") - @classmethod def lookup(cls, query: T | str, no_error: bool = False) -> T: if isinstance(query, cls._item_class): diff --git a/icclim/models/standard_index.py b/icclim/models/standard_index.py index b497aa57..a7ae1d64 100644 --- a/icclim/models/standard_index.py +++ b/icclim/models/standard_index.py @@ -6,6 +6,7 @@ from xarray import DataArray from icclim.generic_indices.cf_var_metadata import StandardVariable +from icclim.models.index_config import IndexConfig from icclim.models.index_group import IndexGroup ComputeIndexFun = Callable[ @@ -45,7 +46,7 @@ class StandardIndex: short_name: str group: IndexGroup input_variables: list[StandardVariable] | None # None when index is generic - generic_indicator: Any # Any -> GenericIndicator + indicator: Any # Any -> Indicator # todo: merge qualifiers with group into a Set of qualifiers ? qualifiers: list[str] | None = None source: str | None = None @@ -61,14 +62,14 @@ class StandardIndex: def __str__(self): return f"{self.group} | {self.short_name} | {self.definition}" - def __call__(self, *args, **kwargs): - self.generic_indicator(*args, **kwargs) + def __call__(self, index_config: IndexConfig, *args, **kwargs): + self.indicator(index_config, *args, **kwargs) def __eq__(self, other: Any) -> bool: if not isinstance(other, StandardIndex): return False return ( - self.generic_indicator.name == other.generic_indicator.name + self.indicator == other.indicator and self.threshold == other.threshold and self.output_unit == other.output_unit and self.rolling_window_width == other.rolling_window_width