Skip to content
This repository has been archived by the owner on Oct 24, 2022. It is now read-only.

Commit

Permalink
Add antarctic_ice_shelves_polys to download (#7)
Browse files Browse the repository at this point in the history
* Bump the version number to 0.2.3

* Add antarctic_ice_shelves_polys to download

This merge switches to using a python script to do the downloading.
This let us get the version number more easily from cartopy, as
well as add features that are not downloaded by default.

I have kind of cheated by downloading the python file we want and
then importing it as a module.  If a better way exists, I'm
eager to hear it!
  • Loading branch information
xylar authored May 6, 2020
1 parent 7e5a16d commit 9bbad39
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 32 deletions.
53 changes: 53 additions & 0 deletions bin/download_cartopy_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python
import argparse
import os
import urllib.request
import tempfile
import cartopy
from cartopy import config
import sys


def main(target_dir):
try:
os.makedirs(target_dir)
except OSError:
pass

version = cartopy.__version__

with tempfile.TemporaryDirectory() as tmpdirname:
target_dir = os.path.abspath(target_dir)
owd = os.getcwd()
os.chdir(tmpdirname)
urllib.request.urlretrieve(
'https://raw.githubusercontent.com/SciTools/cartopy/v{}/tools/feature_download.py'.format(version),
'feature_download.py')

file = open('__init__.py', 'w')
file.close()

sys.path.append(tmpdirname)

from feature_download import FEATURE_DEFN_GROUPS, download_features

# add Antarctic ice shelves
FEATURE_DEFN_GROUPS['physical'] = \
FEATURE_DEFN_GROUPS['physical'] + \
(('physical', 'antarctic_ice_shelves_polys', ('50m', '10m')),)

config['pre_existing_data_dir'] = target_dir
config['data_dir'] = target_dir
config['repo_data_dir'] = target_dir
download_features(
['cultural-extra', 'cultural', 'gshhs', 'physical'], dry_run=False)
os.chdir(owd)


if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Download cartopy data for caching.')
parser.add_argument('--output', '-o', required=True,
help='save datasets in the specified directory')
args = parser.parse_args()
main(args.output)
30 changes: 0 additions & 30 deletions bin/download_cartopy_data.sh

This file was deleted.

4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from setuptools import setup

setup(name='cartopy_offlinedata',
version='0.2.2',
version='0.2.3',
description='Add shared data path to cartopy config',
url='https://github.com/willirath/cartopy_offlinedata',
author='Willi Rath',
author_email='[email protected]',
license='MIT',
packages=['cartopy_userconfig'],
scripts=['bin/download_cartopy_data.sh'],
scripts=['bin/download_cartopy_data.py'],
zip_safe=False)

0 comments on commit 9bbad39

Please sign in to comment.