-
Notifications
You must be signed in to change notification settings - Fork 4
/
jieqi.py
147 lines (131 loc) · 6.72 KB
/
jieqi.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
# -*- coding: utf-8 -*-
"""
Created on Tue May 9 20:32:01 2023
@author: kentang
"""
import re
import math
import ephem
from ephem import Sun, Date, Ecliptic, Equatorial
import config
jieqi_name = re.findall('..', '春分清明穀雨立夏小滿芒種夏至小暑大暑立秋處暑白露秋分寒露霜降立冬小雪大雪冬至小寒大寒立春雨水驚蟄')
def ecliptic_lon(jd_utc):
s=Sun(jd_utc)
equ=Equatorial(s.ra,s.dec,epoch=jd_utc)
e=Ecliptic(equ)
return e.lon
def sta(jd):
e=ecliptic_lon(jd)
n=int(e*180.0/math.pi/15)
return n
def iteration(jd,sta):
s1=sta(jd)
s0=s1
dt=1.0
while True:
jd+=dt
s=sta(jd)
if s0!=s:
s0=s
dt=-dt/2
if abs(dt)<0.0000001 and s!=s1:
break
return jd
def change(year, month, day, hour, minute):
changets = Date("{}/{}/{} {}:{}:00".format(str(year).zfill(4), str(month).zfill(2), str(day).zfill(2),str(hour).zfill(2), str(minute).zfill(2)))
return Date(changets - 24 * ephem.hour *30)
def jq(year, month, day, hour, minute):#从当前时间开始连续输出未来n个节气的时间
#current = datetime.strptime("{}/{}/{} {}:{}:00".format(str(year).zfill(4), str(month).zfill(2), str(day).zfill(2),str(hour).zfill(2), str(minute).zfill(2)), '%Y/%m/%d %H:%M:%S')
current = Date("{}/{}/{} {}:{}:00".format(str(year).zfill(4), str(month).zfill(2), str(day).zfill(2),str(hour).zfill(2), str(minute).zfill(2)))
jd = change(year, month, day, hour, minute)
#jd = Date("{}/{}/{} {}:{}:00.00".format(str(b.year).zfill(4), str(b.month).zfill(2), str(b.day).zfill(2), str(b.hour).zfill(2), str(b.minute).zfill(2) ))
result = []
e=ecliptic_lon(jd)
n=int(e*180.0/math.pi/15)+1
for i in range(3):
if n>=24:
n-=24
jd=iteration(jd,sta)
d=Date(jd+1/3).tuple()
dt = Date("{}/{}/{} {}:{}:00.00".format(d[0],d[1],d[2],d[3],d[4]).split(".")[0])
time_info = { dt:jieqi_name[n]}
n+=1
result.append(time_info)
j = [list(i.keys())[0] for i in result]
if current > j[0] and current > j[1] and current > j[2]:
return list(result[2].values())[0]
if current > j[0] and current > j[1] and current <= j[2]:
return list(result[1].values())[0]
if current >= j[1] and current < j[2]:
return list(result[1].values())[0]
if current < j[1] and current < j[2]:
return list(result[0].values())[0]
def find_jq_date(year, month, day, hour, minute,jieqi):#从当前时间开始连续输出未来n个节气的时间
current = Date("{}/{}/{} {}:{}:00".format(str(year).zfill(4), str(month).zfill(2), str(day).zfill(2),str(hour).zfill(2), str(minute).zfill(2)))
jd = change(year, month, day, hour, minute)
#jd = Date("{}/{}/{} {}:{}:00.00".format(str(b.year).zfill(4), str(b.month).zfill(2), str(b.day).zfill(2), str(b.hour).zfill(2), str(b.minute).zfill(2) ))
result = {}
e=ecliptic_lon(jd)
n=int(e*180.0/math.pi/15)+1
for i in range(24):
if n>=24:
n-=24
jd=iteration(jd,sta)
d=Date(jd+1/3).tuple()
dt = Date("{}/{}/{} {}:{}:00.00".format(d[0],d[1],d[2],d[3],d[4]).split(".")[0])
time_info = { jieqi_name[n]:dt}
n+=1
result.update(time_info)
return Date(result.get(jieqi))
def gong_wangzhuai():
wangzhuai = list("旺相胎沒死囚休廢")
wangzhuai_num = [3,4,9,2,7,6,1,8]
wangzhuai_jieqi = {('春分','清明','穀雨'):'春分',
('立夏','小滿','芒種'):'立夏',
('夏至','小暑','大暑'):'夏至',
('立秋','處暑','白露'):'立秋',
('秋分','寒露','霜降'):'秋分',
('立冬','小雪','大雪'):'立冬',
('冬至','小寒','大寒'):'冬至',
('立春','雨水','驚蟄'):'立春'}
return dict(zip(config.new_list(wangzhuai_num, dict(zip(jieqi_name[0::3],wangzhuai_num )).get(config.multi_key_dict_get(wangzhuai_jieqi, "霜降"))), wangzhuai))
def xzdistance(year, month, day, hour):
return int(find_jq_date(year, month, day, hour, "夏至") - Date("{}/{}/{} {}:00:00.00".format(str(year).zfill(4), str(month).zfill(2), str(day).zfill(2), str(hour).zfill(2))))
def distancejq(year, month, day, hour, minute, jq):
return int( Date("{}/{}/{} {}:{}:00.00".format(str(year).zfill(4), str(month).zfill(2), str(day).zfill(2), str(hour).zfill(2), str(minute).zfill(2))) - find_jq_date(year-1, month, day, hour, minute, jq) )
def jq_count_days(year, month, day, hour, minute):#从当前时间开始连续输出未来n个节气的时间
#current = datetime.strptime("{}/{}/{} {}:{}:00".format(str(year).zfill(4), str(month).zfill(2), str(day).zfill(2),str(hour).zfill(2), str(minute).zfill(2)), '%Y/%m/%d %H:%M:%S')
current = Date("{}/{}/{} {}:{}:00".format(str(year).zfill(4), str(month).zfill(2), str(day).zfill(2),str(hour).zfill(2), str(minute).zfill(2)))
jd = change(year, month, day, hour, minute)
#jd = Date("{}/{}/{} {}:{}:00.00".format(str(b.year).zfill(4), str(b.month).zfill(2), str(b.day).zfill(2), str(b.hour).zfill(2), str(b.minute).zfill(2) ))
result = []
e=ecliptic_lon(jd)
n=int(e*180.0/math.pi/15)+1
for i in range(3):
if n>=24:
n-=24
jd=iteration(jd,sta)
d=Date(jd+1/3).tuple()
dt = Date("{}/{}/{} {}:{}:00.00".format(d[0],d[1],d[2],d[3],d[4]).split(".")[0])
time_info = { dt:jieqi_name[n]}
n+=1
result.append(time_info)
j = [list(i.keys())[0] for i in result]
if current > j[0] and current > j[1] and current > j[2]:
return list(result[2].values())[0], int(current - list(result[2].keys())[0] )
if current > j[0] and current > j[1] and current <= j[2]:
return int(current - list(result[1].keys())[0] )+1
if current >= j[1] and current < j[2]:
return list(result[1].values())[0], int(current - list(result[1].keys())[0] )
if current < j[1] and current < j[2]:
return list(result[0].values())[0], int(current - list(result[0].keys())[0] )
def fjqs(year, month, day, hour):
jd_format = Date("{}/{}/{} {}:00:00.00".format(str(year).zfill(4), str(month).zfill(2), str(day).zfill(2), str(hour).zfill(2) ))
n= int(ecliptic_lon(jd_format)*180.0/pi/15)+1
c = []
for i in range(1):
if n>=24:
n-=24
d = Date(jd_format+1/3).tuple()
c.append([jieqi_name[n], Date("{}/{}/{} {}:{}:00.00".format(str(d[0]).zfill(4), str(d[1]).zfill(2), str(d[2]).zfill(2), str(d[3]).zfill(2) , str(d[4]).zfill(2)))])
return c[0]