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

Class instance fails if u and v are just lat,long arrays with no other (eg time) dimension #96

Closed adrianjmatthews closed 6 years ago

adrianjmatthews commented 6 years ago

Hi Andrew

I get an error if I try to create ww=VectorWind(u,v)


TypeError Traceback (most recent call last)

in () ----> 1 ww=VectorWind(uu,vv) ~/.conda/envs/py36/lib/python3.6/site-packages/windspharm/iris.py in __init__(self, u, v, rsphere) 94 self._coords = u.dim_coords 95 # Reshape the inputs so they are compatible with pyspharm. ---> 96 u = u.data.reshape(u.shape[:2] + (np.prod(u.shape[2:]),)) 97 v = v.data.reshape(v.shape[:2] + (np.prod(v.shape[2:]),)) 98 # Create a base VectorWind instance to do the computations. TypeError: 'numpy.float64' object cannot be interpreted as an integer The problem is that u and v are 2-D iris cubes. np.prod(u.shape[2:]) returns 1.0 a float, not 1 an integer, which causes the fail. This is because u.shape[2:] is () an empty tuple. It works ok if I use lat-long-time u and v cubes. I have fixed my version of this by modifying the windspharm iris.py with an int built-in, ie np.prod(u.shape[2:]) is changed to int(np.prod(u.shape[2:])) and similarly for v in the next line Is this correct, and can you update the package? Cheers Adrian
ajdawson commented 6 years ago

Pretty sure this is already fixed in the latest release v1.6.0, looks like you are on v1.5?

adrianjmatthews commented 6 years ago

Oops. I thought I had the latest version. Just updated to 1.6.0 and it works ok!

adrianjmatthews commented 6 years ago

Oops. I thought I had the latest version. Just updated to 1.6.0 and it works ok!