Repository: Ouranosinc/xclim

Issue:
Implement missing ICCLIM indices
A few icclim indices were never included in early xclim implementation  @bzah indicates he can spend some time on this

List of indices:

- [x] SD : Snow depth
- [ ] CD : Cold and dry days
- [ ] CW: Cold and wet days
- [ ] WD: Warm and dry days
- [ ] WW: Warm and wet days



Discussion:

Patch:
diff --git a/.zenodo.json b/.zenodo.json
index 6f50705d..5b82038d 100644
--- a/.zenodo.json
+++ b/.zenodo.json
@@ -35,6 +35,11 @@
       "name": "Rondeau-Genesse, Gabriel",
       "orcid": "0000-0003-3389-9406"
     },
+    {
+      "affiliation": "CERFACS",
+      "name": "Aoun, Abel",
+      "orcid": "0000-0003-2289-2890"
+    },
     {
       "name": "Roy, Philippe"
     },
@@ -67,5 +72,6 @@
     "analysis"
   ],
   "license": "Apache-2.0",
-  "upload_type": "software"
+  "upload_type": "software",
+  "access_right": "open"
 }
diff --git a/HISTORY.rst b/HISTORY.rst
index 115bff91..89fac4ff 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -2,6 +2,15 @@
 History
 =======
 
+
+0.29.0 (unreleased)
+-------------------
+
+New indicators
+~~~~~~~~~~~~~~
+* ``snow_depth`` indicator returns the mean snow depth over period. Added as ``SD`` to ICCLIM module.
+
+
 0.28.0 (2021-07-07)
 -------------------
 
diff --git a/xclim/data/fr.json b/xclim/data/fr.json
index c808aa5c..df42c8fd 100644
--- a/xclim/data/fr.json
+++ b/xclim/data/fr.json
@@ -763,6 +763,12 @@
     "title": "Approximation de la neige",
     "abstract": "Précipitation solide estimée à partir de la précipitation totale et de la température selon une méthode et un seuil de température donnés."
   },
+  "SD": {
+    "long_name": "Profondeur de neige journalière moyenne",
+    "description": "Profondeur de neige journalière moyenne",
+    "title": "Moyenne de la profondeur de neige",
+    "abstract": "Profondeur de neige journalière moyenne"
+  },
   "PRLP": {
     "long_name": "Précipitation liquide",
     "description": "Précipitation liquide estimée à partir de la précipitation totale et de la température selon la méthode {method} et le seuil de température {thresh}.",
diff --git a/xclim/data/icclim.yml b/xclim/data/icclim.yml
index 149cd5f9..5515f739 100644
--- a/xclim/data/icclim.yml
+++ b/xclim/data/icclim.yml
@@ -286,6 +286,11 @@ indices:
         per:
           data: {per}
           description: Daily 99th percentile of wet day precipitation flux.
+  SD:
+    realm: land
+    base: snow_depth
+    output:
+      long_name: Mean of daily snow depth
   SD1:
     realm: land
     base: snow_cover_duration
diff --git a/xclim/indicators/land/_snow.py b/xclim/indicators/land/_snow.py
index b991418f..17d8e395 100644
--- a/xclim/indicators/land/_snow.py
+++ b/xclim/indicators/land/_snow.py
@@ -9,6 +9,7 @@ __all__ = [
     "snd_max_doy",
     "snow_melt_we_max",
     "winter_storm",
+    "snow_depth",
 ]
 
 
@@ -89,3 +90,13 @@ blowing_snow = Snow(
     units="days",
     compute=xci.blowing_snow,
 )
+
+snow_depth = Snow(
+    identifier="snow_depth",
+    units="cm",
+    standard_name="surface_snow_thickness",
+    long_name="Mean of daily snow depth",
+    description="{freq} mean of daily mean snow depth.",
+    cell_methods="time: mean within days time: mean over days",
+    compute=xci.snow_depth,
+)
diff --git a/xclim/indices/_simple.py b/xclim/indices/_simple.py
index 9ecc771a..842fb7ff 100644
--- a/xclim/indices/_simple.py
+++ b/xclim/indices/_simple.py
@@ -27,6 +27,7 @@ __all__ = [
     "max_1day_precipitation_amount",
     "max_n_day_precipitation_amount",
     "max_pr_intensity",
+    "snow_depth",
 ]
 
 
@@ -502,3 +503,29 @@ def max_pr_intensity(
 
     out.attrs["units"] = pr.units
     return out
+
+
+@declare_units(snd="[length]")
+def snow_depth(
+    snd: xarray.DataArray,
+    freq: str = "YS",
+) -> xarray.DataArray:
+    """Mean of daily average snow depth.
+
+    Resample the original daily mean snow depth series by taking the mean over each period.
+
+    Parameters
+    ----------
+    tas : xarray.DataArray
+      Mean daily snow depth.
+    freq : str
+      Resampling frequency.
+
+    Returns
+    -------
+    xarray.DataArray, [same units as snd]
+      The mean daily snow depth at the given time frequency
+
+    """
+    arr = snd.resample(time=freq)
+    return arr.mean(dim="time", keep_attrs=True)


Test patch:
diff --git a/xclim/testing/tests/test_modules.py b/xclim/testing/tests/test_modules.py
index 9c667868..4cfde01f 100644
--- a/xclim/testing/tests/test_modules.py
+++ b/xclim/testing/tests/test_modules.py
@@ -32,7 +32,7 @@ def test_default_modules_exist():
 
     assert hasattr(cf, "fg")
 
-    assert len(list(icclim.iter_indicators())) == 49
+    assert len(list(icclim.iter_indicators())) == 50
     assert len(list(anuclim.iter_indicators())) == 19
     # Not testing cf because many indices are waiting to be implemented.
 
diff --git a/xclim/testing/tests/test_snow.py b/xclim/testing/tests/test_snow.py
index d321cad9..598b378a 100644
--- a/xclim/testing/tests/test_snow.py
+++ b/xclim/testing/tests/test_snow.py
@@ -5,6 +5,14 @@ from xclim import land
 from xclim.core.utils import ValidationError
 
 
+class TestSnowDepth:
+    def test_simple(self, snd_series):
+        snd = snd_series(np.ones(110), start="2001-01-01")
+        out = land.snow_depth(snd, freq="M")
+        assert out.units == "cm"
+        np.testing.assert_array_equal(out, [100, 100, 100, np.nan])
+
+
 class TestSnowCoverDuration:
     def test_simple(self, snd_series):
         snd = snd_series(np.ones(110), start="2001-01-01")