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

Calculating shear and stretch deform using windspharm #110

Open
winash12 opened this issue Jun 27, 2019 · 4 comments
Open

Calculating shear and stretch deform using windspharm #110

winash12 opened this issue Jun 27, 2019 · 4 comments

Comments

@winash12
Copy link

NCL has this functionality - https://www.ncl.ucar.edu/Document/Functions/Contributed/shear_stretch_deform.shtml. Is it possible to calculate shear and stretch deform using windspharm ?

All we need is the vector gradient of the wind and then we can add and subtract the components to get the respective quantities. Is this doable ?

@ajdawson
Copy link
Owner

ajdawson commented Jun 27, 2019

Why not use the gradient method to compute this, this is pretty much exactly what the NCL code does?

vw = VectorWind(u, v, ...)

# standard interface:
dudx, dudy = vw.gradient(u)
dvdx, dvdy = vw.gradient(v)

# metadata interfaces
dudx, dudy = vw.gradient(vw.u())
dvdx, dvdy = vw.gradient(vw.v())

# Compute stretch and shear
shear   = dvdx + dudy
stretch = dudx - dvdy

@winash12
Copy link
Author

@ajdawson Looks great. Very easy and very clear.

What is the difference between the first set of gradients and the metadata ones ?

@ajdawson
Copy link
Owner

ajdawson commented Jun 27, 2019

Nothing except their input arguments. I just realised there was a typo too, I have corrected it.

@winash12 winash12 reopened this Oct 6, 2020
@winash12
Copy link
Author

winash12 commented Oct 6, 2020

Sorry to reopen this nearly 18 months later and I actually never tried this till now and I get this exception -

`def main():

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'][:]

u = nc_uwndFile.variables['uwnd'][:]
v = nc_vwndFile.variables['vwnd'][:]
u = u[0,0,:,:]
v = v[0,0,:,:]
print(u.shape,v.shape)
vw = VectorWind(u,v)
dudx,dudy = vw.gradient(u)
dvdx,dvdy = vw.gradient(v)
sys.exit()`

and I am getting this exception

`raceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/numpy-1.19.1-py3.8-linux-x86_64.egg/numpy/core/fromnumeric.py", line 58, in _wrapfunc
return bound(*args, **kwds)
TypeError: 'float' object cannot be interpreted as an integer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "testspharm.py", line 40, in
main()
File "testspharm.py", line 23, in main
dudx,dudy = vw.gradient(u)
File "/usr/local/lib/python3.8/dist-packages/windspharm-1.7.0-py3.8.egg/windspharm/standard.py", line 607, in gradient
uchi, vchi = self.s.getgrad(chispec)
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`

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