-
Notifications
You must be signed in to change notification settings - Fork 168
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
Refactor visualization module #199
Conversation
- **kwargs was replaced by the explicit keywords declarations - If unsupported kwargs are provided, they are ignored and a deprecation warning is shown.
- Use a single function to plot the quiver and the streamplots to avoid code duplication. This function is called by the quiver and streamplot functions. - Use different zorders for each type of plot - Improve the handling of existing geoaxes - Add two new utils functions to avoid code repetitions
- Fix bug in plot_precip_field handling the old type keyword.
Also, avoid plotting the no-data mask separately. Instead, plot it in the `_plot_field` function.
- Use the parse_proj4_string for construct a dictionary with the proj definitions - Simplify the function code by using additional dictionaries to relate the Pyproj and Cartopy parameters. - Add support for additional cartopy keywords defined in the Proj4 definitions.
The PYPROJ_PROJ_KWRDS_TO_CARTOPY key,values where reverted (values, keys). This produced incorrect cartopy projections that where unrelated with the proj4 definitions.
Codecov Report
@@ Coverage Diff @@
## master #199 +/- ##
==========================================
+ Coverage 76.30% 78.01% +1.70%
==========================================
Files 130 131 +1
Lines 9690 9638 -52
==========================================
+ Hits 7394 7519 +125
+ Misses 2296 2119 -177
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
Well, this is really excellent work Andres and a very much needed refactoring of the visualization module! It brings a lot of clarity in the code and solves both long standing and newer issues, thanks a lot for the contribution!
I also still need to test it directly myself with some code and data (including the pysteps examples), but for the moment I went through the PR and left few minor comments.
I like the way you formalized the zorder conventions used when plotting. However, personally I like to see the national boundaries on top of the precipitation field: this allows to keep a geographical reference even when the precipitation field is very large and covers most of the domain. Hence, I'd suggest to set the coastline, cultural, reefs and minor_islands features with a zorder > 10, what do you think? |
👍 I'll make the changes. |
Sets the coastline, cultural, reefs and minor_islands features with a zorder = 15. In this way, they are plotted on top of the precipitation field.
Hi @aperezhortal, thanks for including my previous comments in this PR. I had a look at the examples rendered from this branch, and unfortunately, it seems that something's still off, for example in thunderstorm_detection_and_tracking.py: Figure 1, v:refactor_visualization_module: I haven't had the chance to investigate the cause of this yet, but hopefully it relates to something minor. |
- If geodata is not None but cartopy is not installed, return the x/y grids in the coordinates units defined in geogrid.
A workaround for the missing Somerc projection was already implemented in the visualization.utils module: # Note: ccrs.epsg(2056) doesn't work because the projection # limits are too strict. # We'll use the Stereographic projection as an alternative. somerc=ccrs.Stereographic,
…ctor_visualization_module
For certain situations, the quiver plots were not tight and a margin was shown
The y_grid was returned in the incorrect order for yorigin=upper
Hi @dnerini, thanks for spotting this! The Now the documentation is almost equal to the main branch. You may note small differences in the motion vectors since now they are plotted using the grid coordinates with the same y-origin of the data. Thus, the "steps" starts on the y-origin passed in the geodata (upper) instead of starting at the bottom as before. |
This looks really great, Andres. I noticed only one last inconsistency with the current master branch, Figure 4 in plot_steps_nowcast.py: v:refactor_visualization_module Notice the reddish background color in the second image? I think the transparency for zero probabilities is not working properly. I implemented my suggested changes in 9a0049c. Feel free to modify or revert them as needed. |
Since BoundaryNorm was used, there is no need to set the vmin, vmax explicitly.
plt.show was added to make the scripts running correctly from the command line.
Refactor the visualization module
1) Refactor visualization.utils functions
basemaps.plot_geography
clears existing cartopy axis #197.2) Refactor plotting functions
_plot_field_pcolormesh
and_plot_field
in a single function._plot_field
function.quiver
andstreamplots
functions into a single one calledplot_motion
for avoiding code duplication.The
quiver
andstreamplot
functions are now wrappers forplot_motion
.type
keyword inplot_precip_field
toptype
to avoid shadowing the built-in function with the same name. Add the corresponding deprecation warning.3) Define a unique zorder for each type of plot