Skip to content

Commit

Permalink
Merge pull request #1164 from PCMDI/feature/1163_numpy-upgrade_lee1043
Browse files Browse the repository at this point in the history
Numpy version update
  • Loading branch information
lee1043 authored Nov 26, 2024
2 parents e99739d + ec022df commit aaa8a86
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 22 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/build_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,18 @@ jobs:
miniforge-version: latest
activate-environment: "pcmdi_metrics_ci"
environment-file: conda-env/ci.yml
channel-priority: strict
channel-priority: flexible
auto-update-conda: true
python-version: ${{ matrix.python-version }}
use-mamba: false
conda-solver: classic

- name: Verify Conda Environment
run: |
conda info
conda list
conda config --show-sources
conda config --show
# Used for refreshing the cache every 24 hours to avoid inconsistencies of package
# versions between the CI pipeline and local installations.
Expand Down Expand Up @@ -128,6 +137,7 @@ jobs:
environment-file: conda-env/dev.yml
channel-priority: strict
auto-update-conda: true
use-mamba: false # Disable libmamba solver

- name: Install pcmdi_metrics
# Source: https://github.com/conda/conda-build/issues/4251#issuecomment-1053460542
Expand Down
18 changes: 9 additions & 9 deletions conda-env/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ dependencies:
# NOTE: If versions are updated, also `additional_dependencies` list for mypy in `.pre-commit-config.yaml`
- python=3.10.10
- pip=23.1.2
- numpy=1.23.5
- cartopy=0.22.0
- matplotlib=3.7.1
- cdms2=3.1.5
- numpy >=2.0.0,<3.0.0
- cartopy >=0.22.0
- matplotlib >=3.7.1
- cdms2 >=3.1.5
- genutil=8.2.1
- cdutil=8.2.1
- cdp=1.7.0
- eofs=1.4.1
- eofs=2.0.0
- seaborn=0.12.2
- enso_metrics=1.1.1
- xcdat>=0.7.0
- enso_metrics=1.1.2
- xcdat=0.7.3
- xmltodict=0.13.0
- setuptools=67.7.2
- netcdf4>=1.6.3
- regionmask=0.9.0
- regionmask=0.12.1
- rasterio>=1.3.6
- shapely=2.0.1
- shapely >=2.0.1
- numdifftools
- nc-time-axis
- colorcet
Expand Down
18 changes: 9 additions & 9 deletions conda-env/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ dependencies:
# NOTE: If versions are updated, also `additional_dependencies` list for mypy in `.pre-commit-config.yaml`
- python=3.10.10
- pip=23.1.2
- numpy=1.23.5
- cartopy=0.22.0
- matplotlib=3.7.1
- cdms2=3.1.5
- numpy >=2.0.0,<3.0.0
- cartopy >=0.22.0
- matplotlib >=3.7.1
- cdms2 >=3.1.5
- genutil=8.2.1
- cdutil=8.2.1
- cdp=1.7.0
- eofs=1.4.1
- eofs=2.0.0
- seaborn=0.12.2
- enso_metrics=1.1.1
- xcdat>=0.7.2
- enso_metrics=1.1.2
- xcdat=0.7.3
- xmltodict=0.13.0
- setuptools=67.7.2
- netcdf4>=1.6.3
- regionmask=0.9.0
- regionmask=0.12.1
- rasterio>=1.3.6
- shapely=2.0.1
- shapely >=2.0.1
- numdifftools
- nc-time-axis
- colorcet
Expand Down
9 changes: 8 additions & 1 deletion pcmdi_metrics/mjo/lib/lib_mjo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@

import numpy as np
import xarray as xr
from packaging.version import Version
from scipy import signal

from pcmdi_metrics.io import base, get_time_key, select_subset
from pcmdi_metrics.utils import create_target_grid, regrid

np_ver = Version(np.__version__)
if np_ver > Version("1.20.0"):
np_float = np.float64
else:
np_float = np.float


def interp2commonGrid(ds, data_var, dlat, dlon=None, debug=False):
if dlon is None:
Expand Down Expand Up @@ -121,7 +128,7 @@ def space_time_spectrum(d_seg_x_ano: xr.Dataset, data_var: str) -> np.ndarray:
C = np.absolute(EE[NTSub // 2 : NTSub, 0 : NL // 2 + 1]) ** 2
D = np.absolute(EE[0 : NTSub // 2 + 1, 0 : NL // 2 + 1]) ** 2
# Define returning array
p = np.zeros((NTSub + 1, NL + 1), np.float)
p = np.zeros((NTSub + 1, NL + 1), np_float)
p[NTSub // 2 :, : NL // 2] = A[:, ::-1]
p[: NTSub // 2, : NL // 2] = B[:, ::-1]
p[NTSub // 2 + 1 :, NL // 2 :] = C[::-1, :]
Expand Down
9 changes: 8 additions & 1 deletion pcmdi_metrics/mjo/lib/mjo_metric_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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

from pcmdi_metrics.io import get_latitude, get_longitude, get_time_key, xcdat_open
from pcmdi_metrics.mjo.lib import (
Expand All @@ -20,6 +21,12 @@
from .debug_chk_plot import debug_chk_plot
from .plot_wavenumber_frequency_power import plot_power

np_ver = Version(np.__version__)
if np_ver > Version("1.20.0"):
np_float = np.float64
else:
np_float = np.float


def mjo_metric_ewr_calculation(
mip,
Expand Down Expand Up @@ -157,7 +164,7 @@ def mjo_metric_ewr_calculation(
# -----------------------------------------------------------------

# Define array for archiving power from each year segment
Power = np.zeros((numYear, NT + 1, NL + 1), np.float)
Power = np.zeros((numYear, NT + 1, NL + 1), np_float)

# Year loop for space-time spectrum calculation
if debug:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def precip_variability_across_timescale(
lon_range = [-180.0, 180.0]
else:
lon_range = [0.0, 360.0]
rgtmp = RegridHoriz(f, var, res, regions_specs, lon_range)
rgtmp = RegridHoriz(f.compute(), var, res, regions_specs, lon_range)
if fshp is not None:
print("Cropping from shapefile")
rgtmp = region_from_file(rgtmp, fshp, attr, feature)
Expand Down

0 comments on commit aaa8a86

Please sign in to comment.