A question about plotting wind vectors

34 views
Skip to first unread message

Chun-Chih Wang

unread,
Jun 3, 2024, 7:12:44 PM6/3/24
to wrfpython-talk
Hi WRF-Python Talk Group,

I am a WRF-Python user. I am confused about what would be the correct way to plot quivers or barbs using the U and V components in the WRF output.

The U and V components given by WRF are relative to the WRF simulation projection grid (these are the U and V retrieved by calling wrf.getvar(wrfdata, ‘ua’) or wrf.getvar(wrfdata, ‘va’).

Instead of using the WRF-Python’s built-in tool to get the earth-relative U and V (wrf.getvar(wrfdata, ‘uvmet’)), I used the formulas on David Oven’s website on “How to Properly Rotate WRF Winds to Earth-Relative Coordinates” to rotate my grid-relative WRF winds to Earth-relative because I have been using those formulas for a long time, before I started using WRF-Python. The results are slightly different from the results given by WRF-Python’s get_uvmet. I will keep using David Oven’s formulas unless somebody has a strong preference of one over the other.

My first question is, in my understanding, if I wish to plot my barbs on a map with the same map projection as my WRF output, I don’t need to rotate the grid-relative U and V (i.e., ua and va) into Earth-relative at all. Is this correct?

My second question is, what is the proper way to plot my barbs in the same projection as my WRF output in Cartopy. I have been using Basemap before and it seems to do the job. I am now looking into re-writing my code using Cartopy. However, I got confused by the 500 hPa geopotential height and winds example. From my understanding, the Cartopy and the Basemap examples should produce the same barb plots, but they don’t. The Basemap plot makes more sense because the barbs are more or less parallel to the 500-hPa height contours, especially over the upper-left corner of the plotted domain. This is not the case in the Cartopy example figure. It seems the Basemap example code might be doing the right thing?

I attached a couple of figures showing the wind barbs and the ‘smoothed’ geopotential heights at 100 hPa plotted using Cartopy or Basemap (the winds are not smoothed). My Python script to produce these figures is also attached. They illustrate my questions and the tests I have done, along with some possible approaches I found online or by myself. In both figures, I aimed to plot WRF U and V barbs on a map with the same projection as the WRF output. In the Basemap plot, the grid-relative barbs plotted using three different approaches strictly overlay each other. In the Cartopy plot, the black barbs were plotted following WRF-Python’s example. The green barbs were plotted by rotating Earth-relative U and V (from David Oven’s formulas) back to grid-relative using Cartopy’s transform_vectors and plotted on the map with lat-lon coordinates input and transform=ccrs.PlateCarree(). Some people pointed out this method may be deficient due to a bug in Cartopy. The blue barbs were plotted by rotating Earth-relative U and V (from David Oven’s formulas) back to grid-relative using someone’s proposed correction and then plotted on the map with lat-lon coordinates input and transform=ccrs.PlateCarree(). The red barbs were plotted based on my test- the lat-lon coordinates were first transformed to the map-projection coordinates using Cartopy’s transform_points. The barbs were then plotted with the grid-relative U and V, the transformed x and y coordinates, and transform=wrf_map_projection (similar to the Basemap barb-plotting procedure). I think this avoided confusing Cartopy with what projection my grids and wind components were in. I believe no rotation will be performed if I specify that the inputs are also in the same projection as the pre-defined map projection. Finally, I used a modified vector rotation code (alt_rotateVec.py, based on this post: https://github.com/matplotlib/basemap/issues/269) to transform the Earth-relative U and V (from David Oven’s formulas) to grid-relative components, and I then plotted the barbs using the same x and y, and transform=wrf_map_projection). These are shown in magenta barbs. As you can see, the barbs plotted using the last two approaches match each other.

If you compare the two figures, you can also see that the barbs plotted using the last two approaches in my Cartopy figure match those in my Basemap figure. If the barbs in my Basemap figure were plotted correctly, this would indicate that the last two approaches in my Cartopy figure are correct.

For now, I am not entirely sure what approach I should take to plot the barbs correctly in Cartopy and Basemap, as people have different opinions. If someone has a definitive answer to this, that would be great. I really hope to plot my barbs correctly.

Thank you,
David

sample_vectorplots_cartopy_vs_basemap.py
alt_rotateVec.py
barbs_plotting_in_basemap_native_wrf_projection.png
barbs_plotting_in_cartopy_native_wrf_projection.png
Reply all
Reply to author
Forward
0 new messages