-
Notifications
You must be signed in to change notification settings - Fork 367
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
ENH: Allow Natural Earth version to be specified #2351
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -275,10 +275,12 @@ def records(self): | |||||
""" | ||||||
|
||||||
|
||||||
def natural_earth(resolution='110m', category='physical', name='coastline'): | ||||||
def natural_earth(resolution='110m', category='physical', | ||||||
name='coastline', version=None): | ||||||
""" | ||||||
Return the path to the requested natural earth shapefile, | ||||||
downloading and unzipping if necessary. | ||||||
downloading and unzipping if necessary. If version is not specified, | ||||||
the latest available version will be downloaded. | ||||||
|
||||||
To identify valid components for this function, either browse | ||||||
NaturalEarthData.com, or if you know what you are looking for, go to | ||||||
|
@@ -299,10 +301,11 @@ def natural_earth(resolution='110m', category='physical', name='coastline'): | |||||
# get hold of the Downloader (typically a NEShpDownloader instance) | ||||||
# which we can then simply call its path method to get the appropriate | ||||||
# shapefile (it will download if necessary) | ||||||
_version_string = "" if version is None else f"{version}/" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't need to be private if it is just used within the method.
Suggested change
|
||||||
ne_downloader = Downloader.from_config(('shapefiles', 'natural_earth', | ||||||
resolution, category, name)) | ||||||
format_dict = {'config': config, 'category': category, | ||||||
'name': name, 'resolution': resolution} | ||||||
resolution, category, name)) | ||||||
format_dict = {'config': config, 'category': category, 'name': name, | ||||||
'resolution': resolution, 'version': _version_string} | ||||||
return ne_downloader.path(format_dict) | ||||||
|
||||||
|
||||||
|
@@ -321,7 +324,7 @@ class NEShpDownloader(Downloader): | |||||
# Define the NaturalEarth URL template. Shapefiles are hosted on AWS since | ||||||
# 2021: https://github.com/nvkelso/natural-earth-vector/issues/445 | ||||||
_NE_URL_TEMPLATE = ('https://naturalearth.s3.amazonaws.com/' | ||||||
'{resolution}_{category}/ne_{resolution}_{name}.zip') | ||||||
'{version}{resolution}_{category}/ne_{resolution}_{name}.zip') | ||||||
|
||||||
def __init__(self, | ||||||
url_template=_NE_URL_TEMPLATE, | ||||||
|
@@ -386,7 +389,7 @@ def default_downloader(): | |||||
ne_{resolution}_{name}.shp | ||||||
|
||||||
""" | ||||||
default_spec = ('shapefiles', 'natural_earth', '{category}', | ||||||
default_spec = ('shapefiles', 'natural_earth', '{category}', '{version}', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like the doctest failure is related to the docstring right above this. Where it got a |
||||||
'ne_{resolution}_{name}.shp') | ||||||
ne_path_template = str( | ||||||
Path('{config[data_dir]}').joinpath(*default_spec)) | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ def test_natural_earth(): | |
@pytest.mark.mpl_image_compare(filename='natural_earth_custom.png') | ||
def test_natural_earth_custom(): | ||
ax = plt.axes(projection=ccrs.PlateCarree()) | ||
feature = cfeature.NaturalEarthFeature('physical', 'coastline', '50m', | ||
feature = cfeature.NaturalEarthFeature('physical', 'coastline', '50m', '5.1.0', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you find that version There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! Yes, no diff between the baseline image here of Iceland and when using 5.1.0 |
||
edgecolor='black', | ||
facecolor='none') | ||
ax.add_feature(feature) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,7 +83,8 @@ class TestRivers: | |
def setup_class(self): | ||
RIVERS_PATH = shp.natural_earth(resolution='110m', | ||
category='physical', | ||
name='rivers_lake_centerlines') | ||
name='rivers_lake_centerlines', | ||
version='5.0.0') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, did this specific version ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it was passing. Note there is no image comparison here, the test just looks at a few very specific features and there was no change. |
||
self.reader = shp.Reader(RIVERS_PATH) | ||
names = [record.attributes['name'] for record in self.reader.records()] | ||
# Choose a nice small river | ||
|
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.
Can you also update the above cases to follow numpydoc formatting by adding
: str
to all of them.