From 410165993a2961ef4c2cfd30ced93ae54d30968d Mon Sep 17 00:00:00 2001 From: Ryan May Date: Wed, 8 Nov 2023 14:08:15 -0700 Subject: [PATCH] MNT: Avoid some unit stripped warnings from cross-section --- src/metpy/calc/cross_sections.py | 4 ++-- src/metpy/interpolate/slices.py | 8 ++------ tests/calc/test_indices.py | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/metpy/calc/cross_sections.py b/src/metpy/calc/cross_sections.py index acc8bba28a5..1b33330a389 100644 --- a/src/metpy/calc/cross_sections.py +++ b/src/metpy/calc/cross_sections.py @@ -123,8 +123,8 @@ def unit_vectors_from_cross_section(cross, index='index'): """ x, y = distances_from_cross_section(cross) - dx_di = first_derivative(x, axis=index).values - dy_di = first_derivative(y, axis=index).values + dx_di = first_derivative(x, axis=index).data + dy_di = first_derivative(y, axis=index).data tangent_vector_mag = np.hypot(dx_di, dy_di) unit_tangent_vector = np.vstack([dx_di / tangent_vector_mag, dy_di / tangent_vector_mag]) unit_normal_vector = np.vstack([-dy_di / tangent_vector_mag, dx_di / tangent_vector_mag]) diff --git a/src/metpy/interpolate/slices.py b/src/metpy/interpolate/slices.py index 33f390c5298..b11199565e7 100644 --- a/src/metpy/interpolate/slices.py +++ b/src/metpy/interpolate/slices.py @@ -7,7 +7,6 @@ import xarray as xr from ..package_tools import Exporter -from ..units import is_quantity, units from ..xarray import check_axis exporter = Exporter(globals()) @@ -50,17 +49,14 @@ def interpolate_to_slice(data, points, interp_type='linear'): 'your data has been parsed by MetPy with proper x and y ' 'dimension coordinates.') from None + data = data.metpy.dequantify() data_sliced = data.interp({ x.name: xr.DataArray(points[:, 0], dims='index', attrs=x.attrs), y.name: xr.DataArray(points[:, 1], dims='index', attrs=y.attrs) }, method=interp_type) data_sliced.coords['index'] = range(len(points)) - # Bug in xarray: interp strips units - if is_quantity(data.data) and not is_quantity(data_sliced.data): - data_sliced.data = units.Quantity(data_sliced.data, data.data.units) - - return data_sliced + return data_sliced.metpy.quantify() @exporter.export diff --git a/tests/calc/test_indices.py b/tests/calc/test_indices.py index 77623cbc3ae..4a954d16c00 100644 --- a/tests/calc/test_indices.py +++ b/tests/calc/test_indices.py @@ -158,7 +158,7 @@ def test_weighted_continuous_average_elevated(): def test_precipitable_water_xarray(): """Test precipitable water with xarray input.""" data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC') - press = xr.DataArray(data['pressure'], attrs={'units': str(data['pressure'].units)}) + press = xr.DataArray(data['pressure'].m, attrs={'units': str(data['pressure'].units)}) dewp = xr.DataArray(data['dewpoint'], dims=('press',), coords=(press,)) pw = precipitable_water(press, dewp, top=400 * units.hPa) truth = 22.60430651 * units.millimeters