-
Notifications
You must be signed in to change notification settings - Fork 368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quiver with all projections: bad direction of arrows #1179
Comments
Made a test with the Mercator projection instead of north polar stereographic and the problem is the same. So I guess the problem is for all projections. |
Confirming that the I believe there are three cases:
cc @ajdawson as the original |
In putting together the summary above, I had the following example:
Which when visualised in the source CRS:
And in a projected CRS:
Reprojecting that case:
It is quite clear that the magnitude of the vectors is preserved ref and that direction is based on the source grid. |
I've thought over this some more, and now wonder if cases 1 and 2 are actually the same thing, and we are looking at a bug that is acute for this projection. In particular, I think the transform_vectors algorithm uses a forward difference to compute the rotation, but a central difference would provide a much better estimation. |
Thank you for your answer. Maybe I am missing something in your line of thought but it seems to me that the example you have chosen does not illustrate the problem. The problem comes from the difference between the directions of (u /cos (latitude), v) and (u, v). So if you choose v = 0, there is no difference in direction. That is why I chose : u = -3, v =0.1 and latitude = 89°, in my post above. Second, thanks for confirming that the transform_vectors algorithm is based on derivatives of source coordinate system. My point is then that I think the public interface of quiver with cartopy is very inconvenient. The majority of use cases of quiver in Cartopy is probably to plot a wind field in some projection, with the wind given by its eastward and northward components. In order to plot this wind field now in Cartopy, I have to do something like: u_src_crs = u / np.cos(lat[:, np.newaxis] / 180 * np.pi)
v_src_crs = v
magnitude = ma.sqrt(u**2 + v**2)
magn_src_crs = ma.sqrt(u_src_crs**2 + v_src_crs**2)
ax.quiver(lon, lat, u_src_crs * magnitude / magn_src_crs, v_src_crs * magnitude / magn_src_crs,
transform = src_crs) I should not have to do all this just to plot a wind field. There should be a one-line command for this, included with cartopy. |
+1 for simple way of plotting vectors with starting point given by lat & lon and direction and length given by geographic north & east components in some physical units. In my case this would be geomagnetic and geoelectric fields with north and east components of nT and mV/km respectively. |
Ideally there would also be a boolean toggle to choose between making vector lengths depend only on the physical quantity (in addition automatic or user defined global scaling) or also depend on how far they seem to be located from the camera. |
Did anyone ever resolve this or find a way of doing something like rotate_vector without Basemap? That was a pretty useful function but it's hard to use this without needing to define the projection with Basemap too... |
Using the "angles" keyword in call to quiver seems to work fine. |
I do not think it does in a convenient way : that is what I tried to show in submitting this issue. See the example in my post at the top of this issue. |
I total agree with @lguez , the current user interface for vector rotation in Cartopy is inconvenient at the least. I don't think this issue is clearly documented so the first time users may not realize they need to rescale the u/v components (like @lguez's code above) before feeding the vectors into |
+1 for documentation on (optionally simple) way of plotting vectors with starting point given by lat & lon and direction and length given by geographic north & east components in some physical units |
I definitely agree that this needs to be better documented at the very least. I would have continued to plot wind vectors in Antarctica incorrectly if I had not accidentally run across this post. In case anyone needs it, here's another example of the issue:
The arrows at longitude 0 should point West. As you can see in the first figure, without the rotating and rescaling provided by Iguez, the arrows point in the wrong directions. With the rotation and rescaling, the arrows are correct (second figure). |
I agree the current situation is less than ideal and there should be a way to handle this easier within Cartopy. I opened #1920 with a proposed fix for this. |
It has been 3 years and this problem still exists, I would like to know if there are plans to improve it in the future. Thank you in advance. |
There is a linked PR with a proposed fix that no one has commented on: #1926 |
Glad I found this after beating my ahead against this for half a day. It looks like the fix is still pending, in the meantime the cartopy quiver doc could probably use an update. Not sure what the mechanism for this is. |
I have the same problem. Have you resolved this problem? |
Description
I have a wind field : eastward component
u
and northward componentv
, in m s-1. I want to make a quiver plot of this field in north stereographic projection. I would expect the correct command to be:( The complete test code is below.) However, this produces arrows in the wrong direction. It appears that the way to obtain the correct direction for the arrows is to write:
Note that the magnitude of the vector is not correct then, we should also renormalize it to get the correct magnitude. Compare this with the behavior of basemap:
which produces correct arrows.
I think this is a bug, or a bad feature of cartopy. The problem comes from the
transform_vectors
method, as shown in the test code below. In this test code, we want to plot a single vector at longitude 0°, latitude 89°N. The vector is almost westward: u < 0 and v is very small compared to u. In the north stereographic projection, the components of the projected vector should be almost the same than the original components. We see with the test code below that therotate_vector
method of basemap correctly produces this result. However, thetransform_vectors
of cartopy surprisingly does not produce this result. To get the correct result withtransform_vectors
, we have to divideu
by the cosine of latitude, and renormalize the result fromtransform_vectors
. It seems thattransform_vectors
expects the derivative of longitude instead of the wind. This is quite awkward to use and counter-intuitive, I think, or a bug. The test code below goes on to plot the single vector, with basemap and with cartopy. We see the red arrow with cartopy in the wrong direction.Code to reproduce
Here is the complete test code.
Here is the standard output of the script:
And here are the two resulting figures:
Full environment definition
Operating system
Linux Mint 19 Cinnamon
Cartopy version
0.16.0
pip list
The text was updated successfully, but these errors were encountered: