Skip to content

Commit

Permalink
fixed globals
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Lucke committed Feb 26, 2024
1 parent a741ba8 commit a035b6f
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 87 deletions.
90 changes: 85 additions & 5 deletions almanac.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import atexit
import pickle
from collections import defaultdict
Expand All @@ -19,9 +19,17 @@

from corrections import *
from formatting import *
from plots import *

__version__ = "0.2"
from datetime import datetime, timedelta
from os.path import isfile

import seaborn as sns
from matplotlib import use
from matplotlib.pyplot import figure, plot, title, xlabel, ylabel, gca, xlim, ylim, savefig, tight_layout, legend
from numpy import array, nan
from progress.bar import Bar

__version__ = "0.2.1"

planets = "Venus", "Mars", "Jupiter", "Saturn"

Expand Down Expand Up @@ -93,7 +101,7 @@ def iers_info(kind, mode):


ARIES = "Aries"

ts=None

def init(iers_time=True, polar_motion=True, ephemeris="de440s", cache=None):
"initialize SkyField and Almanac global state"
Expand Down Expand Up @@ -482,6 +490,75 @@ def render(template, variables={}, progress=None):
return template.generate()


def eqot_img(year, filename=None, size=(16, 9)):
sns.set_theme(context="notebook", style="whitegrid")
if filename:
if isfile(filename): return filename
use("Agg")
eqot = []
xticks = []
xlabels = []
for d in Bar(filename or "Equation of Time Graph", max=365, suffix="%(percent)d%% %(eta_td)s").iter(range(365)):
t = datetime(year, 1, 1) + timedelta(days=d)
if t.day in [1, 10, 20]:
xticks.append(d)
xlabels.append(f"{t:%b}" if t.day == 1 else t.day)
eqot.append(equation_of_time(t) * 60)

figure(figsize=size)
plot(eqot)
title(f"Equation of Time {year}")
xlabel("month of year")
ylabel("solar time - mean time (UT1) [minutes]")
xlim(0, 364)
gca().set_xticks(xticks, xlabels)
tight_layout()
if filename:
savefig(filename, pad_inches=0)
return filename


def mp_img(year, filename=None, size=(16, 9)):
sns.set_theme(context="notebook", style="whitegrid")
if filename:
if isfile(filename): return filename
use("Agg")
dashes = {"Sun": [],
"Jupiter": [6, 2],
"Saturn": [1, 2],
"Venus": [1, 2, 1, 2, 6, 2],
"Mars": [1, 2, 6, 2, 6, 2],
"Mercury": [1, 2, 6, 2], }
mp = {p: [] for p in dashes.keys()}
xticks = []
xlabels = []
for d in Bar(filename or "Meridian Passages Graph", max=365, suffix="%(percent)d%% %(eta_td)s").iter(range(365)):
t = datetime(year, 1, 1) + timedelta(days=d)
if t.day in [1, 10, 20]:
xticks.append(d)
xlabels.append(f"{t:%b}" if t.day == 1 else t.day)
for p in mp.keys():
mp[p].append(meridian_passage(t, p))

figure(figsize=size)
for p, d in mp.items():
d = array(d)
d[d > 23.8] = nan
plot(d, label=p, dashes=dashes[p])
title(f"Meridian Passages {year}")
xlabel("month of year")
ylabel("MP [hours]")
xlim(0, 364)
ylim(0, 24)
legend()
gca().set_xticks(xticks, xlabels)
yticks = 0, 3, 6, 9, 12, 15, 18, 21
gca().set_yticks(yticks, yticks)
tight_layout()
if filename:
savefig(filename, pad_inches=0)
return filename

def calculate():
import pyinputplus as pyip

Expand Down Expand Up @@ -537,6 +614,7 @@ def process(template, out, variables, progress=None):
# progress(1)
# return
init(variables["iers_time"], variables["polar_motion"], variables["ephemeris"], variables["cache"])

if out == "-":
for l in render(template, variables, progress):
print(l, end="")
Expand Down Expand Up @@ -614,13 +692,15 @@ def main():
parser.add_argument("-e", "--ephemeris", metavar="file", default="de440s", help="ephemeris file to use")
parser.add_argument("-C", "--calculate", action="store_true", help="interactive sight reduction calculation")
parser.add_argument("-p", "--parallel", type=int, default=1, help="number of parallel processes to use")
parser.add_argument("-m", "--multiple", type=int, default=3, help="number of parallel processes to use")
parser.add_argument("-m", "--multiple", type=int, default=3,
help="number of days to process together, smallest chunk size when splitting for parallel processing")
parser.add_argument("-V", "--version", action="version", version=__version__)
args = parser.parse_args()

iers_time = not args.no_finals
polar_motion = iers_time and not args.no_polar


if args.calculate:
init(iers_time, polar_motion, args.ephemeris, args.cache)
calculate()
Expand Down
8 changes: 6 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ pdf: Nautical-Almanac-$(Y).pdf
txt: daily-pages-$(Y).txt

Nautical-Almanac-$(Y).pdf: nautical-almanac.tex.j2 almanac.py
./almanac.py $< -o $(@:.pdf=.tex) -f -c -y$(Y)
./almanac.py $< -o $(@:.pdf=.tex) -f -c -y$(Y) $(O)
latexmk -pdf $(@:.pdf=.tex) -interaction=batchmode

daily-pages-$(Y).txt: daily-pages.txt.j2 almanac.py
./almanac.py $< -o $@ -f -y$(Y)
./almanac.py $< -o $@ -f -c -y$(Y) $(O)

loop:
while true; do inotifywait -q -e close_write *.j2 *.py makefile; make; done

test:
./test.py
echo PASSED

clean:
latexmk -C
rm -f *.tex
Expand Down
80 changes: 0 additions & 80 deletions plots.py

This file was deleted.

2 changes: 2 additions & 0 deletions test.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python3

import re
from datetime import datetime, timedelta
from os import listdir
Expand Down

0 comments on commit a035b6f

Please sign in to comment.