forked from rodegerdts/Pyalmanac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tables.py
executable file
·285 lines (244 loc) · 11.4 KB
/
tables.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#! /usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (C) 2014 Enno Rodegerdts
# This program 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.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#import ephem
#import math
from alma_ephem import *
def planetstab(date):
"""generates a latex table for the navigational plantets"""
tab = r'''\noindent
\begin{tabular*}{0.75\textwidth}[t]{@{\extracolsep{\fill}}|c|r|rr|rr|rr|rr|}
\multicolumn{1}{c}{\normalsize{}} & \multicolumn{1}{c}{\normalsize{Aries}} & \multicolumn{2}{c}{\normalsize{Venus}}& \multicolumn{2}{c}{\normalsize{Mars}} & \multicolumn{2}{c}{\normalsize{Jupiter}} & \multicolumn{2}{c}{\normalsize{Saturn}}\\
'''
d = 0
while d < 3:
da = date+d
tab = tab + r'''\hline
\hline
\textbf{%s} & \multicolumn{1}{c|}{\textbf{GHA}} & \multicolumn{1}{c}{\textbf{GHA}} & \multicolumn{1}{c|}{\textbf{Dec}} & \multicolumn{1}{c}{\textbf{GHA}} & \multicolumn{1}{c|}{\textbf{Dec}}& \multicolumn{1}{c}{\textbf{GHA}} & \multicolumn{1}{c|}{\textbf{Dec}}& \multicolumn{1}{c}{\textbf{GHA}} & \multicolumn{1}{c|}{\textbf{Dec}} \\
\hline
''' %(ephem.date(da).datetime().strftime("%a"))
h = 0
while h < 24:
eph = planets(da)
line = "%s & %s & %s & %s & %s & %s & %s & %s & %s & %s\\\ \n" %(h,eph[0],eph[1],eph[2],eph[3],eph[4],eph[5],eph[6],eph[7],eph[8])
tab = tab + line
h += 1
da = da+ephem.hour
vd = vdmean(date+d)
tab = tab + r"""\hline
\multicolumn{2}{|c|}{Mer.pass.:%s}& \multicolumn{2}{c|}{v%s d%s m%s}& \multicolumn{2}{c|}{v%s d%s m%s} & \multicolumn{2}{c|}{v%s d%s m%s} & \multicolumn{2}{c|}{v%s d%s m%s}\\
\hline
\multicolumn{10}{c}{}\\
""" %(ariestransit(date+d),vd[3],vd[4],vd[5],vd[6],vd[7],vd[8],vd[9],vd[10],vd[11],vd[12],vd[13],vd[14])
d = d + 1
tab = tab+r"""\end{tabular*}
"""
return tab
def starstab(date):
"""returns a table with ephemerieds for the navigational stars
"""
out = r"""\begin{tabular*}{0.25\textwidth}[t]{@{\extracolsep{\fill}}|rrr|}
\multicolumn{3}{c}{\normalsize{Stars}} \\
\hline
\hline
& \multicolumn{1}{c}{\textbf{SHA}} & \multicolumn{1}{c|}{\textbf{Dec}} \\
\hline
"""
stars = stellar(date+1)
for i in range(len(stars)):
out = out + r"""%s & %s & %s \\""" %(stars[i][0],stars[i][1],stars[i][2])
out = out + '\n'
m = '\\hline\n'
for i in range(3):
datex = str(ephem.date(date + i))
m = m + '\\hline \n'
m = m + ''' %s & \\textbf{SHA} & \\textbf{Mer.pass} \\\ \n''' %datex[0:8]
p = planetstransit(datex)
m = m + 'Venus & %s & %s \\\ \n' %(p[0],p[1])
m = m + 'Mars & %s & %s \\\ \n' %(p[2],p[3])
m = m + 'Jupiter & %s & %s \\\ \n' %(p[4],p[5])
m = m + 'Saturn & %s & %s \\\ \n' %(p[6],p[7])
m = m + '\\hline \n'
out = out + m
hp = '\\hline \n'
hp = hp + '\multicolumn{2}{|r}{\\textbf{Horizontal paralax}} & \multicolumn{1}{c|}{}\\\ \n '
hp = hp + '\multicolumn{2}{|r}{Venus:} & \multicolumn{1}{c|}{%s} \\\ \n' %(p[9])
hp = hp + '\multicolumn{2}{|r}{Mars:} & \multicolumn{1}{c|}{%s} \\\ \n' %(p[8])
hp = hp + '\\hline \n'
out = out + hp
out = out + r'\end{tabular*}'
return out
def sunmoontab(date):
"""generates LaTeX table for sun and moon
"""
tab = r'''\noindent
\begin{tabular*}{0.55\textwidth}[t]{@{\extracolsep{\fill}}|c|rr|rrrrr|}
\multicolumn{1}{c}{\normalsize{h}}& \multicolumn{2}{c}{\normalsize{Sun}} & \multicolumn{5}{c}{\normalsize{Moon}} \\
'''
d = 0
while d < 3:
tab = tab + r'''\hline
\hline
\multicolumn{1}{|c|}{\textbf{%s}} &\multicolumn{1}{c}{\textbf{GHA}} & \multicolumn{1}{c|}{\textbf{Dec}} & \multicolumn{1}{c}{\textbf{GHA}} & \multicolumn{1}{c}{\textbf{\(\nu\)}} & \multicolumn{1}{c}{\textbf{Dec}} & \multicolumn{1}{c}{\textbf{d}} & \multicolumn{1}{c|}{\textbf{HP}} \\
\hline
''' %(ephem.date(date+d).datetime().strftime("%a"))
da = date+d
h = 0
while h < 24:
eph = sunmoon(da)
line = "%s & %s & %s & %s & %s & %s & %s & %s \\\ \n" %(h,eph[0],eph[1],eph[2],eph[3],eph[4],eph[5],eph[6])
tab = tab + line
h += 1
da = da+ephem.hour
vd = vdmean(date+d)
tab = tab + r"""\hline
& \multicolumn{1}{c}{SD.=%s} & \multicolumn{1}{c|}{d=%s} & \multicolumn{5}{c|}{S.D.=%s} \\
\hline
\multicolumn{7}{c}{}\\
""" %(vd[1],vd[0],vd[2])
d = d + 1
tab = tab+r"""\end{tabular*}"""
return tab
def twilighttab(date):
"""returns the twilight and moonristables"""
lat = [72,70,68,66,64,62,60,58,56,54,52,50,45,40,35,30,20,10,0,-10,-20,-30,-35,-40,-45,-50,-52,-54,-56,-58,-60]
tab = r'''\begin{tabular*}{0.45\textwidth}[t]{@{\extracolsep{\fill}}|c|ccc|ccc|}
\multicolumn{7}{c}{\normalsize{}} \\
\hline
\hline
\multicolumn{1}{|c|}{} & \multicolumn{2}{c}{\textbf{Twilight}} & \multicolumn{1}{c|}{} & \multicolumn{1}{c}{} & \multicolumn{2}{c|}{\textbf{Twilight}} \\
\multicolumn{1}{|c|}{\textbf{Lat.}} &\multicolumn{1}{c}{Naut.} & \multicolumn{1}{c}{Civil} & \multicolumn{1}{c|}{Sunrise} & \multicolumn{1}{c}{Sunset} & \multicolumn{1}{c}{Civil} &\multicolumn{1}{c|}{Naut.}\\
\hline
'''
for i in lat:
twi = twilight(date+1,i)
line = "%s & %s & %s & %s & %s & %s & %s \\\ \n" %(i,twi[0],twi[1],twi[2],twi[4],twi[5],twi[6])
tab = tab+line
weekday = [ephem.date(date).datetime().strftime("%a"),ephem.date(date+1).datetime().strftime("%a"),ephem.date(date+2).datetime().strftime("%a")]
tab = tab + r"""\hline
\multicolumn{7}{c}{}\\
\hline
\hline
\multicolumn{1}{|c|}{} & \multicolumn{3}{c|}{\textbf{Moonrise}} & \multicolumn{3}{c|}{\textbf{Moonset}} \\
\multicolumn{1}{|c|}{\textbf{Lat.}} &\multicolumn{1}{c}{%s} & \multicolumn{1}{c}{%s} & \multicolumn{1}{c|}{%s} & \multicolumn{1}{c}{%s} & \multicolumn{1}{c}{%s} &\multicolumn{1}{c|}{%s} \\
\hline
""" %(weekday[0],weekday[1],weekday[2],weekday[0],weekday[1],weekday[2],)
moon = [0,0,0,0,0,0]
for j in lat:
moon = moonrise(date,j)
tab=tab+"%s & %s & %s & %s & %s & %s & %s \\\ \n" %(j,moon[0],moon[1],moon[2],moon[3],moon[4],moon[5])
tab = tab + r"""\hline
\multicolumn{7}{c}{}\\
\hline
\hline
\multicolumn{1}{|c|}{} & \multicolumn{3}{c|}{\textbf{Sun}} & \multicolumn{3}{c|}{\textbf{Moon}} \\
\multicolumn{1}{|c|}{\textbf{Day}} &\multicolumn{2}{c}{Eqn.of Time} & \multicolumn{1}{c|}{Mer.} & \multicolumn{2}{c}{Mer.Pass.} & \multicolumn{1}{c|}{Age} \\
\multicolumn{1}{|c|}{} &\multicolumn{1}{c}{00\textsuperscript{h}} & \multicolumn{1}{c}{12\textsuperscript{h}} & \multicolumn{1}{c|}{Pass} & \multicolumn{1}{c}{Upper} & \multicolumn{1}{c}{Lower} &\multicolumn{1}{c|}{} \\
\hline
"""
for k in range(3):
d = ephem.date(date+k)
eq = equation_of_time(d)
tab = tab + "%s & %s & %s & %s & %s & %s & %s(%s\\%%) \\\ \n" %(d.tuple()[2],eq[0],eq[1],eq[2],eq[3],eq[4],eq[5],eq[6])
tab = tab + r"""\hline
\end{tabular*}
"""
return tab
def dobblepage(date):
"""creates a dobblepage(3 days) of the nautical almanac
"""
page = r"""\sffamily
\noindent
\textbf{%s, %s ,%s (%s., %s., %s.)}
\begin{scriptsize}
""" %(ephem.date(date).datetime().strftime("%B %d"),ephem.date(date+1).datetime().strftime("%d"),ephem.date(date+2).datetime().strftime("%d"),ephem.date(date).datetime().strftime("%a"),ephem.date(date+1).datetime().strftime("%a"),ephem.date(date+2).datetime().strftime("%a"))
page = page + planetstab(date)
page = page + starstab(date)
page = page + r""" \end{scriptsize}
\newpage
\begin{flushright}
\textbf{%s to %s}
\end{flushright}
\begin{scriptsize}
""" %(ephem.date(date).datetime().strftime("%Y %B %d"),ephem.date(date+2).datetime().strftime("%b. %d"))
page = page + sunmoontab(date)
page = page + twilighttab(date)
page = page + r"""\end{scriptsize}
\newpage
"""
return page
def pages(date,p):
"""make i dobblepages beginning with date"""
d = ephem.date(date)
out = ''
for i in range(p):
out = out + dobblepage(d)
d = d +3
return out
def almanac(year):
"""make almanak from date til date"""
alm = r"""\documentclass[10pt, twoside, a4paper]{report}
\usepackage[utf8x]{inputenc}
\usepackage[english]{babel}
\usepackage{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{siunitx}
\usepackage{longtable}
\usepackage{multicol}
\usepackage[ top=25mm, bottom=25mm, left=18mm, right=8mm]{geometry}
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}
\usepackage[pdftex]{graphicx}
\begin{document}
\begin{titlepage}
\begin{center}
\textsc{\Large Generated by PyAlmanac}\\[1.5cm]
\includegraphics[width=0.4\textwidth]{./images/Navigational-stars-north}\\[1cm]
\textsc{\huge The Nautical Almanac}\\[0.7cm]
\HRule \\[0.6cm]
{\large Generated: \today}
\HRule \\[0.6cm]
\end{center}
\begin{description}\tiny
\item[Disclaimer:] These are computer generated tables. Use at your own risk.
The software and the tables generated by the software are without any warranty
whatsoever, please see the GNU Public Licence v.2 for more information.
\end{description}
\end{titlepage}
\vfill
Generated using PyAlmanac-st599 which is available via Github: https://github.com/st599/Pyalmanac
Pyalmanac-st599 is a Python script that creates the daily pages of the Nautical Almanac. These are tables that are needed for celestial navigation with a Sextant.
This fork of the original code (which can be found at: https://github.com/rodegerdts/Pyalmanac) aims to include a brief guide to celestial navigation and tables of other numbers required to take a sextant measurement and produce a line of position.
\section*{WARNING}
These tables are generated without warranty or guarantee and should be used with caution. The original author states on his web page (https://sv-inua.net/the-nautical-almanac) that he has tested the code against a 2009 Nautical Almanac (which is published by the UK and US) and could not find any errors over 0.3'.
Requirements
Most of the heavy computing is done by the free Pyephem library. Typesetting is done by TeX/LaTeX So before you can use this program you need to install:
\begin{itemize}
\item Python v2.x (2.6 or later ) python 3 will not work out of the box
\item PyEphem
\item TeX/LaTeX
\end{itemize}
\newpage
\include{./additional_pages/navigational_stars1}
\include{./additional_pages/navigational_maths}
\newpage
""" #%(year)
y = ephem.date(str(year))
alm = alm + pages(y,122)
alm = alm + '\end{document}'
return alm