Skip to content

Commit

Permalink
Merge pull request #166 from cerfacs-globc/maint/cleanup
Browse files Browse the repository at this point in the history
Maint: Make slice_mode typing accept Frequency
  • Loading branch information
bzah authored Apr 28, 2022
2 parents 20da99d + a288fd3 commit 2dd8acc
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 10 deletions.
9 changes: 2 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,14 @@ From sources:
How to use icclim
-----------------

Let's count the number of days above 25ºC, which corresponds to the index ``SU``, from a `tasmax` variable scattered in multiple netcdf files.
Let's count the number of days above 25ºC for each year, which corresponds to the index ``SU``, from a `tasmax` variable scattered in multiple netcdf files.

`SU` is one of the many index that can be computed with icclim. See `the documentation <https://icclim.readthedocs.io/en/latest/explanation/climate_indices.html#icclim-capabilities>`_ to explore what other index you can compute with icclim.

.. code-block:: python
import glob
import icclim
summer_days = icclim.index(
index_name="SU",
in_files=glob.glob(f"netcdf_files/tasmax*.nc"),
out_file="summer_days.nc"
)
summer_days = icclim.su("netcdf_files/tasmax_1990-2100.nc", out_file="summer_days.nc")
For more examples on how to use icclim, see icclim's `How to ... <https://icclim.readthedocs.io/en/latest/how_to/index.html>`_ documentation or
`our notebooks <https://gitlab.com/is-enes-cdi-c4i/notebooks/-/tree/master/>`_.
Expand Down
2 changes: 1 addition & 1 deletion doc/source/dev/release_process.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Release process
python3 -m setup sdist
#. Try to upload on testpypi first.
#. Try to upload on testpypi first. ``twine`` must be installed in your env beforehand.

.. code-block:: sh
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies:
- pytest
- pytest-cov
- setuptools
- twine
# Extra dependencies
- matplotlib
- cartopy
5 changes: 3 additions & 2 deletions icclim/models/frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

from icclim.icclim_exceptions import InvalidIcclimArgumentError

SliceMode = Union[str, List[Union[str, Tuple, int]]]


def seasons_resampler(
month_list: list[int],
Expand Down Expand Up @@ -232,3 +230,6 @@ def _get_frequency_from_list(slice_mode_list: list) -> Frequency:
"The sampling frequency must be one of {'season', 'month'}"
)
return custom_freq


SliceMode = Union[Frequency, str, List[Union[str, Tuple, int]]]
13 changes: 13 additions & 0 deletions icclim/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import icclim
from icclim.models.ecad_indices import EcadIndex
from icclim.models.frequency import Frequency
from icclim.models.index_group import IndexGroup


Expand Down Expand Up @@ -68,6 +69,18 @@ def test_index_SU(self):
)
np.testing.assert_array_equal(0, res.SU)

def test_index_SU__monthy_sampled(self):
res = icclim.index(
indice_name="SU",
in_files=self.data,
out_file=self.OUTPUT_FILE,
slice_mode=Frequency.MONTH,
)
np.testing.assert_array_equal(0, res.SU)
np.testing.assert_array_equal(
len(np.unique(self.TIME_RANGE.year)) * 12, len(res.time)
)

def test_indices_from_DataArray(self):
res = icclim.indices(
index_group=IndexGroup.HEAT, in_files=self.data, out_file=self.OUTPUT_FILE
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ cftime
dask[array]
distributed
fsspec
netCDF4~=1.5.7
numpy
pandas
pytest
Expand Down
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pytest-cov
rechunker~=0.5
setuptools>=49.6.0
sphinx
twine
xarray~=0.19.0
xclim~=0.34.0
zarr

0 comments on commit 2dd8acc

Please sign in to comment.