ajdawson / windspharm

A Python library for spherical harmonic computations on vector winds.
http://ajdawson.github.io/windspharm
MIT License
82 stars 36 forks source link

windspharm.iris.VectorWind fails with Numpy v1.24 #123

Closed jonseddon closed 1 year ago

jonseddon commented 1 year ago

windspharm.iris.VectorWind fails with Numpy v1.24 because numpy.int has been removed and was deprecated since Numpy v1.20. The following example illustrates this:

import numpy as np
from windspharm.iris import VectorWind
import iris
from iris.fileformats.pp import STASH

def _create_windspeed_cubes():
    """Create 3D cubes of u-wind and v-wind for use in the above test classes."""
    lats = np.arange(-90., 91., 30.)
    lons = np.arange(0., 360., 30.)
    shape = (1, len(lats), len(lons))
    loncrd = iris.coords.DimCoord(lons, standard_name='longitude', units='degrees_east')
    latcrd = iris.coords.DimCoord(lats, standard_name='latitude', units='degrees_north')
    levcrd = iris.coords.DimCoord(850, long_name='pressure', units='hPa')
    uwind = iris.cube.Cube(np.ones(shape), standard_name='x_wind', units='m s-1')
    uwind.add_dim_coord(levcrd, 0)
    uwind.add_dim_coord(latcrd, 1)
    uwind.add_dim_coord(loncrd, 2)
    uwind.attributes['STASH'] = STASH.from_msi('m01s30i201')
    vwind = iris.cube.Cube(np.ones(shape), standard_name='y_wind', units='m s-1')
    vwind.add_dim_coord(levcrd, 0)
    vwind.add_dim_coord(latcrd, 1)
    vwind.add_dim_coord(loncrd, 2)
    vwind.attributes['STASH'] = STASH.from_msi('m01s30i202')
    return iris.cube.CubeList([uwind, vwind])

cubes = _create_windspeed_cubes()

VectorWind(cubes[0], cubes[1])

which gives the error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/conda/envs/after-3-10/lib/python3.10/site-packages/windspharm/iris.py", line 102, in __init__
    u = to3d(u.data)
  File "/conda/envs/after-3-10/lib/python3.10/site-packages/windspharm/_common.py", line 119, in to3d
    new_shape = array.shape[:2] + (np.prod(array.shape[2:], dtype=np.int),)
  File "/conda/envs/after-3-10/lib/python3.10/site-packages/numpy/__init__.py", line 284, in __getattr__
    raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'int'. Did you mean: 'inf'?
jonseddon commented 1 year ago

There are more details about the deprecation and suggested fix in https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations