-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinca_lunar.py
151 lines (120 loc) · 4.36 KB
/
inca_lunar.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
#!/usr/bin/python3
#
# Convert between the Inca civil calendar and Julian Day
#
from fractions import *
from math import floor, ceil
MONTHS_NORMAL = ("Intiraymipacha", "Pachacyahuarllamapacha", "Yapuypacha", "Coyaraymipacha", "Paramañaypacha", "Ayamarcaypacha", "Capacintiraymipacha", "Huacapacha", "Huarachicuypacha", "Paraypacha", "Rinrituccinapacha", "Aymuraypacha")
MONTHS_LEAP = ("Intiraymipacha", "Pachacyahuarllamapacha", "Yapuypacha", "Coyaraymipacha", "Paramañaypacha", "Ayamarcaypacha", "Capacintiraymipacha", "Huacapacha", "Huarachicuypacha", "Paraypacha", "Rinrituccinapacha", "Aymuraypacha", "Intihuatapacyapanapacha")
monlen = 29 + Fraction(12,24) + Fraction(44,1440) + Fraction(28,864000)
eqlen = 365 + Fraction(5,24) + Fraction(48,1440) + Fraction(45,86400)
year12 = 12 * monlen
year13 = 13 * monlen
solar_epoch = Fraction(6065414981, 2700) - Fraction(5,24) + 1 # southern solstice in 1438 AD, corrected for Peruvian time
lunar_epoch = Fraction(485229140243, 216000) + Fraction(5,24) + 1 # new moon before the souther solstice of 1438 AD, corrected for Peruvian time
def tojd(day, month, year):
"""Convert a date in the Inca civil calendar to a Julian Day."""
day = int(day)
month = month
year = int(year)
curryear = False
if year >= 0:
# positive dates
equinox = ((year - 1) * eqlen) + solar_epoch
lunations = (equinox - lunar_epoch) // monlen
jday = (lunations * monlen) + lunar_epoch
while ceil(jday + monlen) < floor(equinox):
jday += monlen
# jday is now the new moon of the first month in the year in question. Is the year in question a leap year?
if ceil(jday + year13) <= floor(equinox + eqlen):
# leap year
m = MONTHS_LEAP
else:
# not a leap year
m = MONTHS_NORMAL
if month not in m:
month = "Aymuraypacha"
else:
# negative years
equinox = (year * eqlen) + solar_epoch
lunations = (lunar_epoch - equinox) // monlen
jday = lunar_epoch - (lunations * monlen)
while ceil(jday) > floor(equinox):
jday -= monlen
# jday is now the new moon of the first month of the year in question. Is it a leap year?
if ceil(jday + year13) <= floor(equinox + eqlen):
# leap year
m = MONTHS_LEAP
else:
# not a leap year
m = MONTHS_NORMAL
if month not in m:
month = "Aymuraypacha"
for i in m:
if i == month:
jday = ceil(jday) + day - 1
break
else:
jday += monlen
return jday
def fromjd(jday):
"""Convert a Julian Day to a date in the Babylonian calendar"""
jday = int(jday)
day = 0
month = ""
year = 0
curryear = False
equinox = solar_epoch
raymi = lunar_epoch
if jday >= ceil(lunar_epoch):
# positive dates
year = 1
while curryear == False:
nexteq = equinox + eqlen
if ceil(raymi + year13) < floor(nexteq):
next_raymi = raymi + year13
else:
next_raymi = raymi + year12
if jday < int(next_raymi):
curryear = True
else:
year += 1
equinox = nexteq
raymi = next_raymi
# check if it's a leap year
if int(raymi + year13) <= int(equinox + eqlen):
# leap year
m = MONTHS_LEAP
else:
# not a leap year
m = MONTHS_NORMAL
else:
# negative dates
while ceil(raymi) > jday:
year -= 1
equinox -= eqlen
if raymi - year12 < equinox:
raymi -= year12
else:
raymi -= year13
# right, now what type of year is it?
nexteq = equinox + eqlen
if raymi + year13 < nexteq:
# leap year
m = MONTHS_LEAP
else:
# not a leap year
m = MONTHS_NORMAL
newmoon = raymi
nextmoon = newmoon + monlen
for i in m:
crescent = ceil(newmoon)
next_crescent = ceil(nextmoon)
if jday < next_crescent:
month = i
day = floor(jday) - crescent + 1
break
else:
newmoon += monlen
nextmoon += monlen
return (day, month, year)