Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enh/add new ecad indices #295

Merged
merged 6 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion doc/source/references/ecad_functions_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ For example to use this new API with the index `su` you can do:
gsl
spi6
spi3
pp
ss
rh
custom_index

.. Generated API comment:End
.. Generated API comment:End
2 changes: 1 addition & 1 deletion doc/source/references/generic_functions_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ capabilities of these generic indices.
mean_of_absolute_one_time_step_difference
difference_of_means

.. Generated API comment:End
.. Generated API comment:End
6 changes: 6 additions & 0 deletions doc/source/references/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
release being published. This action requires a manual approval on
github.

- [enh] Add the following ECAD indices: PP (average of pressure),
SS (sum of sunshine) and RH (average of humidity).

- [fix] the default unit of clt standard variable is now % as expected
(was a wind strenght unit).

*******
6.5.0
*******
Expand Down
243 changes: 243 additions & 0 deletions src/icclim/_generated_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@
"gsl",
"spi6",
"spi3",
"pp",
"ss",
"rh",
"custom_index",
]

Expand Down Expand Up @@ -7683,6 +7686,246 @@ def spi3(
)


def pp(
in_files: InFileLike,
var_name: str | Sequence[str] | None = None,
slice_mode: FrequencyLike | Frequency = "year",
time_range: Sequence[dt.datetime | str] | None = None,
out_file: str | None = None,
ignore_Feb29th: bool = False,
netcdf_version: str | NetcdfVersion = "NETCDF4",
logs_verbosity: Verbosity | str = "LOW",
date_event: bool = False,
) -> Dataset:
"""PP.

Mean of daily sea level pressure (hPa)
Source: ECA&D, Algorithm Theoretical Basis Document (ATBD) v11.

Parameters
----------
in_files: str | list[str] | Dataset | DataArray | InputDictionary
Absolute path(s) to NetCDF dataset(s), including OPeNDAP URLs,
or path to zarr store, or xarray.Dataset or xarray.DataArray.
var_name: str | list[str] | None
``optional`` Target variable name to process corresponding to ``in_files``.
If None (default) on ECA&D index, the variable is guessed based on the
climate index wanted.
Mandatory for a user index.
slice_mode: SliceMode
Type of temporal aggregation:
The possibles values are ``{"year", "month", "DJF", "MAM", "JJA", "SON",
"ONDJFM" or "AMJJAS", ("season", [1,2,3]), ("month", [1,2,3,])}``
(where season and month lists can be customized) or any valid pandas
frequency.
A season can also be defined between two exact dates:
``("season", ("19 july", "14 august"))``.
Default is "year".
See :ref:`slice_mode` for details.
time_range: list[datetime.datetime ] | list[str] | tuple[str, str] | None
``optional`` Temporal range: upper and lower bounds for temporal subsetting.
If ``None``, whole period of input files will be processed.
The dates can either be given as instance of datetime.datetime or as string
values. For strings, many format are accepted.
Default is ``None``.
out_file: str | None
Output NetCDF file name (default: "icclim_out.nc" in the current directory).
Default is "icclim_out.nc".
If the input ``in_files`` is a ``Dataset``, ``out_file`` field is ignored.
Use the function returned value instead to retrieve the computed value.
If ``out_file`` already exists, icclim will overwrite it!
ignore_Feb29th: bool
``optional`` Ignoring or not February 29th (default: False).
netcdf_version: str | NetcdfVersion
``optional`` NetCDF version to create (default: "NETCDF3_CLASSIC").
logs_verbosity: str | Verbosity
``optional`` Configure how verbose icclim is.
Possible values: ``{"LOW", "HIGH", "SILENT"}`` (default: "LOW")
date_event: bool
When True the date of the event (such as when a maximum is reached) will be
stored in coordinates variables.
**warning** This option may significantly slow down computation.

Notes
-----
This function has been auto-generated.

"""
return icclim.index(
index_name="PP",
in_files=in_files,
var_name=var_name,
slice_mode=slice_mode,
time_range=time_range,
out_file=out_file,
ignore_Feb29th=ignore_Feb29th,
netcdf_version=netcdf_version,
logs_verbosity=logs_verbosity,
date_event=date_event,
out_unit="hPa",
)


def ss(
in_files: InFileLike,
var_name: str | Sequence[str] | None = None,
slice_mode: FrequencyLike | Frequency = "year",
time_range: Sequence[dt.datetime | str] | None = None,
out_file: str | None = None,
ignore_Feb29th: bool = False,
netcdf_version: str | NetcdfVersion = "NETCDF4",
logs_verbosity: Verbosity | str = "LOW",
date_event: bool = False,
) -> Dataset:
"""SS.

Sunshine duration (hours)
Source: ECA&D, Algorithm Theoretical Basis Document (ATBD) v11.

Parameters
----------
in_files: str | list[str] | Dataset | DataArray | InputDictionary
Absolute path(s) to NetCDF dataset(s), including OPeNDAP URLs,
or path to zarr store, or xarray.Dataset or xarray.DataArray.
var_name: str | list[str] | None
``optional`` Target variable name to process corresponding to ``in_files``.
If None (default) on ECA&D index, the variable is guessed based on the
climate index wanted.
Mandatory for a user index.
slice_mode: SliceMode
Type of temporal aggregation:
The possibles values are ``{"year", "month", "DJF", "MAM", "JJA", "SON",
"ONDJFM" or "AMJJAS", ("season", [1,2,3]), ("month", [1,2,3,])}``
(where season and month lists can be customized) or any valid pandas
frequency.
A season can also be defined between two exact dates:
``("season", ("19 july", "14 august"))``.
Default is "year".
See :ref:`slice_mode` for details.
time_range: list[datetime.datetime ] | list[str] | tuple[str, str] | None
``optional`` Temporal range: upper and lower bounds for temporal subsetting.
If ``None``, whole period of input files will be processed.
The dates can either be given as instance of datetime.datetime or as string
values. For strings, many format are accepted.
Default is ``None``.
out_file: str | None
Output NetCDF file name (default: "icclim_out.nc" in the current directory).
Default is "icclim_out.nc".
If the input ``in_files`` is a ``Dataset``, ``out_file`` field is ignored.
Use the function returned value instead to retrieve the computed value.
If ``out_file`` already exists, icclim will overwrite it!
ignore_Feb29th: bool
``optional`` Ignoring or not February 29th (default: False).
netcdf_version: str | NetcdfVersion
``optional`` NetCDF version to create (default: "NETCDF3_CLASSIC").
logs_verbosity: str | Verbosity
``optional`` Configure how verbose icclim is.
Possible values: ``{"LOW", "HIGH", "SILENT"}`` (default: "LOW")
date_event: bool
When True the date of the event (such as when a maximum is reached) will be
stored in coordinates variables.
**warning** This option may significantly slow down computation.

Notes
-----
This function has been auto-generated.

"""
return icclim.index(
index_name="SS",
in_files=in_files,
var_name=var_name,
slice_mode=slice_mode,
time_range=time_range,
out_file=out_file,
ignore_Feb29th=ignore_Feb29th,
netcdf_version=netcdf_version,
logs_verbosity=logs_verbosity,
date_event=date_event,
out_unit="hours",
)


def rh(
in_files: InFileLike,
var_name: str | Sequence[str] | None = None,
slice_mode: FrequencyLike | Frequency = "year",
time_range: Sequence[dt.datetime | str] | None = None,
out_file: str | None = None,
ignore_Feb29th: bool = False,
netcdf_version: str | NetcdfVersion = "NETCDF4",
logs_verbosity: Verbosity | str = "LOW",
date_event: bool = False,
) -> Dataset:
"""RH.

Mean of daily relative humidity (%)
Source: ECA&D, Algorithm Theoretical Basis Document (ATBD) v11.

Parameters
----------
in_files: str | list[str] | Dataset | DataArray | InputDictionary
Absolute path(s) to NetCDF dataset(s), including OPeNDAP URLs,
or path to zarr store, or xarray.Dataset or xarray.DataArray.
var_name: str | list[str] | None
``optional`` Target variable name to process corresponding to ``in_files``.
If None (default) on ECA&D index, the variable is guessed based on the
climate index wanted.
Mandatory for a user index.
slice_mode: SliceMode
Type of temporal aggregation:
The possibles values are ``{"year", "month", "DJF", "MAM", "JJA", "SON",
"ONDJFM" or "AMJJAS", ("season", [1,2,3]), ("month", [1,2,3,])}``
(where season and month lists can be customized) or any valid pandas
frequency.
A season can also be defined between two exact dates:
``("season", ("19 july", "14 august"))``.
Default is "year".
See :ref:`slice_mode` for details.
time_range: list[datetime.datetime ] | list[str] | tuple[str, str] | None
``optional`` Temporal range: upper and lower bounds for temporal subsetting.
If ``None``, whole period of input files will be processed.
The dates can either be given as instance of datetime.datetime or as string
values. For strings, many format are accepted.
Default is ``None``.
out_file: str | None
Output NetCDF file name (default: "icclim_out.nc" in the current directory).
Default is "icclim_out.nc".
If the input ``in_files`` is a ``Dataset``, ``out_file`` field is ignored.
Use the function returned value instead to retrieve the computed value.
If ``out_file`` already exists, icclim will overwrite it!
ignore_Feb29th: bool
``optional`` Ignoring or not February 29th (default: False).
netcdf_version: str | NetcdfVersion
``optional`` NetCDF version to create (default: "NETCDF3_CLASSIC").
logs_verbosity: str | Verbosity
``optional`` Configure how verbose icclim is.
Possible values: ``{"LOW", "HIGH", "SILENT"}`` (default: "LOW")
date_event: bool
When True the date of the event (such as when a maximum is reached) will be
stored in coordinates variables.
**warning** This option may significantly slow down computation.

Notes
-----
This function has been auto-generated.

"""
return icclim.index(
index_name="RH",
in_files=in_files,
var_name=var_name,
slice_mode=slice_mode,
time_range=time_range,
out_file=out_file,
ignore_Feb29th=ignore_Feb29th,
netcdf_version=netcdf_version,
logs_verbosity=logs_verbosity,
date_event=date_event,
out_unit="%",
)


def custom_index(
user_index: UserIndexDict,
in_files: InFileLike,
Expand Down
33 changes: 33 additions & 0 deletions src/icclim/ecad/ecad_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,3 +764,36 @@ def to_list(cls: EcadIndexRegistry) -> list[str]:
qualifiers=[REFERENCE_PERIOD_INDEX],
output_unit="",
)
PP = StandardIndex(
reference=ECAD_REFERENCE,
indicator=GenericIndicatorRegistry.Average,
definition="Mean of daily sea level pressure (hPa)",
source=ECAD_ATBD,
short_name="PP",
group=IndexGroupRegistry.PRESSURE,
input_variables=[StandardVariableRegistry.PSL],
qualifiers=[],
output_unit="hPa",
)
SS = StandardIndex(
reference=ECAD_REFERENCE,
indicator=GenericIndicatorRegistry.Sum,
definition="Sunshine duration (hours)",
source=ECAD_ATBD,
short_name="SS",
group=IndexGroupRegistry.SUNSHINE,
input_variables=[StandardVariableRegistry.SUND],
qualifiers=[],
output_unit="hours",
)
RH = StandardIndex(
reference=ECAD_REFERENCE,
indicator=GenericIndicatorRegistry.Average,
definition="Mean of daily relative humidity (%)",
source=ECAD_ATBD,
short_name="RH",
group=IndexGroupRegistry.HUMIDITY,
input_variables=[StandardVariableRegistry.HURS],
qualifiers=[],
output_unit="%",
)
2 changes: 1 addition & 1 deletion src/icclim/generic_indices/standard_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class StandardVariableRegistry(Registry[StandardVariable]):
standard_name="cloud_area_fraction",
long_name="Total Cloud Cover Percentage",
aliases=["clt"],
default_units="m s-1",
default_units="%",
)
RSDS = StandardVariable(
short_name="rsds",
Expand Down
3 changes: 3 additions & 0 deletions src/icclim/models/index_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,8 @@ class IndexGroupRegistry(Registry[IndexGroup]):
RAIN = IndexGroup("rain")
SNOW = IndexGroup("snow")
WIND = IndexGroup("wind")
PRESSURE = IndexGroup("pressure")
SUNSHINE = IndexGroup("sunshine")
HUMIDITY = IndexGroup("humidity")
# no climate index should be bounded to "all"
WILD_CARD_GROUP = IndexGroup("all")
Loading
Loading