Repository navigation
Expand file tree
/
Copy pathexamples.py
More file actions
executable file
·74 lines (52 loc) · 1.73 KB
/
Copy pathexamples.py
File metadata and controls
executable file
·74 lines (52 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""Runs examples from documentation and copies the image to the docs directory"""
import subprocess
import glob
import time
from PIL import Image
from multiprocessing import Pool
from starplot.data.catalogs import download_all_catalogs
skip = [
"map_comet_neowise.py",
"horizon_sgr.py",
"optic_moon_saturn.py",
# "map_orthographic.py",
"galaxy_custom_marker.py",
# "map_milky_way_stars.py",
# "stuff.py",
]
def thumbnail(filename, max_dimension=900):
print(filename)
img = Image.open(filename)
img.thumbnail((max_dimension, max_dimension), Image.LANCZOS)
img.save(f"{filename[:-4]}-sm.png", optimize=True)
def get_example_names():
filenames = []
for filename in glob.iglob("*.py"):
# if filename not in ["map_virgo_cluster.py"]:
# continue
if filename.endswith("examples.py"):
continue
if filename in skip:
continue
filenames.append(filename)
return filenames
def run_example(filename):
print(f"Running {filename}")
subprocess.call(["python", filename])
if __name__ == "__main__":
num_workers = 4
start = time.time()
example_files = get_example_names()
processes = []
# download catalogs if they dont exist
download_all_catalogs(silent=True)
with Pool(num_workers) as pool:
pool.map(run_example, example_files)
# Create thumbnail images for the examples list page
image_files = glob.glob("*.png")
pool = Pool(num_workers)
results = pool.map(thumbnail, image_files)
# Copy all images to docs directory
print("Copying images to examples directory...")
subprocess.call("cp *.png *.svg ../docs/images/examples/", shell=True)
print(f"{time.time() - start}")