diff --git a/src/metpy/calc/tools.py b/src/metpy/calc/tools.py index 63867264e43..73292c946f6 100644 --- a/src/metpy/calc/tools.py +++ b/src/metpy/calc/tools.py @@ -1804,7 +1804,7 @@ def _abbreviate_direction(ext_dir_str): @exporter.export -@preprocess_and_wrap() +@preprocess_and_wrap(wrap_like='input_angle') def angle_to_direction(input_angle, full=False, level=3): """Convert the meteorological angle to directional text. @@ -1838,6 +1838,8 @@ def angle_to_direction(input_angle, full=False, level=3): input_angle = input_angle.m except AttributeError: # no units associated origin_units = units.degree + if origin_units == units.dimensionless: # assume if dimensionless is degree + origin_units = units.degree if not hasattr(input_angle, '__len__') or isinstance(input_angle, str): input_angle = [input_angle] diff --git a/tests/calc/test_calc_tools.py b/tests/calc/test_calc_tools.py index 6f92f03d385..5bad684f2f8 100644 --- a/tests/calc/test_calc_tools.py +++ b/tests/calc/test_calc_tools.py @@ -933,7 +933,7 @@ def test_angle_to_direction_level_1(): assert_array_equal(output_dirs, expected_dirs) -def test_angle_to_direction_ndarray(): +def test_angle_to_direction_ndarray_np(): """Test array of angles in degree with a 2d numpy array.""" expected_dirs = np.array([['E', 'W'], ['E', 'W']]) input_angle = np.array([[90, 270], [90, 270]]) @@ -941,6 +941,15 @@ def test_angle_to_direction_ndarray(): assert_array_equal(output_dirs, expected_dirs) +def test_angle_to_direction_ndarray_xr(): + """Test array of angles in degree with a 2d xarray.DataArray.""" + expected_dirs = xr.DataArray(np.array([['E', 'W'], ['E', 'W']])) + input_angle = xr.DataArray(np.array([[90, 270], [90, 270]])) + output_dirs = angle_to_direction(input_angle, level=1) + assert_array_equal(output_dirs, expected_dirs) + assert isinstance(output_dirs, xr.DataArray) + + def test_azimuth_range_to_lat_lon(): """Test conversion of azimuth and range to lat/lon grid.""" az = [332.2403, 334.6765, 337.2528, 339.73846, 342.26257]