Comments (4)
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
from windspharm.
@ajdawson Looks great. Very easy and very clear.
What is the difference between the first set of gradients and the metadata ones ?
from windspharm.
Nothing except their input arguments. I just realised there was a typo too, I have corrected it.
from windspharm.
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`
from windspharm.
Related Issues (20)
- Conda Install Packages Not Found HOT 3
- Enhancement - including APIs for adding filters HOT 1
- Curious issue creating WindVector from 2D arrays HOT 2
- divergence is not right? HOT 4
- take divergence and vorticity as input HOT 1
- Issue attempting to import Windspharm in script HOT 2
- Importing JRA-55 files with windspharm
- Problem with computing vorticity of NWP model output
- ValueError: Cube 'U velocity' must contain a single 1D x coordinate. HOT 1
- Typo in windspharm.xarray docs
- windspharm future
- prep_data occur TypeError: unhashable type: 'list' HOT 1
- Possible issue with windspharm package's calculations of irrotational winds
- installation on Apple silicon HOT 2
- windspharm.iris.VectorWind fails with Numpy v1.24 HOT 1
- use windspharm on a Mercator grid? HOT 1
- numpy.float64 object cannot be interpreted as an index HOT 1
- Class instance fails if u and v are just lat,long arrays with no other (eg time) dimension HOT 3
- Memory conservation: legfunc kwarg HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from windspharm.