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

Add custom gradient function #174

Closed
dopplershift opened this issue Jun 30, 2016 · 17 comments
Closed

Add custom gradient function #174

dopplershift opened this issue Jun 30, 2016 · 17 comments
Assignees
Labels
Area: Calc Pertains to calculations Type: Enhancement Enhancement to existing functionality

Comments

@dopplershift
Copy link
Member

It seems np.gradient doesn't support arrays for dx, etc. For a case where we want to compute the geostrophic wind on a lat/lon grid (like GFS), we have a varying dx. Time for our own I guess.

@dopplershift dopplershift added Type: Enhancement Enhancement to existing functionality Area: Calc Pertains to calculations labels Jun 30, 2016
@deeplycloudy
Copy link
Collaborator

A while ago I wrote a 4th order accurate gradient and third order accurate second derivative (along each axis) function. From a quick glance at it, it looks like it might adapt trivially to arrays of dx. I put it in a gist, which you're free to use.

https://gist.github.com/deeplycloudy/1b9fa46d5290314d9be02a5156b48741

@sgdecker
Copy link
Contributor

I believe this issue explains why the geostrophic winds in the example at https://github.com/Unidata/notebook-gallery/blob/master/notebooks/Geostrophic_Wind_Example.ipynb are close to but not exactly parallel to the height contours.

@dopplershift dopplershift modified the milestone: Winter 2017 Mar 10, 2017
@dopplershift dopplershift modified the milestones: Summer 2017, Winter 2017 Apr 18, 2017
@dopplershift
Copy link
Member Author

Move up in priority since numpy 1.12 has broken the ability to pass arrays for dx/dy. We just need to move to our own, likely based on @deeplycloudy 's implementation. (cc @kgoebber )

@deeplycloudy
Copy link
Collaborator

It's mentioned in the comment at the top of the gist, but my implementation should drop in easily, since it was based on the version in numpy. It's worth noting that the implementation extends easily to vectorizing other derivative stencils of various orders of accuracy.

@dopplershift
Copy link
Member Author

I agree, but I can't help but think of this:

xkcd 974

@deeplycloudy
Copy link
Collaborator

I believe that's called Mathematica

@laufers
Copy link

laufers commented Apr 25, 2017 via email

@lesserwhirls
Copy link
Contributor

...a few of us resemble that remark...

@dopplershift dopplershift modified the milestones: 0.6, Fall 2017 Jul 19, 2017
@jrleeman
Copy link
Contributor

@tjwixtrom just hit this in working up some new examples. Will be nice to fix by 0.6 if possible. Probably a decent amount of example/doc updating to go with it.

@dopplershift dopplershift modified the milestones: 0.6, Fall 2017 Aug 2, 2017
@dopplershift dopplershift modified the milestones: 0.6, Fall 2017 Sep 11, 2017
@dopplershift
Copy link
Member Author

Not sure, but numpy/numpy#9408 (for 1.13.2) may restore the variable differences.

@eric-wieser
Copy link

@dopplershift: Passing anything other than 1D arrays was never supported, and computed incorrect results. 1.13.2 just raises an error in those cases instead

@dopplershift
Copy link
Member Author

Good to know, thx.

@sgdecker
Copy link
Contributor

The following reference (especially the first three equations) might have some useful info for computing the gradient (and other quantities that involve the del operator like divergence) properly on non-uniform grids:
http://www1.arl.noaa.gov/documents/reports/cmapf.pdf
Looks like the routines still exist at https://www.arl.noaa.gov/HYSPLIT_cmapf.php as well.

@dopplershift
Copy link
Member Author

Thanks @sgdecker ! We'll have a look.

@dopplershift
Copy link
Member Author

Here's an updated link for the NOAA stuff: https://www.arl.noaa.gov/hysplit/cmapf-mapping-routines/

I think we'll defer on the issues with projected coordinate systems in the short term, but I should get in a PR in a bit that tackles the non-uniform issue.

@dopplershift
Copy link
Member Author

Re-opening to remind us to tackle the coordinate system issues.

@dopplershift
Copy link
Member Author

We can continue to talk about the map projection issues in #893.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Calc Pertains to calculations Type: Enhancement Enhancement to existing functionality
Projects
None yet
Development

No branches or pull requests

7 participants