Repository navigation
Add Cartopy background maps - #107
Merged
Merged
Conversation
Member
Add background map
…unctionality missing, though
Member
|
@overeem11 I had a go at integrating some parts of what you have in the separate
Remaining TODOs:
@overeem11 What are crucial feature that are missing in you opinion? |
…ebook I did also refactor the exiting things a bit. This is not perfect yet, though. Maybe a better solution would be to completely remove the map background stuff from plot_lines and only have it in plot_plg because plot_lines could be a function that is not exposed to the user anyway since plot_plg has the same functionality plus the option to plot grid and points in addition...
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #107 +/- ##
==========================================
+ Coverage 98.90% 98.97% +0.06%
==========================================
Files 7 7
Lines 822 878 +56
==========================================
+ Hits 813 869 +56
Misses 9 9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
|
Current status:
TODOs:
I will take a break with this PR and try to finish it next week. |
this is also the current state in upstream/main but I add it here manually
Make the "NE" (Natural Earth) background map features configurable via a default dict that users can override, and expose the new background map options through the xarray accessor plotting functions. plot_map.py: - Add DEFAULT_NE_FEATURES dict capturing the default NE features (ocean, land, lakes, borders, coastlines). Each entry specifies whether to call ax.add_feature or ax.coastlines plus the keyword arguments. - Add ne_features parameter to set_up_axes. User-provided kwargs are merged into the defaults per feature, so individual features can be overridden without re-specifying the whole configuration. - Add ne_features pass-through to plot_lines and plot_plg. - Clean up redundant parentheses in type annotations (formatter). xarray.py: - Expose background_map, projection, and ne_features parameters on both the Dataset and DataArray .plg.plot_cmls() accessor methods, forwarding them to plot_map.plot_lines. tests: - Add tests for custom/empty ne_features, unsupported method error, plot_lines with ne_features, plot_plg with ne_features, and both accessor variants. - Close datasets returned by load_openmrg() in the plot_plg tests. Not closing them left netCDF4 file handles open, which caused a segmentation fault when the same example files were opened again in a subsequent test.
Expand the docstrings of plot_lines, set_up_axes and plot_plg in plot_map.py to properly document the background_map, projection, extent and ne_features parameters that were added for cartopy background map support. This includes the valid values of background_map ("stock", "OSM", "NE"), the default projection behavior, when the parameters are used (only if ax is not provided), and a Raises section for set_up_axes. Also remove a leftover garbage line in the plot_plg docstring.
Document the same parameters in the docstrings of the plot_cmls accessor methods in xarray.py and clarify that the Dataset accessor plots with a single color while the DataArray accessor colors the lines based on the data values.
Fix pylint warning C0206 (consider-using-dict-items) in set_up_axes by iterating over DEFAULT_NE_FEATURES.items() in the dict comprehension that merges the default and user-provided NE feature configuration.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
This PR adds support for cartopy-based map backgrounds to the poligrain
plotting functions, so that CMLs, points and grids can be plotted on top of
a geographic map.
New features
matplotlib Axes or cartopy GeoAxes with an optional background map:
borders, coastlines), configurable via the module-level
DEFAULT_NE_FEATURES dict and the ne_features argument, e.g.
ne_features={"land": {"facecolor": "green"}}
the displayed bounding box
(both Dataset and DataArray) now accept the new background_map,
projection, extent and ne_features arguments and use set_up_axes()
when no ax is provided
data_crs argument (defaults to PlateCarree for lon-lat data)
Tests
custom/empty/invalid ne_features), scatter_lines with GeoAxes and
data_crs validation, plot_lines/plot_plg with GeoAxes and
ne_features, and the xarray accessors with ne_features
Documentation
backgrounds, including ne_features customization, for both plot_lines
and plot_plg
.plg.plot_cmls() accessors, documenting all new parameters
Other