Skip to content

Commit

Permalink
make function unit aware
Browse files Browse the repository at this point in the history
  • Loading branch information
kgoebber committed Jul 22, 2021
1 parent beeed8b commit b375fa3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/metpy/calc/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""Contains a collection of generally useful calculation tools."""
import functools
from operator import itemgetter
import warnings

import numpy as np
from numpy.core.numeric import normalize_axis_index
Expand Down Expand Up @@ -887,6 +888,16 @@ def azimuth_range_to_lat_lon(azimuths, ranges, center_lon, center_lat, geod=None
else:
g = geod

try: # convert range units to meters
ranges = ranges.to('meters').m
except AttributeError: # no units associated
warnings.warn('Range values are not a Pint-Quantity, assuming values are in meters.')
try: # convert azimuth units to degrees
azimuths = azimuths.to('degrees').m
except AttributeError: # no units associated
warnings.warn(
'Azimuth values are not a Pint-Quantity, assuming values are in degrees.'
)
rng2d, az2d = np.meshgrid(ranges, azimuths)
lats = np.full(az2d.shape, center_lat)
lons = np.full(az2d.shape, center_lon)
Expand Down
4 changes: 2 additions & 2 deletions tests/calc/test_calc_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,8 +947,8 @@ def test_azimuth_range_to_lat_lon():

def test_azimuth_range_to_lat_lon_diff_ellps():
"""Test conversion of azimuth and range to lat/lon grid."""
az = [332.2403, 334.6765, 337.2528, 339.73846, 342.26257]
rng = [2125., 64625., 127125., 189625., 252125., 314625.]
az = [332.2403, 334.6765, 337.2528, 339.73846, 342.26257] * units.degrees
rng = [2125., 64625., 127125., 189625., 252125., 314625.] * units.meters
clon = -89.98416666666667
clat = 32.27972222222222
output_lon, output_lat = azimuth_range_to_lat_lon(az, rng, clon, clat, Geod(ellps='WGS84'))
Expand Down

0 comments on commit b375fa3

Please sign in to comment.