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

[python #KMV-811594]: Absolute momentum calculation problem(metpy)



Greetings!

So the problem is that the absolute momentum code wants some additional 
coordinate information generated by MetPy's cross-section code. I'm guessing 
you wrote your own because you could not get MetPy's to work. What you need to 
get it to work is add a call to `parse_cf()`, which triggers MetPy to do some 
parsing/interpretation of the CF metadata in the file. If you add this line 
right after you call `xr.open_dataset()`:

    data = data.metpy.parse_cf()

I get your code to run correctly. This is shown, though it's not obvious, in 
the cross-section example in the MetPy documentation:

https://unidata.github.io/MetPy/latest/examples/cross_section.html#sphx-glr-examples-cross-section-py

Hope this helps,

Ryan

> Here is the python code. I use cfgrib to read data into xarray and do the
> cross section by xarray.
> The data is from GFS FTP:
> https://nomads.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/gfs.2019051306/gfs.t06z.pgrb2.0p25.f000
> Attached File is python code.
> Thank you.
> 
> Unidata Python Support <address@hidden> ? 2019?5?11? ??
> ??7:27???
> 
> > Hi,
> >
> > Apologies for the delayed response. Did you ever manage to work around the
> > problem?
> >
> > If not can you send me your code and the data file (or point me to where
> > you got it)? The cross-section code assumes it can identify the x and y
> > coordinates, so it's likely some missing metadata.
> >
> > Ryan
> >
> > > I use the advanced interpolation of xarray to calculate
> > cross-section,and I
> > > put the cross section U,V into metpy.calc.absolute_momentum(u_wind,
> > v_wind,
> > > index='index'),but it doesn't work.
> > >
> > > U V array is geostrophic wind.
> > >
> > > The ERROR message:
> > >
> > > File "F:\Anaconda3\lib\site-packages\metpy\calc\cross_sections.py", line
> > > 125,
> > > in unit_vectors_from_cross_section
> > > x, y = distances_from_cross_section(cross)
> > > File "F:\Anaconda3\lib\site-packages\metpy\calc\cross_sections.py", line
> > > 36, i
> > > n distances_from_cross_section
> > > if (CFConventionHandler.check_axis(cross.metpy.x, 'lon')
> > > File "F:\Anaconda3\lib\site-packages\metpy\xarray.py", line 100, in x
> > > return self._axis('x')
> > > File "F:\Anaconda3\lib\site-packages\metpy\xarray.py", line 77, in _axis
> > > raise AttributeError(axis + ' attribute is not available.')
> > > AttributeError: x attribute is not available.
> >
> >
> > Ticket Details
> > ===================
> > Ticket ID: KMV-811594
> > 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.
> >
> >
> >
> 
> 

Ticket Details
===================
Ticket ID: KMV-811594
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.