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

[python #KWS-403390]: MetPym parse_cf and cross_section query



Hello! Thanks much for reaching out to us.

The `metpy.xarray.parse_cf` method allows you to take xarray datasets that 
contain NetCDF Climate and Forecast (CF) standard metadata, like data 
projections (see: 
http://cfconventions.org/cf-conventions/cf-conventions.html#grid-mappings-and-projections)
 that are often included in data/output distributed via NetCDF throughout the 
field, and pull out that information and make it useable for you in Python. We 
do this by reading in all the provided information we know we can pull from the 
CF standard and creating a cartopy CRS object with that information. So, if you 
know your projection and are already creating it by hand for cartopy to use, 
then you've already done that work. You don't have any CF metadata from which 
to have `parse_cf` create the projection for you. So, if you follow the example 
linked but instead you have created your own `data_crs` (this cartopy Lambert 
Cylindrical CRS you've attached to your xarray dataset) you can use that 
instead of generating it with `par
 se_cf`. This hopefully should get you going in the right direction. If not, or 
if you run into any other transform problems after this, please don't hesitate 
to follow up and let us know! Hope this helps.


All the best,

Drew


> Hi,
> 
> I am still stuck on this and have tried copying the 'crs' from the example
> into my xarray, but cannot get that to work. Any tips to help me get over
> this 'TypeError: 'LambertCylindrical' object is not subscriptable' problem
> would be very much appreciated.
> 
> > Hi,
> >
> > I have been trying to copy the cross section example given here:
> >
> > https://unidata.github.io/MetPy/latest/examples/cross_section.html#sphx-glr-examples-cross-section-py
> >
> > I have my data in a numpy array and write an xarray:
> >
> > ds1 = xr.Dataset({'q': (['time', 'level', 'y', 'x'],  q), 'lat': (['y',
> > 'x'],lat), 'lon': (['y','x'],lon)}, coords={'x': (lon[0,:]), 'y':
> > (lat[:,0]), 'crs':ccrs.LambertCylindrical()})
> > data1 = ds1.metpy.parse_cf().squeeze()
> >
> > However, when I do parse_cf()  above I get the error 'TypeError:
> > 'LambertCylindrical' object is not subscriptable'
> >
> > I have checked my xarray many times and I have set it up in the same way
> > as the example, with x, y and crs as coordinates and the variable (q) and
> > lat and lon as data variables (see below from example):
> >
> > Coordinates:
> >     time                 datetime64[ns] 1987-04-04T18:00:00
> >   * isobaric             (isobaric) float64 1e+03 975.0 950.0 ... 125.0 
> > 100.0
> >   * y                    (y) float64 -3.087e+06 -3.054e+06 ... 7.114e+05
> >   * x                    (x) float64 -3.977e+06 -3.945e+06 ... 5.47e+06
> >     crs                  object Projection: lambert_conformal_conic
> > Data variables:
> >     Temperature          (isobaric, y, x) float32 ...
> >     Lambert_Conformal    |S1 ...
> >     lat                  (y, x) float64 ...
> >     lon                  (y, x) float64 ...
> >     u_wind               (isobaric, y, x) float32 ...
> >     v_wind               (isobaric, y, x) float32 ...
> >     Geopotential_height  (isobaric, y, x) float32 ...
> >     Specific_humidity    (isobaric, y, x) float32 ...
> > Attributes:
> >
> >
> > I am pretty stuck on what could be going wrong here as the projection is
> > set up in the example. Any suggestions you have would be very much
> > appreciated.
> >
> > I have attached a screen shot of the ds1 that I create. Once I get the
> > parse_cf to work hopefully it will be simple to run into the cross section
> > code:
> >
> > cross = cross_section(data1, start, end).set_coords(('lat','lon'))
> 
> 


Ticket Details
===================
Ticket ID: KWS-403390
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.