Skip to content

Commit

Permalink
Merge pull request #861 from pangeo-data/fix-esmf
Browse files Browse the repository at this point in the history
Pin importlib-metadata, raise numpy to v1.25, synchronize dependencies
  • Loading branch information
Zeitsperre authored Jul 4, 2024
2 parents 6a8c8cc + 2a4203e commit 56133d2
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ repos:
rev: v0.3.9
hooks:
- id: blackdoc
additional_dependencies: [ 'black==23.10.1' ]
additional_dependencies: [ 'black==24.4.2' ]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.1
Expand All @@ -55,7 +55,7 @@ repos:
types-pytz,
typing-extensions,
# Dependencies that are typed
numpy,
numpy
]

- repo: https://github.com/python-jsonschema/check-jsonschema
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Internals/Minor Fixes
---------------------
- Fixed some issues with the documentation build to address rendering errors and reduce the number of warnings on ReadTheDocs. (pr:`843`) `Trevor James Smith`_
- Fixed some issues with the typing hints of classes functions. (pr:`850`) `Trevor James Smith`_
- Fixed several issues with incompatible dependency configurations in the CI and addressed a few deprecations. (pr:`861`) `Trevor James Smith`_

climpred v2.4.0 (2023-11-09)
============================
Expand Down
13 changes: 7 additions & 6 deletions ci/requirements/climpred-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ channels:
- conda-forge
- nodefaults
dependencies:
- python >=3.9,<3.12
- python >=3.9,<3.13
# Documentation
- myst-nb
- nbstripout
Expand All @@ -23,13 +23,13 @@ dependencies:
# Miscellaneous
- cftime >=1.5.0
# Numerics
- numpy
- numpy >=1.25.0
- pandas
- scipy
- xarray
- xarray >=2022.6.0
# Package Management
- asv
- black==19.10b0
- black ==24.4.2
- coveralls
- flake8
- isort
Expand All @@ -46,13 +46,14 @@ dependencies:
- dask-core
- numba
# Regridding
- esmpy=*=mpi* # Ensures MPI works with version of esmpy.
- esmpy =*=mpi* # Ensures MPI works with version of esmpy.
- importlib-metadata <8.0.0 # Pin needed for esmpy compatibility. See: https://github.com/pangeo-data/xESMF/issues/374
- xesmf
# Statistics
- bias_correction
- eofs
- esmtools >=1.1.3
- xclim >=0.30.0
- xclim >=0.46.0
- xrft
- xskillscore >=0.0.20
# Visualization
Expand Down
4 changes: 3 additions & 1 deletion ci/requirements/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ dependencies:
- tqdm
# optionals
- bias_correction
- esmpy=*=mpi* # Ensures MPI works with version of esmpy.
- esmpy =*=mpi* # Ensures MPI works with version of esmpy.
- esmtools
- importlib-metadata <8.0.0 # Pin needed for esmpy compatibility. See: https://github.com/pangeo-data/xESMF/issues/374
- nc-time-axis >=1.4.0
- numba >=0.52
- numpy >=1.25.0
- xclim
- xesmf
- xrft
10 changes: 6 additions & 4 deletions ci/requirements/maximum-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ dependencies:
- coveralls
- dask-core
- eofs
- esmpy=*=mpi* # Ensures MPI works with version of esmpy.
- esmpy =*=mpi* # Ensures MPI works with version of esmpy.
- h5netcdf
- importlib-metadata <8.0.0 # Pin needed for esmpy compatibility. See: https://github.com/pangeo-data/xESMF/issues/374
- matplotlib-base
- nc-time-axis >=1.4.0
- h5netcdf
- numpy >=1.25.0
- pip
- pooch
- pytest<8
- pytest <8.0.0
- pytest-cov
- pytest-lazy-fixture
- pytest-xdist
- scipy
- tqdm
- xarray >=2022.6.0
- xclim >=0.46
- xarray
- xesmf
- xrft
- xskillscore >=0.0.18
7 changes: 4 additions & 3 deletions ci/requirements/minimum-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ dependencies:
- coveralls
- dask-core
- h5netcdf
- numpy >=1.25.0
- pip
- pooch
- pytest<8
- pytest <8.0.0
- pytest-cov
- pytest-lazy-fixture
- pytest-xdist
- scipy
- xarray
- xskillscore >=0.0.18
- tqdm
- xarray >=0.19.0
- xskillscore >=0.0.18
8 changes: 4 additions & 4 deletions climpred/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,20 +422,20 @@ def _chunk_before_resample_iterations_idx(
if isinstance(chunking_dims, str):
chunking_dims = [chunking_dims]
# size of CLIMPRED_DIMS
climpred_dim_chunksize = 8 * np.product(
climpred_dim_chunksize = 8 * np.prod(
np.array([ds[d].size for d in CLIMPRED_DIMS if d in ds.dims])
)
# remaining blocksize for remaining dims considering iteration
spatial_dim_blocksize = optimal_blocksize / (climpred_dim_chunksize * iterations)
# size of remaining dims
chunking_dims_size = np.product(
chunking_dims_size = np.prod(
np.array([ds[d].size for d in ds.dims if d not in CLIMPRED_DIMS])
) # ds.lat.size*ds.lon.size
# chunks needed to get to optimal blocksize
chunks_needed = chunking_dims_size / spatial_dim_blocksize
# get size clon, clat for spatial chunks
cdim = [1 for i in chunking_dims]
nchunks = np.product(cdim)
nchunks = np.prod(cdim)
stepsize = 1
counter = 0
while nchunks < chunks_needed:
Expand All @@ -444,7 +444,7 @@ def _chunk_before_resample_iterations_idx(
if c <= ds[d].size:
c = c + stepsize
cdim[i] = c
nchunks = np.product(cdim)
nchunks = np.prod(cdim)
counter += 1
if counter == 100:
break
Expand Down
8 changes: 4 additions & 4 deletions climpred/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,16 +908,16 @@ def remove_seasonality(
>>> HindcastEnsemble.remove_seasonality(seasonality="month")
<climpred.HindcastEnsemble>
Initialized:
SST (init, lead, member) float64 -0.2349 -0.216 ... 0.6476 0.6433
SST (init, lead, member) float64 -0.2392 -0.2203 ... 0.618 0.6136
Uninitialized:
SST (time, member) float64 -0.1789 0.005732 -0.257 ... 0.4359 0.4154
SST (time, member) float64 -0.1969 -0.01221 -0.275 ... 0.4179 0.3974
Observations:
SST (time) float32 -0.3739 -0.3248 -0.1575 ... 0.2757 0.3736 0.4778
SST (time) float32 -0.4015 -0.3524 -0.1851 ... 0.2481 0.346 0.4502
"""

def _remove_seasonality(ds, initialized_dim="init", seasonality=None):
"""Remove the seasonal cycle from the data."""
if ds is {}:
if ds == {}:
return {}
if seasonality is None:
seasonality = OPTIONS["seasonality"]
Expand Down
9 changes: 9 additions & 0 deletions climpred/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import warnings

import numpy as np
import pytest
import xarray as xr
from packaging.version import Version

import climpred
from climpred import HindcastEnsemble, PerfectModelEnsemble
Expand Down Expand Up @@ -319,6 +322,12 @@ def hindcast_S2S_Germany():
def hindcast_NMME_Nino34():
"""NMME hindcasts with monthly leads and monthly inits and related IOv2
observations for SST of the Nino34 region."""
if Version(np.__version__) >= Version("2.0.0") and Version(
xr.__version__
) <= Version("2024.6.0"):
warnings.warn("Skipping test due to incompatible numpy and xarray versions.")
pytest.skip("Changes in numpy>=2.0.0 break xarray<=2024.6.0.")

init = load_dataset("NMME_hindcast_Nino34_sst")
obs = load_dataset("NMME_OIv2_Nino34_sst")
init["sst"].attrs["units"] = "C"
Expand Down
1 change: 1 addition & 0 deletions climpred/tests/test_bias_removal.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ def test_remove_bias_compare_scaling_and_mean(hindcast_recon_1d_mm):

def test_remove_bias_errors(hindcast_NMME_Nino34):
"""Test remove_bias error messaging."""

how = "additive_mean"
he = (
hindcast_NMME_Nino34.sel(lead=[4, 5])
Expand Down
8 changes: 6 additions & 2 deletions climpred/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ def convert_init_lead_to_valid_time_lead(
[skill.sel(lead=lead).swap_dims({"init": "valid_time"}) for lead in skill.lead],
"lead",
)
return add_init_from_time_lead(swapped.drop("init")).dropna("valid_time", how="all")
return add_init_from_time_lead(swapped.drop_vars("init")).dropna(
"valid_time", how="all"
)


def convert_valid_time_lead_to_init_lead(
Expand Down Expand Up @@ -343,7 +345,9 @@ def convert_valid_time_lead_to_init_lead(
[skill.sel(lead=lead).swap_dims({"valid_time": "init"}) for lead in skill.lead],
"lead",
)
return add_time_from_init_lead(swapped.drop("valid_time")).dropna("init", how="all")
return add_time_from_init_lead(swapped.drop_vars("valid_time")).dropna(
"init", how="all"
)


def find_start_dates_for_given_init(control, single_init):
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cf_xarray>=0.6.0
cftime>=1.5.0
dask>=2021.10.0
numpy
numpy>=1.25.0
packaging
pooch>=1.4
xarray
xarray>=0.19.0
xskillscore>=0.0.20

0 comments on commit 56133d2

Please sign in to comment.