Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
winash12 opened this issue Oct 6, 2020 · 4 comments
Open

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

winash12 opened this issue Oct 6, 2020 · 4 comments

Comments

@winash12
Copy link

winash12 commented Oct 6, 2020

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
Copy link
Author

winash12 commented Aug 26, 2021

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

@DWesl
Copy link
Contributor

DWesl commented Aug 10, 2024

The issue would be with this line here:

numpy.reshape(chispec, ((ntrunc+1)*(ntrunc+2)/2,1))

In python 3, the normal / division returns a float, even when used with two integers. To have an integer result, one must use the floor division operator //. That is, the following should work:

numpy.reshape(chispec, ((ntrunc+1)*(ntrunc+2)//2,1))

That error in particular looks like issues I found when running the example code recently.

@winash12
Copy link
Author

@DWesl Great work !!!

@winash12
Copy link
Author

@DWesl Would you be interested in collaborating with me on a rewrite of this package ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants