Giter Club home page Giter Club logo

Comments (4)

ajdawson avatar ajdawson commented on July 28, 2024

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.

winash12 avatar winash12 commented on July 28, 2024

@ajdawson Looks great. Very easy and very clear.

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

from windspharm.

ajdawson avatar ajdawson commented on July 28, 2024

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

from windspharm.

winash12 avatar winash12 commented on July 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.