Skip to content

Commit

Permalink
Merge branch 'main' into SSI_SGI
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeitsperre authored Feb 21, 2025
2 parents 43d9be3 + d327e60 commit 388dfe9
Show file tree
Hide file tree
Showing 103 changed files with 1,733 additions and 4,136 deletions.
32 changes: 12 additions & 20 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ jobs:
strategy:
matrix:
os: [ 'ubuntu-latest' ]
python-version: [ "3.10" ]
python-version: [ "3.11" ]
testdata-cache: [ '~/.cache/xclim-testdata' ]
steps:
- name: Harden Runner
Expand Down Expand Up @@ -195,11 +195,6 @@ jobs:
matrix:
include:
# Linux builds
- os: 'ubuntu-latest'
testdata-cache: '~/.cache/xclim-testdata'
markers: -m 'not slow'
python-version: "3.10"
tox-env: standard
- os: 'ubuntu-latest'
testdata-cache: '~/.cache/xclim-testdata'
markers: -m 'not slow'
Expand All @@ -210,7 +205,6 @@ jobs:
markers: -m 'not slow'
python-version: "3.12"
tox-env: standard
# Coverage is not yet supported on Python3.13 . See `tox.ini`.
- os: 'ubuntu-latest'
testdata-cache: '~/.cache/xclim-testdata'
markers: -m 'not slow'
Expand All @@ -220,14 +214,14 @@ jobs:
- os: 'windows-latest'
testdata-cache: 'C:\Users\runneradmin\AppData\Local\xclim-testdata\xclim-testdata\Cache'
markers: -m 'not slow'
python-version: "3.10"
tox-env: py310-coverage-prefetch # Test data prefetch is needed for Windows
python-version: "3.12"
tox-env: py312-coverage-prefetch # Test data prefetch is needed for Windows
# macOS builds
- os: 'macos-latest'
testdata-cache: '~/Library/Caches/xclim-testdata'
markers: '' # Slow tests
python-version: "3.11"
tox-env: py311-coverage-extras
tox-env: py311-coverage-extras-lmoments
# Specialized tests
- os: 'ubuntu-latest'
testdata-cache: '~/.cache/xclim-testdata'
Expand All @@ -237,7 +231,7 @@ jobs:
- os: 'ubuntu-latest'
testdata-cache: '~/.cache/xclim-testdata'
markers: '' # No markers for notebooks
python-version: "3.10"
python-version: "3.11"
tox-env: notebooks
- os: 'ubuntu-latest'
testdata-cache: '~/.cache/xclim-testdata'
Expand Down Expand Up @@ -346,7 +340,7 @@ jobs:
strategy:
matrix:
os: [ 'ubuntu-latest' ]
python-version: [ "3.10", "3.12" ]
python-version: [ "3.11", "3.13" ]
testdata-cache: [ '~/.cache/xclim-testdata' ]
defaults:
run:
Expand Down Expand Up @@ -412,14 +406,12 @@ jobs:
continue-on-error: true
- name: Test with pytest
run: |
python -m pytest --numprocesses=logical --durations=10 --cov=xclim --cov-report=term-missing
- name: Report coverage
run: |
coveralls
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_FLAG_NAME: run-{{ matrix.python-version }}-conda
COVERALLS_PARALLEL: true
python -m pytest --numprocesses=logical --durations=10 --cov=xclim --cov-report=lcov
- name: Report Coverage
uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b # v2.3.6
with:
flag-name: run-{{ matrix.python-version }}-conda
parallel: true
- name: Tests measurement
uses: green-coding-solutions/eco-ci-energy-estimation@7ff5628108e21227662ce881f10156eb9deab891 # v4.4
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ htmlcov/
.coverage.*
.cache
nosetests.xml
coverage.lcov
coverage.xml
*.cover
.hypothesis/
Expand Down
29 changes: 12 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ repos:
rev: v3.19.1
hooks:
- id: pyupgrade
args: ['--py310-plus']
args: ['--py311-plus']
exclude: 'src/xclim/core/indicator.py'
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
exclude: '.ipynb|.github/publish-mastodon-template.md'
- id: fix-byte-order-marker
- id: name-tests-test
args: [ '--pytest-test-first' ]
- id: no-commit-to-branch
args: [ '--branch', 'main' ]
- id: check-merge-conflict
- id: check-json
- id: check-toml
- id: check-yaml
Expand All @@ -32,22 +38,20 @@ repos:
hooks:
- id: yamllint
args: [ '--config-file=.yamllint.yaml' ]
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 25.1.0
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.4
rev: v0.9.6
hooks:
- id: ruff
args: [ '--fix', '--show-fixes' ]
- id: ruff-format
exclude: '(src/xclim/indices/__init__.py|docs/installation.rst)'
- repo: https://github.com/pylint-dev/pylint
rev: v3.3.4
hooks:
- id: pylint
args: [ '--rcfile=.pylintrc.toml', '--errors-only', '--jobs=0', '--disable=import-error' ]
- repo: https://github.com/pycqa/flake8
rev: 7.1.1
rev: 7.1.2
hooks:
- id: flake8
additional_dependencies: [ 'flake8-rst-docstrings ']
Expand All @@ -56,14 +60,6 @@ repos:
rev: 'v2.14'
hooks:
- id: vulture
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.9.1
hooks:
- id: nbqa-pyupgrade
args: [ '--py310-plus' ]
additional_dependencies: [ 'pyupgrade==3.19.0' ]
- id: nbqa-black
additional_dependencies: [ 'black==24.10.0' ]
- repo: https://github.com/kynan/nbstripout
rev: 0.8.1
hooks:
Expand Down Expand Up @@ -91,8 +87,7 @@ repos:
hooks:
- id: blackdoc
additional_dependencies: [ 'black==25.1.0' ]
exclude: '(src/xclim/indices/__init__.py|docs/installation.rst)'
- id: blackdoc-autoupdate-black
exclude: '(.py|docs/installation.rst)'
- repo: https://github.com/codespell-project/codespell
rev: v2.4.1
hooks:
Expand Down
7 changes: 4 additions & 3 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ sphinx:
# - pdf

build:
os: ubuntu-22.04
os: ubuntu-24.04
tools:
python: "mambaforge-22.9"
python: "mambaforge-23.11"
jobs:
pre_create_environment:
- sed -i "s/python >=3.11,<3.14/python >=3.11,<3.13/" environment.yml
pre_build:
- sphinx-apidoc -o docs/apidoc/ --private --module-first src/xclim src/xclim/testing/tests src/xclim/indicators src/xclim/indices
- rm docs/apidoc/xclim.rst
Expand All @@ -31,7 +33,6 @@ python:

search:
ranking:

notebooks/*: 2
api_indicators.html: 1
indices.html: -1
Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@
Changelog
=========

v0.56.0 (unreleased)
--------------------
Contributors to this version: Trevor James Smith (:user:`Zeitsperre`).

Breaking changes
^^^^^^^^^^^^^^^^
* `xclim` no longer supports Python 3.10. The minimum required version is now Python 3.11. (:pull:`2082`).
* The minimum versions of several key dependencies have been raised (`numpy` >=1.24.0; `scikit-learn` >=1.2.0; `scipy` >=1.11.0). (:pull:`2082`).

Internal changes
^^^^^^^^^^^^^^^^
* `black`, `isort`, and `nbqa` have all been dropped from the development dependencies. (:issue:`1805`, :pull:`2082`).
* `ruff` has been configured to provide code formatting. (:pull:`2083`):
* The maximum line-length is now 120 characters.
* Docstring formatting is now enabled.
* Line endings in files now must be `Unix`-compatible (`LF`).
* The `blackdoc` pre-commit hook now only examines `.rst` and `.md` files. (:pull:`2083`).

v0.55.0 (2025-02-17)
--------------------
Contributors to this version: Juliette Lavoie (:user:`juliettelavoie`), Trevor James Smith (:user:`Zeitsperre`), Sascha Hofmann (:user:`saschahofmann`), Pascal Bourgault (:user:`aulemahal`), Éric Dupuis (:user:`coxipi`), Baptiste Hamon (:user:`baptistehamon`), Sarah Gammon (:user:`SarahG-579462`).
Expand Down
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,10 @@ clean-test: ## remove test and coverage artifacts
rm -fr .pytest_cache

lint: ## check style with flake8 and black
python -m black --check src/xclim tests
python -m ruff check src/xclim tests
python -m flake8 --config=.flake8 src/xclim tests
python -m vulture src/xclim tests
python -m nbqa black --check docs
python -m blackdoc --check --exclude=src/xclim/indices/__init__.py src/xclim
python -m blackdoc --check docs
python -m blackdoc --check README.rst CHANGELOG.rst CONTRIBUTING.rst docs --exclude=".py"
codespell src/xclim tests docs
python -m numpydoc lint src/xclim/*.py src/xclim/ensembles/*.py src/xclim/indices/*.py src/xclim/indicators/*.py src/xclim/testing/*.py
python -m deptry src
Expand Down
10 changes: 3 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ xclim: Climate services library |logo| |logo-dark| |logo-light|
+----------------------------+-----------------------------------------------------+
| Open Source | |license| |ossf-score| |zenodo| |pyOpenSci| |joss| |
+----------------------------+-----------------------------------------------------+
| Coding Standards | |black| |ruff| |pre-commit| |ossf-bp| |fossa| |
| Coding Standards | |ruff| |pre-commit| |ossf-bp| |fossa| |
+----------------------------+-----------------------------------------------------+
| Development Status | |status| |build| |coveralls| |
+----------------------------+-----------------------------------------------------+
Expand Down Expand Up @@ -68,13 +68,13 @@ Conventions
-----------
In order to provide a coherent interface, `xclim` tries to follow different sets of conventions. In particular, input data should follow the `CF conventions`_ whenever possible for variable attributes. Variable names are usually the ones used in `CMIP6`_, when they exist.

However, xclim will *always* assume the temporal coordinate is named "time". If your data uses another name (for example: "T"), you can rename the variable with:
However, `xclim` will *always* assume the temporal coordinate is named "time". If your data uses another name (for example: "T"), you can rename the variable with:

.. code-block:: python
ds = ds.rename(T="time")
`xclim` code uses the `black`_ formatter, a modified `ruff`_ linting configuration, and (mostly) adheres to the `NumPy docstring`_ style. For more information on coding and development conventions, see the `Contributing Guidelines`_.
`xclim` employs `black`_-like code formatting style, a modified `ruff`_ linting configuration, and (mostly) adheres to the `NumPy docstring`_ style. For more information on coding and development conventions, see the `Contributing Guidelines`_.

.. _black: https://black.readthedocs.io/en/stable/
.. _ruff: https://docs.astral.sh/ruff/
Expand Down Expand Up @@ -191,10 +191,6 @@ This package was created with Cookiecutter_ and the `audreyfeldroy/cookiecutter-
:target: https://app.fossa.com/projects/git%2Bgithub.jparrowsec.cn%2FOuranosinc%2Fxclim?ref=badge_shield
:alt: FOSSA

.. |black| image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/psf/black
:alt: Python Black

.. |logo| image:: https://raw.githubusercontent.com/Ouranosinc/xclim/main/docs/logos/xclim-logo-small-light.png
:target: https://github.com/Ouranosinc/xclim
:alt: Xclim
Expand Down
4 changes: 1 addition & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,7 @@ class XCStyle(AlphaStyle):

# General information about the project.
project = "xclim"
copyright = (
f"2018-{datetime.datetime.now().year}, Ouranos Inc., Travis Logan, and contributors"
)
copyright = f"2018-{datetime.datetime.now().year}, Ouranos Inc., Travis Logan, and contributors"
author = "xclim Project Development Team"

# The version info for the project you're documenting, acts as replacement
Expand Down
8 changes: 2 additions & 6 deletions docs/notebooks/analogs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@
"metadata": {},
"outputs": [],
"source": [
"results = analog.spatial_analogs(\n",
" sim[[\"tg_mean\"]], obs[[\"tg_mean\"]], method=\"seuclidean\"\n",
")\n",
"results = analog.spatial_analogs(sim[[\"tg_mean\"]], obs[[\"tg_mean\"]], method=\"seuclidean\")\n",
"\n",
"results.plot()\n",
"plt.plot(sim.lon, sim.lat, \"ro\", label=\"Target\")\n",
Expand Down Expand Up @@ -169,9 +167,7 @@
"metadata": {},
"outputs": [],
"source": [
"results = analog.spatial_analogs(\n",
" sim[[\"tg_mean\"]], obs[[\"tg_mean\"]], method=\"zech_aslan\"\n",
")\n",
"results = analog.spatial_analogs(sim[[\"tg_mean\"]], obs[[\"tg_mean\"]], method=\"zech_aslan\")\n",
"\n",
"results.plot(center=False)\n",
"plt.plot(sim.lon, sim.lat, \"ro\", label=\"Target\")\n",
Expand Down
8 changes: 2 additions & 6 deletions docs/notebooks/benchmarks/sdba_quantile.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,15 @@
"for use_fnq in [True, False]:\n",
" sdba.nbutils.USE_FASTNANQUANTILE = use_fnq\n",
" # heat-up the jit\n",
" sdba.nbutils.quantile(\n",
" xr.DataArray(np.array([0, 1.5])), dim=\"dim_0\", q=np.array([0.5])\n",
" )\n",
" sdba.nbutils.quantile(xr.DataArray(np.array([0, 1.5])), dim=\"dim_0\", q=np.array([0.5]))\n",
" for size in np.arange(250, 2000 + 250, 250):\n",
" da = tx.isel(time=slice(0, size))\n",
" t0 = time.time()\n",
" for _i in range(num_tests):\n",
" sdba.nbutils.quantile(da, **kws).compute()\n",
" timed[use_fnq].append([size, time.time() - t0])\n",
"\n",
"for k, lab in zip(\n",
" [True, False], [\"xclim.core.utils.nan_quantile\", \"fastnanquantile\"], strict=False\n",
"):\n",
"for k, lab in zip([True, False], [\"xclim.core.utils.nan_quantile\", \"fastnanquantile\"], strict=False):\n",
" arr = np.array(timed[k])\n",
" plt.plot(arr[:, 0], arr[:, 1] / num_tests, label=lab)\n",
"plt.legend()\n",
Expand Down
27 changes: 7 additions & 20 deletions docs/notebooks/customize.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@
"metadata": {},
"outputs": [],
"source": [
"tasmax = (\n",
" xr.tutorial.load_dataset(\"air_temperature\")\n",
" .air.resample(time=\"D\")\n",
" .max(keep_attrs=True)\n",
")\n",
"tasmax = xr.tutorial.load_dataset(\"air_temperature\").air.resample(time=\"D\").max(keep_attrs=True)\n",
"tasmax = tasmax.where(tasmax.time.dt.day % 10 != 0)"
]
},
Expand Down Expand Up @@ -137,9 +133,7 @@
"outputs": [],
"source": [
"with xclim.set_options(check_missing=\"wmo\"):\n",
" tx_mean = xclim.atmos.tx_mean(\n",
" tasmax=tasmax, freq=\"MS\"\n",
" ) # compute monthly max tasmax\n",
" tx_mean = xclim.atmos.tx_mean(tasmax=tasmax, freq=\"MS\") # compute monthly max tasmax\n",
"tx_mean.sel(time=\"2013\", lat=75, lon=200)"
]
},
Expand All @@ -165,7 +159,7 @@
"\n",
"To add additional arguments, one should override the `__init__` (receiving those arguments) and the `validate` static method, which validates them. The options are then stored in the `options` property of the instance. See example below and the docstrings in the module.\n",
"\n",
"When registering the class with the `xclim.core.checks.register_missing_method` decorator, the keyword arguments will be registered as options for the missing method. "
"When registering the class with the `xclim.core.checks.register_missing_method` decorator, the keyword arguments will be registered as options for the missing method."
]
},
{
Expand All @@ -186,12 +180,9 @@
" super().__init__(max_n=max_n)\n",
"\n",
" def is_missing(self, valid, count, freq):\n",
" \"\"\"Return a boolean mask where True values are for elements that are considered missing and masked on the output.\"\"\"\n",
" \"\"\"Return a boolean mask for elements that are considered missing and masked on the output.\"\"\"\n",
" null = ~valid\n",
" return (\n",
" null.resample(time=freq).map(longest_run, dim=\"time\")\n",
" >= self.options[\"max_n\"]\n",
" )\n",
" return null.resample(time=freq).map(longest_run, dim=\"time\") >= self.options[\"max_n\"]\n",
"\n",
" @staticmethod\n",
" def validate(max_n):\n",
Expand All @@ -212,12 +203,8 @@
"metadata": {},
"outputs": [],
"source": [
"with xclim.set_options(\n",
" check_missing=\"consecutive\", missing_options={\"consecutive\": {\"max_n\": 2}}\n",
"):\n",
" tx_mean = xclim.atmos.tx_mean(\n",
" tasmax=tasmax, freq=\"MS\"\n",
" ) # compute monthly max tasmax\n",
"with xclim.set_options(check_missing=\"consecutive\", missing_options={\"consecutive\": {\"max_n\": 2}}):\n",
" tx_mean = xclim.atmos.tx_mean(tasmax=tasmax, freq=\"MS\") # compute monthly max tasmax\n",
"tx_mean.sel(time=\"2013\", lat=75, lon=200)"
]
},
Expand Down
Loading

0 comments on commit 388dfe9

Please sign in to comment.