You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When pulling data for GFS, the only direction coordinates that come through are for lon/lat and have no corresponding x, y coordinate values. The following code will reproduce the Attribute error AttributeError: x attribute is not available. I've attempted to create and x and y variable, but have not been able to unlock the magic. This error would also likely persist for NCEP/NCAR reanalysis data as that is a global lat/lon base. Currently, the metpy.parse_cf() does not generate a coordinate attribute since the crs is labelled longitude_latitude. Although interestingly it does not raise an error at that segment of the code, which directly precedes where this error occurs.
? Based on testing this out quick myself, it appears that the coordinates are being parsed correctly (see the axis argument on data['lon']), but the dataset contains non-coordinate variables that are not on the lat/lon grid (like data['sigma_layer_bounds']), and so, the cross section cannot be taken on the whole dataset.
Ah! Okay - I think I'm getting it now. Definitely need to add some further examples for Cross Section stuff. I was able to get it from both a single parameter as @jthielen suggested, and also by creating a new xarray Dataset that contains a small subset of the data available from the original file.
I think some further examples would be useful as well (I have some/will have more for the AMS poster on cross sections). Where would be a good location for those once they are ready?
Also, with this sort of problem specifically (supplying a dataset that has some variables without sufficient coordinates), should we be giving a more informative error, or is there some other expected behavior?
It seems this came up again in #2939. I looked at the error message changes made in this work, but @jthielen comment above here:
the dataset contains non-coordinate variables that are not on the lat/lon grid
still wasn't obvious to me from the error messages raised.
To answer this question raised above also by @jthielen:
Also, with this sort of problem specifically (supplying a dataset that has some variables without sufficient coordinates), should we be giving a more informative error, or is there some other expected behavior?
Since cross_section() requires a DataArray or Dataset, we could make it more explicit for users that it's useful to define a list of variables they would like a cross_section of rather than passing the whole Xarray object:
data = xr.open_dataset(get_test_data('narr_example.nc', False))
data = data.metpy.parse_cf().squeeze()
cross_section_vars = ['isobaric','Temperature','Specific_humidity','u_wind','v_wind']
cross_section = cross_section(data[cross_section_vars], start, end).set_coords(('lat','lon'))
So the question is whether we can do a better check here:
try:
crs_data=data.metpy.cartopy_crsifisinstance(data,xr.core.dataarray.DataArray):
x=data.metpy.xelse:
forvarindata.data_vars:
x=data[var].metpy.xexceptAttributeError:
raiseValueError('Data missing required coordinate information. Verify that ''your data have been parsed by MetPy with proper x and y ''dimension coordinates and added crs coordinate of the ''correct projection for each variable.')
I am happy to convert to issue and open a PR to add this if it seems useful.
Activity
jthielen commentedon Oct 1, 2018
@kgoebber Would you be able to try taking the cross section along a single, known 3D field, such as
? Based on testing this out quick myself, it appears that the coordinates are being parsed correctly (see the
axisargument ondata['lon']), but the dataset contains non-coordinate variables that are not on the lat/lon grid (likedata['sigma_layer_bounds']), and so, the cross section cannot be taken on the whole dataset.kgoebber commentedon Oct 2, 2018
Ah! Okay - I think I'm getting it now. Definitely need to add some further examples for Cross Section stuff. I was able to get it from both a single parameter as @jthielen suggested, and also by creating a new xarray Dataset that contains a small subset of the data available from the original file.
jthielen commentedon Oct 2, 2018
I think some further examples would be useful as well (I have some/will have more for the AMS poster on cross sections). Where would be a good location for those once they are ready?
Also, with this sort of problem specifically (supplying a dataset that has some variables without sufficient coordinates), should we be giving a more informative error, or is there some other expected behavior?
jrleeman commentedon Oct 2, 2018
I'd think examples here and/or the gallery would probably be best. I think I'd also vote for a more useful error message.
Make necessary coordinate information for cross sections clearer
parent cf7d532
DanielAdriaansen commentedon Mar 8, 2023
It seems this came up again in #2939. I looked at the error message changes made in this work, but @jthielen comment above here:
To answer this question raised above also by @jthielen:
I think that the more informative error is the way to go here, maybe combined with some tweaks to the existing
cross_section()example here: https://unidata.github.io/MetPy/latest/examples/cross_section.html#sphx-glr-examples-cross-section-py?Since
cross_section()requires aDataArrayorDataset, we could make it more explicit for users that it's useful to define a list of variables they would like a cross_section of rather than passing the whole Xarray object:So the question is whether we can do a better check here:
MetPy/metpy/interpolate/slices.py
Lines 156 to 158 in 3a14af1
Maybe:
I am happy to convert to issue and open a PR to add this if it seems useful.