windspharm
windspharm copied to clipboard
Calculating shear and stretch deform using windspharm
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 ?
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
@ajdawson Looks great. Very easy and very clear.
What is the difference between the first set of gradients and the metadata ones ?
Nothing except their input arguments. I just realised there was a typo too, I have corrected it.
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