forked from dcf21/astrolabe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathastrolabe.py
executable file
·146 lines (120 loc) · 6.1 KB
/
astrolabe.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/python3
# astrolabe.py
# -*- coding: utf-8 -*-
#
# The python script in this file makes the various parts of a model astrolabe.
#
# Copyright (C) 2010-2022 Dominic Ford <[email protected]>
#
# 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 astrolabes 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 an astrolabe for that latitude, and instructions as to how to put them together.
"""
import os
import subprocess
import time
import text
from climate import Climate
from graphics_context import GraphicsPage, CompositeComponent
from mother_back import MotherBack
from mother_front import MotherFront
from rete import Rete
from rule import Rule
from settings import fetch_command_line_arguments
# Create clean output directory
os.system("rm -Rf output")
os.system("mkdir -p output/astrolabes output/astrolabe_parts")
arguments = fetch_command_line_arguments()
theme = arguments['theme']
# Render astrolabe in all available languages
for language in text.text:
# Render simplified and full astrolabes
for astrolabe_type in ["full", "simplified"]:
# Render climates for latitudes at 5-degree spacings from 10 deg -- 85 deg, plus 52N
for latitude in list(range(-80, 90, 5)) + [52]:
# Do not make equatorial astrolabes, as they don't really work
if -10 < latitude < 10:
continue
# Boolean flag for which hemisphere we're in
southern = latitude < 0
# A dictionary of common substitutions
subs = {
"dir_parts": "output/astrolabe_parts",
"dir_out": "output/astrolabes",
"abs_lat": abs(latitude),
"ns": "S" if southern else "N",
"astrolabe_type": astrolabe_type,
"lang": language,
"lang_short": "" if language == "en" else "_{}".format(language)
}
settings = {
'language': language,
"astrolabe_type": astrolabe_type,
'latitude': latitude,
'theme': theme
}
# Render the parts of the astrolabe that do not change with geographic location
MotherFront(settings=settings).render_all_formats(
filename="{dir_parts}/mother_front_{abs_lat:02d}{ns}_{lang}_{astrolabe_type}".format(**subs)
)
MotherBack(settings=settings).render_all_formats(
filename="{dir_parts}/mother_back_{abs_lat:02d}{ns}_{lang}_{astrolabe_type}".format(**subs)
)
Rete(settings=settings).render_all_formats(
filename="{dir_parts}/rete_{abs_lat:02d}{ns}_{lang}_{astrolabe_type}".format(**subs)
)
Rule(settings=settings).render_all_formats(
filename="{dir_parts}/rule_{abs_lat:02d}{ns}_{lang}_{astrolabe_type}".format(**subs)
)
# Render the climate of the astrolabe
Climate(settings=settings).render_all_formats(
filename="{dir_parts}/climate_{abs_lat:02d}{ns}_{lang}_{astrolabe_type}".format(**subs)
)
# Make combined mother and climate
for img_format in GraphicsPage.supported_formats():
CompositeComponent(
settings=settings,
components=[
MotherFront(settings=settings),
Climate(settings=settings)
]
).render_all_formats(
filename="{dir_parts}/mother_front_combi_{abs_lat:02d}{ns}_{lang}_{astrolabe_type}".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}/mother_back_{abs_lat:02d}{ns}_{lang}_{astrolabe_type}.pdf "
" doc/tmp/mother_back.pdf".format(**subs))
os.system("cp {dir_parts}/mother_front_combi_{abs_lat:02d}{ns}_{lang}_{astrolabe_type}.pdf "
" doc/tmp/mother_front.pdf".format(**subs))
os.system("cp {dir_parts}/rete_{abs_lat:02d}{ns}_{lang}_{astrolabe_type}.pdf "
" doc/tmp/rete.pdf".format(**subs))
os.system("cp {dir_parts}/rule_{abs_lat:02d}{ns}_{lang}_{astrolabe_type}.pdf "
" doc/tmp/rule.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 astrolabe.tex", shell=True)
os.system("mv doc/astrolabe.pdf "
" {dir_out}/astrolabe_{abs_lat:02d}{ns}_{lang}_{astrolabe_type}.pdf".format(**subs))
# For the English language astrolabe, create a symlink with no language suffix in the filename
if language == "en" and astrolabe_type == "full":
os.system("ln -s astrolabe_{abs_lat:02d}{ns}_en_full.pdf "
"{dir_out}/astrolabe_{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")