-
Notifications
You must be signed in to change notification settings - Fork 390
enforce stable aws endpoint for cartopy_feature_download.py #1837
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
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -10,19 +10,23 @@ | |
|
|
||
| For detail on how to use this tool, execute it with the `-h` option: | ||
|
|
||
| python download.py -h | ||
| python cartopy_feature_download.py -h | ||
|
|
||
| """ | ||
|
|
||
| import argparse | ||
| import pathlib | ||
|
|
||
| from cartopy import config | ||
| from cartopy.feature import Feature, GSHHSFeature, NaturalEarthFeature | ||
| from cartopy.io import Downloader | ||
| from cartopy.io import Downloader, DownloadWarning | ||
|
|
||
|
|
||
| ALL_SCALES = ('110m', '50m', '10m') | ||
|
|
||
| # See https://github.com/SciTools/cartopy/pull/1833 | ||
| URL_TEMPLATE = "https://naturalearth.s3.amazonaws.com/{resolution}_{category}/ne_{resolution}_{name}.zip" | ||
| SHP_NE_SPEC = ("shapefiles", "natural_earth") | ||
|
|
||
| FEATURE_DEFN_GROUPS = { | ||
| # Only need one GSHHS resolution because they *all* get downloaded | ||
|
|
@@ -114,11 +118,27 @@ def download_features(group_names, dry_run=True): | |
| action='store_true') | ||
| parser.add_argument('--ignore-repo-data', action='store_true', | ||
| help='ignore existing repo data when downloading') | ||
| parser.add_argument('--no-warn', | ||
| action='store_true', | ||
| help='ignore cartopy "DownloadWarning" warnings') | ||
| args = parser.parse_args() | ||
|
|
||
| if args.output: | ||
| config['pre_existing_data_dir'] = args.output | ||
| config['data_dir'] = args.output | ||
| target_dir = pathlib.Path(args.output).expanduser().resolve() | ||
| target_dir.mkdir(parents=True, exist_ok=True) | ||
|
Member
Author
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. The
Contributor
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. I guess you'll just get an error if you want to try with an earlier Python version ;) |
||
| config['pre_existing_data_dir'] = target_dir | ||
| config['data_dir'] = target_dir | ||
| if args.ignore_repo_data: | ||
| config['repo_data_dir'] = config['data_dir'] | ||
| if args.no_warn: | ||
| import warnings | ||
| warnings.filterwarnings("ignore", category=DownloadWarning) | ||
|
|
||
| # Enforce use of stable AWS endpoint, regardless of cartopy version. | ||
| # In doing so, this allows users to download this script and execute it with | ||
bjlittle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # any version of cartopy, thus taking advantage of the stable AWS endpoint. | ||
| # This removes the need to backport the associated fix | ||
| # https://github.com/SciTools/cartopy/pull/1833. | ||
| config['downloaders'][SHP_NE_SPEC].url_template = URL_TEMPLATE | ||
|
|
||
| download_features(args.group_names, dry_run=args.dry_run) | ||
Uh oh!
There was an error while loading. Please reload this page.