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 #3422

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/userguide/gempak.rst
Original file line number Diff line number Diff line change
Expand Up @@ -493,12 +493,12 @@ blue is uncertain of parity, and white is unevaluated.
<td></td>
</tr>
<tr>
<td>JCBN(S1, S2)</td>
<td>Jacobian determinant</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td class="tg-implemented">JCBN(S1, S2)</td>
<td class="tg-implemented">Jacobian determinant</td>
<td class="tg-implemented"><a href="../api/generated/metpy.calc.jacobian.html#metpy.calc.jacobian">metpy.calc.jacobian</a></td>
<td class="tg-yes">Yes</td>
<td class="tg-yes">Yes</td>
<td class="tg-yes">Yes</td>
</tr>
<tr>
<td class="tg-implemented">KNTS(S)</td>
Expand Down
58 changes: 58 additions & 0 deletions src/metpy/calc/kinematics.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,64 @@
return np.sqrt((dvdx + dudy)**2 + (dudx - dvdy)**2)


@exporter.export
@parse_grid_arguments
@preprocess_and_wrap(wrap_like='u', broadcast=('u', 'v', 'parallel_scale', 'meridional_scale'))
@check_units('[speed]', '[speed]', '[length]', '[length]')
def jacobian(u, v, dx=None, dy=None, x_dim=-1, y_dim=-2, *,
parallel_scale=None, meridional_scale=None):
r"""Calculate the Jacobian determinant of scalar quantities u and v.

Parameters
----------
u : (..., M, N) `xarray.DataArray` or `pint.Quantity`
first scalar quantity (often the x component of the wind)
v : (..., M, N) `xarray.DataArray` or `pint.Quantity`
second scalar quantity (often the y component of the wind)

Returns
-------
(..., M, N) `xarray.DataArray` or `pint.Quantity`
Jacobian Determinant

Other Parameters
----------------
dx : `pint.Quantity`, optional
The grid spacing(s) in the x-direction. If an array, there should be one item less than
the size of `u` along the applicable axis. Optional if `xarray.DataArray` with
latitude/longitude coordinates used as input.
dy : `pint.Quantity`, optional
The grid spacing(s) in the y-direction. If an array, there should be one item less than
the size of `u` along the applicable axis. Optional if `xarray.DataArray` with
latitude/longitude coordinates used as input.
x_dim : int, optional
Axis number of x dimension. Defaults to -1 (implying [..., Y, X] order). Automatically
parsed from input if using `xarray.DataArray`.
y_dim : int, optional
Axis number of y dimension. Defaults to -2 (implying [..., Y, X] order). Automatically
parsed from input if using `xarray.DataArray`.
parallel_scale : `pint.Quantity`, optional
Parallel scale of map projection at data coordinate. Optional if `xarray.DataArray`
with latitude/longitude coordinates and MetPy CRS used as input. Also optional if
longitude, latitude, and crs are given. If otherwise omitted, calculation will be
carried out on a Cartesian, rather than geospatial, grid. Keyword-only argument.
meridional_scale : `pint.Quantity`, optional
Meridional scale of map projection at data coordinate. Optional if `xarray.DataArray`
with latitude/longitude coordinates and MetPy CRS used as input. Also optional if
longitude, latitude, and crs are given. If otherwise omitted, calculation will be
carried out on a Cartesian, rather than geospatial, grid. Keyword-only argument.

See Also
--------
gradient

"""
(dudx, dudy), (dvdx, dvdy) = vector_derivative(

Check warning on line 411 in src/metpy/calc/kinematics.py

View check run for this annotation

Codecov / codecov/patch

src/metpy/calc/kinematics.py#L411

Added line #L411 was not covered by tests
u, v, dx=dx, dy=dy, x_dim=x_dim, y_dim=y_dim, parallel_scale=parallel_scale,
meridional_scale=meridional_scale)
return dudx * dvdy - dudy * dvdx

Check warning on line 414 in src/metpy/calc/kinematics.py

View check run for this annotation

Codecov / codecov/patch

src/metpy/calc/kinematics.py#L414

Added line #L414 was not covered by tests


@exporter.export
@parse_grid_arguments
@preprocess_and_wrap(wrap_like='scalar',
Expand Down
Loading