Skip to content

Commit

Permalink
Improve agreement with GEMPAK
Browse files Browse the repository at this point in the history
* Adjust to change to radians at the last possible time. At least in the
GFS case, this keeps the data exactly representable in floating point
(e.g. 0.5, 0.25 spacing), which lets the math work better, or at least
provide uniform output spacing given uniform input.

* Working in degrees makes everything consistent with our handling of
forward_az in the aftermath of the function. If radians=True, then
forward_az comes out in radians.
  • Loading branch information
dopplershift committed Oct 19, 2022
1 parent d2dd039 commit f052ea2
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/metpy/calc/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,15 +874,11 @@ def nominal_lat_lon_grid_deltas(longitude, latitude, geod=None):
'that are not one dimensional.'
)

dx = units.Quantity(
geod.a * np.diff(longitude.m_as('radian')),
'meter'
)
lat = latitude.m_as('radian')
lon_meridian_diff = np.zeros(len(lat) - 1)
forward_az, _, dy = geod.inv(
lon_meridian_diff, lat[:-1], lon_meridian_diff, lat[1:], radians=True
)
dx = units.Quantity(g.a * np.diff(longitude).m_as('radian'), 'meter')
lat = latitude.m_as('degree')
lon_meridian_diff = np.zeros(len(lat) - 1, dtype=lat.dtype)
forward_az, _, dy = g.inv(lon_meridian_diff, lat[:-1], lon_meridian_diff, lat[1:],
radians=False)
dy[(forward_az < -90.) | (forward_az > 90.)] *= -1
dy = units.Quantity(dy, 'meter')

Expand Down Expand Up @@ -1028,7 +1024,7 @@ def wrapper(f, **kwargs):

def parse_grid_arguments(func):
"""Parse arguments to functions involving derivatives on a grid.
TODO: use this to completely replace add_grid_arguments_from_xarray
"""
# u, v, *, dx=None, dy=None, x_dim=-1, y_dim=-2, longitude=None, latitude=None, crs=None,
Expand Down Expand Up @@ -1148,7 +1144,7 @@ def wrapper(*args, **kwargs):
except:
# Fall back to cartesian calculation if CRS is not provided or invalid
cartesian = True

lat = bound_args.arguments['latitude']
lon = bound_args.arguments['longitude']

Expand Down Expand Up @@ -1524,7 +1520,7 @@ def _vector_derivative(
):
# Determine which derivatives to calculate
derivatives = {
component: None
component: None
for component in ('du/dx', 'du/dy', 'dv/dx', 'dv/dy')
if (return_only is None or component in return_only)
}
Expand Down

0 comments on commit f052ea2

Please sign in to comment.