pyspharm icon indicating copy to clipboard operation
pyspharm copied to clipboard

TypeError: 'float' object cannot be interpreted as an integer

Open winash12 opened this issue 4 years ago • 4 comments

I have this sample code that I am running using pyspharm and I am getting this error -

` file1 = 'uwnd_200_2020_3_10_00Z.nc' file2 = 'vwnd_200_2020_3_10_00Z.nc'

nc_uwndFile = Dataset(file1,'r')
nc_vwndFile = Dataset(file2,'r')
lats = nc_uwndFile.variables['lat'][:]  # extract/copy the data
lons = nc_uwndFile.variables['lon'][:]


s = Spharmt(len(lons),len(lats), gridtype='regular',
                         rsphere=6.3712e6, legfunc='stored')

u = nc_uwndFile.variables['uwnd'][:]
v = nc_vwndFile.variables['vwnd'][:]
u = u[0,0,:,:]
v = v[0,0,:,:]
print(u.shape,v.shape)

ntruncation = 13
uspectral = s.grdtospec(u,None)
vspectral = s.grdtospec(v,None)
dudx,dudy = s.getgrad(uspectral)
dvdx,dvdy = s.getgrad(vspectral)

` amd I am getting this error -

Where am I going wrong ?

File "testspharm.py", line 29, in main dudx,dudy = s.getgrad(uspectral) File "/usr/local/lib/python3.8/dist-packages/spharm/spharm.py", line 878, in getgrad chispec = numpy.reshape(chispec, ((ntrunc+1)*(ntrunc+2)/2,1)) File "<__array_function__ internals>", line 5, in reshape File "/usr/local/lib/python3.8/dist-packages/numpy-1.19.1-py3.8-linux-x86_64.egg/numpy/core/fromnumeric.py", line 299, in reshape return _wrapfunc(a, 'reshape', newshape, order=order) File "/usr/local/lib/python3.8/dist-packages/numpy-1.19.1-py3.8-linux-x86_64.egg/numpy/core/fromnumeric.py", line 67, in _wrapfunc return _wrapit(obj, method, *args, **kwds) File "/usr/local/lib/python3.8/dist-packages/numpy-1.19.1-py3.8-linux-x86_64.egg/numpy/core/fromnumeric.py", line 44, in _wrapit result = getattr(asarray(obj), method)(*args, **kwds) TypeError: 'float' object cannot be interpreted as an integer

winash12 avatar Oct 06 '20 07:10 winash12

Any update on this ? I tried changing to SHTns but that has this issue - https://bitbucket.org/nschaeff/shtns/issues/38/valueerror-nlat-must-be-even

winash12 avatar Aug 26 '21 03:08 winash12