Skip to content

xarray quantify accessor doesn't return a Quantity for a coordinate variable #3260

@deeplycloudy

Description

@deeplycloudy

What went wrong?

I read an xarray dataset, with units correctly attached. The metpy quantify accessor stripped units but did not return a Pint quantity. An extract of sample data, which is derived from a DOE ASR interpolated radiosonde dataset, is attached.

xarray = 2023.8.0, numpy = 1.25.2, pint = 0.22
height_test_data.nc.zip

Operating System

MacOS

Version

1.5.1

Python Version

3.10.12

Code to Reproduce

import xarray as xr
import metpy.units as units
ds = xr.open_dataset('height_test_data.nc')
height_q = ds.height.metpy.quantify()
height_q_good = ds.height * units.units(ds.height.attrs['units'])
print(height_q.metpy.units) # dimensionless
print(height_q_good.metpy.units) # kilometers

Errors, Traceback, and Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: UnitsPertains to unit informationArea: XarrayPertains to xarray integrationType: BugSomething is not working like it should

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions