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

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

This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.


  • Subject: [python #SWP-244115]: metpy cross-section issue
  • Date: Fri, 10 May 2019 17:01:54 -0600

Hi,

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 
here.

Hope this helps,

Ryan

> 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.