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

Implement Jacobian determinant #2356

Open
sgdecker opened this issue Feb 22, 2022 · 4 comments · May be fixed by #3422
Open

Implement Jacobian determinant #2356

sgdecker opened this issue Feb 22, 2022 · 4 comments · May be fixed by #3422
Labels
Area: Calc Pertains to calculations GEMPAK Conversion Needed to replicate GEMPAK functionality Type: Feature New functionality

Comments

@sgdecker
Copy link
Contributor

What should we add?

GEMPAK provides a JCBN function, so to support the transition to MetPy, it would be good to provide a direct equivalent. The GEMPAK code indicates:

 * This subroutine computes the Jacobian determinant of two scalar	*
 * grids:								*
 *									*
 *     JCBN ( S1, S2 ) = DDX(S1) * DDY(S2) - DDY(S1) * DDX(S2)		*
 *									*
 * Map scale factors are included implicitly.				*

Looks like a pretty easy thing to implement (famous last words!)

Reference

No response

@sgdecker sgdecker added the Type: Feature New functionality label Feb 22, 2022
@jthielen
Copy link
Collaborator

jthielen commented Feb 22, 2022

To have "map scale factors [...] included implicitly," taking inspiration from #1389 (comment), I think this could be implemented something like

def jacobian(field_0, field_1):
    grad_field_1_y, grad_field_1_x = gradient(field_1, axes=('y', 'x'))
    return vorticity(field_0 * grad_field_1_x, field_0 * grad_field_1_y)

Since

image

@jthielen jthielen added Area: Calc Pertains to calculations GEMPAK Conversion Needed to replicate GEMPAK functionality labels Feb 22, 2022
@kgoebber
Copy link
Collaborator

Our current implementation of vorticity won't work with @jthielen suggestion since we check for units of speed in a decorator with the function. Doing two gradient calls doesn't seem like it would be too much with a function like

def jacobian(field_0, field_1):
    grad_field_1_y, grad_field_1_x = gradient(field_1, axes=('y', 'x'))
    grad_field_0_y, grad_field_0_x = gradient(field_0, axes=('y', 'x'))
    return grad_field_0_x * grad_field_1_y - grad_field_0_y * grad_field_1_x

Otherwise, we could develop a more generic curl function that might help both vorticity and this calculation.

@jthielen
Copy link
Collaborator

jthielen commented Feb 23, 2022

@kgoebber That approach was my first thought, but I avoided it because my prior impression from #893 was that scalar gradients (as used there) wouldn't have any scale factor corrections, and so this in turn would lack them, compared to the curl-based approach which would.

However, this mismatch between formulations that should otherwise be equivalent worried me a bit, so I went back to https://en.wikipedia.org/wiki/Orthogonal_coordinates and the implementations in #893 to figure out the proper/expected behavior. Long story short, I'm pretty sure we need to apply scale factor corrections in gradient:

map factor gradient 2D

so that the Jacobian (via either curl of product with gradient or cross product of gradients, the former results in a lot of cancellations so the latter is probably better computationally) ends up as:

jacobian of 2D fields with map factors

@kgoebber
Copy link
Collaborator

Ah, yes. Good catch.

sgdecker added a commit to sgdecker/MetPy that referenced this issue Mar 5, 2024
Closes Unidata#2356 as it implements an equivalent to GEMPAK's JCBN
function.  The approach is modeled on the deformation calculations.
@sgdecker sgdecker linked a pull request Mar 5, 2024 that will close this issue
3 tasks
sgdecker added a commit to sgdecker/MetPy that referenced this issue Mar 5, 2024
Closes Unidata#2356 as it implements an equivalent to GEMPAK's JCBN
function.  The approach is modeled on the deformation calculations.
sgdecker added a commit to sgdecker/MetPy that referenced this issue Mar 5, 2024
Closes Unidata#2356 as it implements an equivalent to GEMPAK's JCBN
function.  The approach is modeled on the deformation calculations.
sgdecker added a commit to sgdecker/MetPy that referenced this issue Mar 5, 2024
Closes Unidata#2356 as it implements an equivalent to GEMPAK's JCBN
function.  The approach is modeled on the deformation calculations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Calc Pertains to calculations GEMPAK Conversion Needed to replicate GEMPAK functionality Type: Feature New functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants