Problem with cross section #2939
-
Hiii.. fn="2v-mlitradar_2022-06-03_0450utc.nc"
datapath="./"
time = fn[13:28]
data = xr.open_dataset(datapath+fn)
data = data.metpy.parse_cf().squeeze()
print(data)
colorscale = "pyart_NWSRef"
start = (139.5, 35.8)
end = (139.5, 36.3)
cross = cross_section(data, start, end)
print(cross)
cross.set_coords(('lat','lon'),True)
print(cross)
#Define the figure object and primary axes
fig = plt.figure(1, figsize=(16., 9.))
ax = plt.axes()
#plot
re_contour = ax.contourf( cross['lon'],cross['REF'],
levels=np.arange(-10, 60, .05), cmap=colorscale)
re_colorbar = fig.colorbar(re_contour)
plt.show() I'm getting: File "C:\Users\anaconda3\envs\pyart_env\lib\site-packages\metpy\interpolate\slices.py", line 162, in cross_section
x = data.metpy.x
File "C:\Users\anaconda3\envs\pyart_env\lib\site-packages\metpy\xarray.py", line 502, in x
return self._axis('x')
File "C:\Users\anaconda3\envs\pyart_env\lib\site-packages\metpy\xarray.py", line 419, in _axis
raise AttributeError(axis + ' attribute is not available.')
AttributeError: x attribute is not available.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "pruebita.py", line 32, in <module>
cross = cross_section(data, start, end)
File "C:\Users\anaconda3\envs\pyart_env\lib\site-packages\metpy\interpolate\slices.py", line 151, in cross_section
return data.map(cross_section, True, (start, end), steps=steps,
File "C:\Users\anaconda3\envs\pyart_env\lib\site-packages\xarray\core\dataset.py", line 5934, in map
variables = {
File "C:\Users\anaconda3\envs\pyart_env\lib\site-packages\xarray\core\dataset.py", line 5935, in <dictcomp>
k: maybe_wrap_array(v, func(v, *args, **kwargs))
File "C:\Users\anaconda3\envs\pyart_env\lib\site-packages\metpy\interpolate\slices.py", line 164, in cross_section
raise ValueError('Data missing required coordinate information. Verify that '
ValueError: 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. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Thank you for sharing your code and your full error message. In the error message, it looks like this is the main problem with the current error: From the documentation for
It would seem that your Could you share the output of the three |
Beta Was this translation helpful? Give feedback.
Based on this #949 (comment):
Try including the specific variable you'd like to make the cross-section for. If you are trying to make a reflectivity cross section, then change this line:
cross = cross_section(data, start, end)
to be:
cross = cross_section(data['REF'], start, end)
And see if that works.
The trouble I think is that variables
U
andV
do not haveLAT
andLON
coordinate variables, and socross_section
fails when passing the whole dataset.If you want multiple variables, you can do:
cross = cross_section(data[['REF','ZDR','RHOHV','KDP','RR','QUALITY_FLAGS']], start, end)
Just make sure any variable you're passing to
cross_section
hasLAT
andLON
coordinates.