-
Notifications
You must be signed in to change notification settings - Fork 29
/
planisphere.py
executable file
·117 lines (93 loc) · 4.49 KB
/
planisphere.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/python3
# planisphere.py
# -*- coding: utf-8 -*-
#
# The python script in this file makes the various parts of a model planisphere.
#
# Copyright (C) 2014-2024 Dominic Ford <https://dcford.org.uk/>
#
# This code is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# You should have received a copy of the GNU General Public License along with
# this file; if not, write to the Free Software Foundation, Inc., 51 Franklin
# Street, Fifth Floor, Boston, MA 02110-1301, USA
# ----------------------------------------------------------------------------
"""
This is the top level script for drawing all the parts needed to build planispheres which work at a range of
different latitudes. They are rendered in PDF, SVG and PNG image formats.
Additionally, we use LaTeX to build a summary document for each latitude, which includes all of the parts needed
to build a planisphere for that latitude, and instructions as to how to put them together.
"""
import os
import subprocess
import time
from typing import Dict, Union
import text
from alt_az import AltAzGrid
from holder import Holder
from settings import fetch_command_line_arguments
from starwheel import StarWheel
# Create output directory
os.system("rm -Rf output")
os.system("mkdir -p output/planispheres output/planisphere_parts")
arguments: Dict[str, Union[int, str]] = fetch_command_line_arguments()
theme: str = arguments['theme']
# Render planisphere in all available languages
language: str
for language in text.text:
# Render climates for latitudes at 5-degree spacings from 10 deg -- 85 deg, plus 52N
latitude: float
for latitude in list(range(-80, 90, 5)) + [52]:
# Do not make equatorial planispheres, as they don't really work
if -10 < latitude < 10:
continue
# Boolean flag for which hemisphere we're in
southern: bool = latitude < 0
# A dictionary of common substitutions
subs: Dict[str, Union[str, float]] = {
"dir_parts": "output/planisphere_parts",
"dir_out": "output/planispheres",
"abs_lat": abs(latitude),
"ns": "S" if southern else "N",
"lang": language,
"lang_short": "" if language == "en" else "_{}".format(language)
}
settings: Dict[str, Union[str, float]] = {
'language': language,
'latitude': latitude,
'theme': theme
}
# Render the various parts of the planisphere
StarWheel(settings=settings).render_all_formats(
filename="{dir_parts}/starwheel_{abs_lat:02d}{ns}_{lang}".format(**subs)
)
Holder(settings=settings).render_all_formats(
filename="{dir_parts}/holder_{abs_lat:02d}{ns}_{lang}".format(**subs)
)
AltAzGrid(settings=settings).render_all_formats(
filename="{dir_parts}/alt_az_grid_{abs_lat:02d}{ns}_{lang}".format(**subs)
)
# Copy the PDF versions of the components of this astrolabe into LaTeX's working directory, to produce a
# PDF file containing all the parts of this astrolabe
os.system("mkdir -p doc/tmp")
os.system("cp {dir_parts}/starwheel_{abs_lat:02d}{ns}_{lang}.pdf doc/tmp/starwheel.pdf".format(**subs))
os.system("cp {dir_parts}/holder_{abs_lat:02d}{ns}_{lang}.pdf doc/tmp/holder.pdf".format(**subs))
os.system("cp {dir_parts}/alt_az_grid_{abs_lat:02d}{ns}_{lang}.pdf doc/tmp/altaz.pdf".format(**subs))
with open("doc/tmp/lat.tex", "wt") as f:
f.write(r"${abs_lat:d}^\circ${ns}".format(**subs))
# Wait for cairo to wake up and close the files
time.sleep(1)
# Build LaTeX documentation
for build_pass in range(3):
subprocess.check_output("cd doc ; pdflatex planisphere{lang_short}.tex".format(**subs), shell=True)
os.system("mv doc/planisphere{lang_short}.pdf "
"{dir_out}/planisphere_{abs_lat:02d}{ns}_{lang}.pdf".format(**subs))
# For the English language planisphere, create a symlink with no language suffix in the filename
if language == "en":
os.system("ln -s planisphere_{abs_lat:02d}{ns}_en.pdf "
"{dir_out}/planisphere_{abs_lat:02d}{ns}.pdf".format(**subs))
# Clean up the rubbish that LaTeX leaves behind
os.system("cd doc ; rm -f *.aux *.log *.dvi *.ps *.pdf")