Repository: Unidata/MetPy

Issue:
Fix unit-handling in azimuth_range_to_lat_lon
`azimuth_range_to_lat_lon` currently says:
https://github.com/Unidata/MetPy/blob/3173ec65de269ed2bcf9d6ef7c2ee79c27c31c13/src/metpy/calc/tools.py#L856-L867

This is problematic because:
1. Contrary to the docs, we don't actually handle non-degrees
2. We suggest `meters`, but really it is *required* to be in meters when passing to PyProj. We're a unit-aware library, the whole point is to be able to help users.

What we should be doing is:
1. Convert to degrees as necessary using Pint for azimuth
2. Make `range` be like azimuth and say e.g. "Must be in meters unless a Quantity". Then convert to meters as possible when sending to PyProj.

An option to consider for 2.0 is to require units, which for some reason isn't being done here.

Discussion:

Patch:
diff --git a/src/metpy/calc/tools.py b/src/metpy/calc/tools.py
index d2544a6af7..19e5fac426 100644
--- a/src/metpy/calc/tools.py
+++ b/src/metpy/calc/tools.py
@@ -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
@@ -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.m_as('meters')
+    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.m_as('degrees')
+    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)


Test patch:
diff --git a/tests/calc/test_calc_tools.py b/tests/calc/test_calc_tools.py
index 17678bdafa..5c12352cf4 100644
--- a/tests/calc/test_calc_tools.py
+++ b/tests/calc/test_calc_tools.py
@@ -920,7 +920,8 @@ def test_azimuth_range_to_lat_lon():
     rng = [2125., 64625., 127125., 189625., 252125., 314625.]
     clon = -89.98416666666667
     clat = 32.27972222222222
-    output_lon, output_lat = azimuth_range_to_lat_lon(az, rng, clon, clat)
+    with pytest.warns(UserWarning, match='not a Pint-Quantity'):
+        output_lon, output_lat = azimuth_range_to_lat_lon(az, rng, clon, clat)
     true_lon = [[-89.9946968, -90.3061798, -90.6211612, -90.9397425, -91.2620282,
                 -91.5881257],
                 [-89.9938369, -90.2799198, -90.5692874, -90.8620385, -91.1582743,
@@ -947,8 +948,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'))