From 3359b1b748bfbdc6c79f37c800227cc325d34e30 Mon Sep 17 00:00:00 2001 From: Pascal Bourgault Date: Fri, 13 Oct 2023 14:30:22 -0400 Subject: [PATCH 1/5] Add keywords, move ind api to its own page --- docs/_static/indsearch.js | 2 +- docs/api.rst | 47 ++------------------------ xclim/core/indicator.py | 5 ++- xclim/indicators/atmos/_precip.py | 7 ++++ xclim/indicators/atmos/_temperature.py | 5 +++ xclim/indicators/atmos/_wind.py | 1 + xclim/indicators/land/_snow.py | 3 ++ xclim/indicators/land/_streamflow.py | 1 + xclim/indicators/seaIce/_seaice.py | 1 + 9 files changed, 26 insertions(+), 46 deletions(-) diff --git a/docs/_static/indsearch.js b/docs/_static/indsearch.js index cbaacbac5..d657a63f4 100644 --- a/docs/_static/indsearch.js +++ b/docs/_static/indsearch.js @@ -67,7 +67,7 @@ function indTemplate(ind) {
diff --git a/docs/api.rst b/docs/api.rst index 8e91a0600..65631ee85 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -10,51 +10,10 @@ API Indicators ========== -Indicators are the main tool xclim provides to compute climate indices. In contrast -to the function defined in `xclim.indices`, Indicators add a layer of health checks -and metadata handling. Indicator objects are split into realms : atmos, land and seaIce. +.. toctree:: + :maxdepth: 1 -Virtual modules are also inserted here. A normal installation of xclim comes with three virtual modules: - - - :py:mod:`xclim.indicators.cf`, Indicators defined in `cf-index-meta`. - - :py:mod:`xclim.indicators.icclim`, Indicators defined by ECAD, as found in python package Icclim. - - :py:mod:`xclim.indicators.anuclim`, Indicators of the Australian National University's Fenner School of Environment and Society. - -Climate Indicators API ----------------------- - -.. automodule:: xclim.indicators.atmos - :members: - :undoc-members: - :imported-members: - -.. automodule:: xclim.indicators.land - :members: - :undoc-members: - :imported-members: - -.. automodule:: xclim.indicators.seaIce - :members: - :undoc-members: - :imported-members: - -Virtual Indicator Submodules ----------------------------- - -.. automodule:: xclim.indicators.cf - :members: - :imported-members: - :undoc-members: - -.. automodule:: xclim.indicators.icclim - :members: - :imported-members: - :undoc-members: - -.. automodule:: xclim.indicators.anuclim - :members: - :imported-members: - :undoc-members: + api_indicators Indices ======= diff --git a/xclim/core/indicator.py b/xclim/core/indicator.py index 4aeb7bb2a..5b323423e 100644 --- a/xclim/core/indicator.py +++ b/xclim/core/indicator.py @@ -462,9 +462,12 @@ def __new__(cls, **kwds): # All updates done. kwds["_all_parameters"] = parameters - # Parse keywords to organize `cf_attrs` + # Parse kwds to organize `cf_attrs` # And before converting callables to static methods kwds["cf_attrs"] = cls._parse_output_attrs(kwds, identifier) + # Parse keywords + if "keywords" in kwds: + kwds["keywords"] = cls.keywords + " " + kwds.get("keywords") # Convert function objects to static methods. for key in cls._funcs: diff --git a/xclim/indicators/atmos/_precip.py b/xclim/indicators/atmos/_precip.py index 988a09476..431634e84 100644 --- a/xclim/indicators/atmos/_precip.py +++ b/xclim/indicators/atmos/_precip.py @@ -71,12 +71,14 @@ class FireWeather(Indicator): src_freq = "D" context = "hydro" + keywords = "fire" class Precip(Daily): """Indicator involving daily pr series.""" context = "hydro" + keywords = "precipitation" class PrecipWithIndexing(ResamplingIndicatorWithIndexing): @@ -84,6 +86,7 @@ class PrecipWithIndexing(ResamplingIndicatorWithIndexing): src_freq = "D" context = "hydro" + keywords = "precipitation" class PrTasxWithIndexing(ResamplingIndicatorWithIndexing): @@ -91,6 +94,7 @@ class PrTasxWithIndexing(ResamplingIndicatorWithIndexing): src_freq = "D" context = "hydro" + keywords = "precipitation" def cfcheck(self, pr, tas): cfchecks.cfcheck_from_name("pr", pr) @@ -108,6 +112,7 @@ class HrPrecip(Hourly): """Indicator involving hourly pr series.""" context = "hydro" + keywords = "precipitation" rain_on_frozen_ground_days = PrTasxWithIndexing( @@ -363,6 +368,7 @@ class HrPrecip(Hourly): abstract="Precipitation over a moving window, normalized such that SPI averages to 0 for the calibration data. " "The window unit `X` is the minimal time period defined by the resampling frequency.", cell_methods="", + keywords="precipitation", compute=indices.standardized_precipitation_index, ) @@ -379,6 +385,7 @@ class HrPrecip(Hourly): "SPEI averages to 0 for the calibration data. The window unit `X` is the minimal time period defined by the " "resampling frequency.", cell_methods="", + keywords="precipitation", compute=indices.standardized_precipitation_evapotranspiration_index, ) diff --git a/xclim/indicators/atmos/_temperature.py b/xclim/indicators/atmos/_temperature.py index 0182b3316..b1828cbc9 100644 --- a/xclim/indicators/atmos/_temperature.py +++ b/xclim/indicators/atmos/_temperature.py @@ -93,11 +93,14 @@ class Temp(Daily): """Indicators involving daily temperature.""" + keywords = "temperature" + class TempWithIndexing(ResamplingIndicatorWithIndexing): """Indicators involving daily temperature and adding an indexing possibility.""" src_freq = "D" + keywords = "temperature" tn_days_above = TempWithIndexing( @@ -1163,6 +1166,8 @@ class TempWithIndexing(ResamplingIndicatorWithIndexing): class FireSeasonBase(Indicator): """Special Indicator class for FireSeason that accepts any tas[min/max] and optional snd and is not resampling.""" + keywords = "fire" + def cfcheck(self, tas, snd=None): cfchecks.check_valid(tas, "standard_name", "air_temperature") cfchecks.cfcheck_from_name("snd", snd) diff --git a/xclim/indicators/atmos/_wind.py b/xclim/indicators/atmos/_wind.py index 9525c63e1..3e63036ad 100644 --- a/xclim/indicators/atmos/_wind.py +++ b/xclim/indicators/atmos/_wind.py @@ -19,6 +19,7 @@ class Wind(ResamplingIndicatorWithIndexing): """Indicator involving daily sfcWind series.""" src_freq = "D" + keywords = "wind" calm_days = Wind( diff --git a/xclim/indicators/land/_snow.py b/xclim/indicators/land/_snow.py index 458109a37..f2294d1ab 100644 --- a/xclim/indicators/land/_snow.py +++ b/xclim/indicators/land/_snow.py @@ -27,11 +27,14 @@ class Snow(Daily): """Indicators dealing with snow variables.""" + keywords = "snow" + class SnowWithIndexing(ResamplingIndicatorWithIndexing): """Indicators dealing with snow variables, allowing indexing.""" src_freq = "D" + keywords = "snow" snd_season_length = SnowWithIndexing( diff --git a/xclim/indicators/land/_streamflow.py b/xclim/indicators/land/_streamflow.py index c6c7a74b4..dc4984126 100644 --- a/xclim/indicators/land/_streamflow.py +++ b/xclim/indicators/land/_streamflow.py @@ -17,6 +17,7 @@ class Streamflow(ResamplingIndicator): context = "hydro" src_freq = "D" + keywords = "streamflow hydrology" @staticmethod def cfcheck(q): diff --git a/xclim/indicators/seaIce/_seaice.py b/xclim/indicators/seaIce/_seaice.py index 61156d14f..ec9f52b4e 100644 --- a/xclim/indicators/seaIce/_seaice.py +++ b/xclim/indicators/seaIce/_seaice.py @@ -14,6 +14,7 @@ class SiconcAreacello(Indicator): """Class for indicators having sea ice concentration and grid cell area inputs.""" missing = "skip" + keywords = "seaice" sea_ice_extent = SiconcAreacello( From 88c3ab44e6ded64d6bfc263682c8799eb8ba5372 Mon Sep 17 00:00:00 2001 From: Pascal Bourgault Date: Fri, 13 Oct 2023 14:34:38 -0400 Subject: [PATCH 2/5] ofc i forgot to add the new file --- docs/api_indicators.rst | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 docs/api_indicators.rst diff --git a/docs/api_indicators.rst b/docs/api_indicators.rst new file mode 100644 index 000000000..d24dfd2e2 --- /dev/null +++ b/docs/api_indicators.rst @@ -0,0 +1,45 @@ +Indicators are the main tool xclim provides to compute climate indices. In contrast +to the function defined in `xclim.indices`, Indicators add a layer of health checks +and metadata handling. Indicator objects are split into realms : atmos, land and seaIce. + +Virtual modules are also inserted here. A normal installation of xclim comes with three virtual modules: + + - :py:mod:`xclim.indicators.cf`, Indicators defined in `cf-index-meta`. + - :py:mod:`xclim.indicators.icclim`, Indicators defined by ECAD, as found in python package Icclim. + - :py:mod:`xclim.indicators.anuclim`, Indicators of the Australian National University's Fenner School of Environment and Society. + +Climate Indicators API +---------------------- + +.. automodule:: xclim.indicators.atmos + :members: + :undoc-members: + :imported-members: + +.. automodule:: xclim.indicators.land + :members: + :undoc-members: + :imported-members: + +.. automodule:: xclim.indicators.seaIce + :members: + :undoc-members: + :imported-members: + +Virtual Indicator Submodules +---------------------------- + +.. automodule:: xclim.indicators.cf + :members: + :imported-members: + :undoc-members: + +.. automodule:: xclim.indicators.icclim + :members: + :imported-members: + :undoc-members: + +.. automodule:: xclim.indicators.anuclim + :members: + :imported-members: + :undoc-members: From cf05b22bf5d81a9d271df2d0511fde9c0163df0c Mon Sep 17 00:00:00 2001 From: Pascal Bourgault Date: Fri, 13 Oct 2023 14:54:19 -0400 Subject: [PATCH 3/5] Update test_formatting.py --- tests/test_formatting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_formatting.py b/tests/test_formatting.py index 7388c4859..09091bab8 100644 --- a/tests/test_formatting.py +++ b/tests/test_formatting.py @@ -30,7 +30,7 @@ def test_indicator_docstring(): doc[5] == "Based on indice :py:func:`~xclim.indices._multivariate.heat_wave_frequency`." ) - assert doc[6] == "Keywords : health,." + assert doc[6] == "Keywords : temperature health,." assert doc[12] == " Default : `ds.tasmin`. [Required units : [temperature]]" assert ( doc[41] From afc95a45716691a8175a68c8d67950fd17f256ae Mon Sep 17 00:00:00 2001 From: Zeitsperre <10819524+Zeitsperre@users.noreply.github.com> Date: Mon, 16 Oct 2023 13:20:47 -0400 Subject: [PATCH 4/5] adjust test expectation --- tests/test_formatting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_formatting.py b/tests/test_formatting.py index 09091bab8..958240d49 100644 --- a/tests/test_formatting.py +++ b/tests/test_formatting.py @@ -42,7 +42,7 @@ def test_indicator_docstring(): ) doc = degree_days_exceedance_date.__doc__.split("\n") - assert doc[20] == " Default : >. " + assert doc[21] == " Default : >. " def test_update_xclim_history(atmosds): From b9f987408dd8de5aa564672c0c34a1645ebea881 Mon Sep 17 00:00:00 2001 From: Pascal Bourgault Date: Mon, 16 Oct 2023 17:26:05 -0400 Subject: [PATCH 5/5] Update CHANGES.rst --- CHANGES.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.rst b/CHANGES.rst index 141113c06..b530cf4b5 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -46,6 +46,7 @@ Internal changes * The `pkg_resources` library has been replaced for the `packaging` library when version comparisons have been performed, and a few warning messages have been silenced in the testing suite. (:issue:`1489`, :pull:`1490`). * New ``xclim.testing.helpers.assert_lazy`` context manager to assert the laziness of code blocks. (:pull:`1484`). * Added a fix for the deprecation warnings that `importlib.resources` throws, made backwards-compatible for Python3.8 with `importlib_resources` backport. (:pull:`1485`). +* Added basic keywords on most indicators for easier searching in the docs. Extracted climate indicators API to its own page for faster loaing. (:pull:`1502`, :issue:`1433`). v0.45.0 (2023-09-05) --------------------