Skip to content

Commit

Permalink
Add keywords, move indicators API to its own page (#1502)
Browse files Browse the repository at this point in the history
### What kind of change does this PR introduce?

* Changes how the "keyword" attribute is inherited between indicators to
inherit by concatenating.
* Add basic keywords to all subclasses
* Move the indicators API to its own page to lower loading times (it's
still slow, but a lot more bearable IMO)

### Does this PR introduce a breaking change?
No.
  • Loading branch information
Zeitsperre authored Oct 16, 2023
2 parents e6fcaeb + b9f9874 commit 21388ff
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 48 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
--------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/_static/indsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function indTemplate(ind) {
<div class="indElem" id="${ind.id}">
<div class="indHeader">
<b class="indTitle">${ind.title}</b>
<a class="reference_internal indName" href="api.html#xclim.indicators.${ind.module}.${ind.name}" title="${ind.name}">
<a class="reference_internal indName" href="api_indicators.html#xclim.indicators.${ind.module}.${ind.name}" title="${ind.name}">
<code>${ind.module}.${ind.name}</code>
</a>
</div>
Expand Down
47 changes: 3 additions & 44 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=======
Expand Down
45 changes: 45 additions & 0 deletions docs/api_indicators.rst
Original file line number Diff line number Diff line change
@@ -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:
4 changes: 2 additions & 2 deletions tests/test_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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):
Expand Down
5 changes: 4 additions & 1 deletion xclim/core/indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions xclim/indicators/atmos/_precip.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,30 @@ 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):
"""Indicator involving daily pr series and allowing indexing."""

src_freq = "D"
context = "hydro"
keywords = "precipitation"


class PrTasxWithIndexing(ResamplingIndicatorWithIndexing):
"""Indicator involving pr and one of tas, tasmin or tasmax, allowing indexing."""

src_freq = "D"
context = "hydro"
keywords = "precipitation"

def cfcheck(self, pr, tas):
cfchecks.cfcheck_from_name("pr", pr)
Expand All @@ -108,6 +112,7 @@ class HrPrecip(Hourly):
"""Indicator involving hourly pr series."""

context = "hydro"
keywords = "precipitation"


rain_on_frozen_ground_days = PrTasxWithIndexing(
Expand Down Expand Up @@ -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,
)

Expand All @@ -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,
)

Expand Down
5 changes: 5 additions & 0 deletions xclim/indicators/atmos/_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions xclim/indicators/atmos/_wind.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Wind(ResamplingIndicatorWithIndexing):
"""Indicator involving daily sfcWind series."""

src_freq = "D"
keywords = "wind"


calm_days = Wind(
Expand Down
3 changes: 3 additions & 0 deletions xclim/indicators/land/_snow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions xclim/indicators/land/_streamflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
class Streamflow(ResamplingIndicator):
context = "hydro"
src_freq = "D"
keywords = "streamflow hydrology"

@staticmethod
def cfcheck(q):
Expand Down
1 change: 1 addition & 0 deletions xclim/indicators/seaIce/_seaice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 21388ff

Please sign in to comment.