Debian Codegraph @

tools/download_datasets.py

raw symbols SCIP
1 """
2 Tool to download all local datasets and save them within the vega_datasets
3 source tree.
4
5 Usage:
6 $ python download_datasets.py
7 """
8
9 import json
10 from os.path import abspath, join, dirname
11 import sys
12 from urllib.request import urlretrieve
13 import json
14
15 sys.path.insert(1, abspath(join(dirname(__file__), "..")))
16 from vega_datasets.core import Dataset
17
18 DATASETS_TO_DOWNLOAD = [
19 "airports",
20 "anscombe",
21 "barley",
22 "burtin",
23 "cars",
24 "crimea",
25 "driving",
26 "iowa-electricity",
27 "iris",
28 "la-riots",
29 "ohlc",
30 "seattle-temps",
31 "seattle-weather",
32 "sf-temps",
33 "stocks",
34 "us-employment",
35 "wheat",
36 ]
37
38
39 def _download_datasets():
40 """Utility to download datasets into package source"""
41
42 def filepath(*args):
43 return abspath(join(dirname(__file__), "..", "vega_datasets", *args))
44
45 dataset_listing = {}
46 for name in DATASETS_TO_DOWNLOAD:
47 data = Dataset(name)
48 url = data.url
49 filename = filepath("_data", data.filename)
50 print("retrieving data {0} -> {1}".format(url, filename))
51 urlretrieve(url, filename)
52 dataset_listing[name] = "_data/{0}".format(data.filename)
53 with open(filepath("local_datasets.json"), "w") as f:
54 json.dump(dataset_listing, f, indent=2, sort_keys=True)
55
56
57 if __name__ == "__main__":
58 _download_datasets()