-
Notifications
You must be signed in to change notification settings - Fork 298
added rotate_winds #1546
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
added rotate_winds #1546
Conversation
|
It may be squashed into a single commit by me, but rest assured @PPMo did all the work 😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this new globe handling has broken a couple of the existing tests in iris.tests.test_mapping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'm onto it.
|
Can you add some information to the documentation regarding the units of the vectors. Does the function assume the units are the same in each coordinate system (e.g. the vectors are desired to be in m/s in both) or does it assume the vectors are based on the distance metric in each individual projection? I'm assuming it is the former because that is by far the most common case, but you need to say so because the two are obviously not the same thing. |
|
Can you comment about not utilizing the existing |
I did have a version of the code that wrapped the cartopy rotate_vectors call with before-and-after distance scaling, but then I found I had all the bits in place to just do it entirely in Iris.. I came to the conclusion that the existing cartopy transform_vectors is actually "wrong", because although it preserves magnitudes it doesn't take account of unequal scaling of X and Y w.r.t. actual distances on the ground. An example Now consider the same wind in a rotated system with the pole at (say) lat=30, long=180 (pole is rotated "backwards" by 60 deg).
So, the problem with the existing routine is : in this case the code will take the vector (10, 10) and transform it. However, a vector with equal X and Y steps does not follow a 45 degree path on the ground. As the calculation is the correct one for coordinate vectors, this doesn't work right (of course, a similar distance-scaling factor is also needed after the transform step). Another way of looking at this is that the units of an actual coordinate time differential would be (e.g.) degrees/second, but winds are in metres/second. Even if the projection has metres as its units, these can't possibly match real metres everywhere. So, what I think the existing routine is actually doing is transforming coordinate vectors, not wind-type vectors -- except that it adjusts the magnitudes to keep them the same. |
Your assumption is 100% correct, that is what is meant. In fact, I was originally were intending to name the operation in a more general fashion, something like "transform_distance_differentials" or "project_displacement_vectors"... In the end, I was persuaded that simply calling it "rotate_winds" was the least confusing way of explaining what is meant, even though the concept is in fact more general, and more subtle. @ajdawson if you really want more explanation, can you suggest how we might phrase it ? |
5052a38 to
9990b97
Compare
9990b97 to
dd2f5bf
Compare
|
+1 for a statement on the units. One of my early versions mentioned that they are not modified. |
|
@pp-mo - I don't think I agree with your assertion that the cartopy code is wrong. However, your explanation is not clear to me either. There is plenty of room for misunderstanding here so I'll be clear about how I view the cartopy methodology: Cartopy transform vectors assuming vectors are defined as components in projection coordinates, i.e. they are grid relative rather than north/east. It assumes these are vectors of a quantity such as wind speed. It transforms to a set of vectors that are grid relative in the target projection (i.e. u and v are in the same directions as the strictly orthogonal x and y projection coordinates). The transformed vectors are constructed so that they point in the same direction (north/east) in the target projection as in the source projection, and the magnitude of the vector in terms of the wind speed will be conserved. I'm not really sure how this doesn't fit the bill, are you saying the vector directions are incorrect with cartopy? At least visually I can't see any issue, but perhaps it is more subtle? For example: I'd appreciate your feedback on this. In particular it'd be great to see a reproduction of this example using your methodology (u=v=10; x=0,30,60,90; y=0,45; all expressed in Plate Carree). |
|
Hi @ajdawson. When I began this work I convinced myself that the cartopy code fitted the bill perfectly. The code is clear and the logic is well explained. After a lot of thinking I've become convinced that it doesn't quite do what's needed in this case. Whether the code is cartopy needs changing is another question that my brain couldn't take on at the time. I now think it does, but I was hoping we could get this functionality into Iris and then have the debate on cartopy. My thinking as to why This is calculating an angle in terms of u and v (in m/s) at a location where u and v are components in the directions defined by the grid directions in the source coordinate system at the location in question. In my mind this angle points in the physical direction that the wind is pointing in the real world. The issue is that a perturbation in grid coordinates (e.g. deg lat and deg lon) is then calculated using this angle in a way that assumes the scaling of the x and y axes is the same i.e. delta degrees lat and delta degrees lon is the same distance on the ground. This scaling varies with location (latitude), which manifests itself as a systematic error as you move away from the equator. Another way to imagine this (bear with me, this might sound very silly 😉) is to consider a short stick lying on the ground pointing in the direction of the wind. Imagine that the physical length of this stick (say 20cm) represents the wind speed (20 m/s), and the windspeed is 20m/s everywhere. As the wind direction changes we rotate the stick to point in the right direction. As we move around the globe, we take our stick with us and provided the wind speed is 20m/s the stick is the correct length. Pick a location and for simplicity, consider a non-rotated lot-lon where x and y are measured in degrees longitude and latitude. The location is easy with my garmin GPS and the x and y directions are well defined as they happen to point east and north. Now the tricky bit. Let the wind (and the stick) point NE. Look down at the stick from above and imagine grid lines of lat and lon. The stick will be at 45 degrees to these axes and the u and v components will be equal. Using the cartopy code the Does any of this make sense? |
lib/iris/analysis/cartography.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pp-mo - I find this troublesome as they are measures of speed, not distance. I think I understand your desire for this statement - would replacing distance with speed be ok?
|
Thanks @esc24. I think that's a very cogent account, and assuming I've understood it right I think this agrees with my view of it. Meanwhile, though, I want to make one important point right now : I think we need to be very careful about plots. For example, consider @ajdawson 's first plot in the above comment.. This appears to show a constant "SW" wind, i.e. U=V; or "bearing from 135 deg"; or arrows at 45deg everywhere. I'm still not sure whether I think the cartopy quiver is "correct" in this. However there's another even bigger question here, which is what a wind plot "should" look like. |
|
@esc24 - It does make sense to me. I understand the different scaling with respect to to coordinate system. I've no problem with the functionality in Iris. The thing I'm trying to think over is whether this is actually wrong or not in cartopy, which is tangential to the discussion of this PR. I guess in a lot of plotting software you actually get to choose this behaviour (e.g. Reading IDL meteorology library's /MAP keyword). I'm excited that this could lead to better handling of vectors in Cartopy too, the current implementation is definitely a bit rough around the edges to say the least. For instance if you want "standard" vectors from a lat/lon grid you have to define them on a PlateCarree() projection then they are treated as being in the projection coordinates, so equal u and v components will be at 45 degrees everywhere, which is correct given the definition of the problem. However, perhaps it would be better to be able to express them in a lat/lon CRS and transform to a Plate Carree projection which would then exhibit an angle change away from the equator. I'm not sure the current framework allows for this, but perhaps this new work would. If the functionality required here and that in Cartopy are the same (solving the same problem) then it would be good to eventually do the work in Cartopy and leave a thin wrapper over it in Iris. Of course implementing it solely in Iris is a good first start. |
|
@pp-mo - The definition of the quiver function in cartopy specifies that wind components be grid relative. In the example I chose I defined the vectors on a Plate Carree projection (not a lat/lon spherical) so in this case it is absolutely correct that they are at 45 degrees everywhere. However, users may want to transform the data in spherical lat/lon to Plate Carree and see the variation in angle away from the equator. This is currently not supported.
Good point, other software I've worked with often gives you the choice of how to scale, and matplotlib can do this too (with respect to the actual projection coordinates though, so won't understand the nature of the projection of the sphere). We should definitely aim to be able to plot as you describe in cartopy, especially for streamlines as you described, but it may also be desirable to retain the present functionality as many users will actually want to use it. |
lib/iris/analysis/cartography.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor typo, change be tha same to be the same
Thanks for this hint. This is actually from our own older codebase (the IDL "UKMO library"). |
|
@pp-mo - Not specifically, I've never used the UKMO PP library. I was referring to the guide and accompanying software Using IDL In Meteorology (pdf). Other tools like NCL have this type of feature too. |
|
Hi @ajdawson I have just made a worked example of my above confusing+wordy example. I think this shows how the cartopy calculation differs, and what I thought was the "wrong" answer. |
added masking of erroneous values
|
Ok, I'm good with those changes, and I also checked I'm happy with the other tests I inherited from Ed's code before. |
|
Lots of useful info here to think about from a cartopy perspective, but I'm happy with |
Not just cartopy, either, as the tested result accuracies are still rather questionable.
So the big remaining questions are :-
It occurs to me we may be able to investigate the role of PROJ4 by performing the numerical calculation, but with "exact" rotated-pole equations for the point transformations. |
No description provided.