[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[python #SWP-244115]: metpy cross-section issue


So the xarray machinery in MetPy is expecting netCDF compliant metadata when 
accessing the unit attributes, so strings, not a pint object.

So when creating the Dataset, you should do:

ds2 = xr.Dataset({'potential temperature': (['vertical', 'y', 'x'], th_iso, 
{'units': str(th_iso.units)}),
                                'u wind': (['vertical', 'y', 'x'], u_iso, 
{'units': str(u_iso.units)}), \
                                'v wind': (['vertical', 'y', 'x'], v_iso, 
{'units': str(v_iso.units)}), \
                                'lon': (['y', 'x'], lons, {'units': 
'degrees_east'}), \
                                'lat': (['y', 'x'], lats, {'units': 
'degrees_north'})}, \
                                coords={'vertical': (['vertical'], plevs, 
{'units': str(plevs.units)}), \
                                'y': (['y'], y, {'units': 'm'}), \
                                'x': (['x'], x, {'units': 'm'})})

I think it will make sense for MetPy to eventually have something that 
simplifies this vastly overcomplicated process, but you're just ahead of us 

Hope this helps,


> I am trying to set up WRF data in xarray so that I can create a cross-section 
> with metpy. I followed the example in Issue 1004 to add projection 
> information into my dataset. However, I am getting the following error when I 
> call parse_cf:
> AttributeError: 'Unit' object has no attribute 'replace'
> Is this a metpy bug, or am I doing something wrong? Attached is the code that 
> I currently have.

Ticket Details
Ticket ID: SWP-244115
Department: Support Python
Priority: Low
Status: Closed
NOTE: All email exchanges with Unidata User Support are recorded in the Unidata 
inquiry tracking system and then made publicly available through the web.  If 
you do not want to have your interactions made available in this way, you must 
let us know in each email you send to us.