Skip to content

Implement Jacobian determinant #2356

Open

Description

@sgdecker

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

Activity

  1. jthielen commented on Feb 22, 2022

    @jthielen
    Collaborator

    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

  2. kgoebber commented on Feb 22, 2022

    @kgoebber
    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.

  3. jthielen commented on Feb 23, 2022

    @jthielen
    Collaborator

    @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

  4. kgoebber commented on Feb 23, 2022

    @kgoebber
    Collaborator

    Ah, yes. Good catch.

  5. added 4 commits that reference this issue on Mar 5, 2024
    73484e6
    8928e9f
    77bcb91
    1195d32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: CalcPertains to calculationsGEMPAK ConversionNeeded to replicate GEMPAK functionalityType: FeatureNew functionality

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions