forked from neXyon/pynephoscope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
moon.py
69 lines (57 loc) · 1.79 KB
/
moon.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2015-2016 Joerg Hermann Mueller
#
# This file is part of pynephoscope.
#
# pynephoscope 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 3 of the License, or
# (at your option) any later version.
#
# pynephoscope 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 pynephoscope. If not, see <http://www.gnu.org/licenses/>.
import sys
from astropy.coordinates import EarthLocation
from astropy import units as u
from astropy.time import Time
from sky import SkyCatalog
from configuration import Configuration
from skycamerafile import SkyCameraFile
from glob import glob
class MoonChecker:
def __init__(self):
location = EarthLocation(lat=Configuration.latitude, lon=Configuration.longitude, height=Configuration.elevation)
self.catalog = SkyCatalog(False, True)
self.catalog.setLocation(location)
self.now()
def now(self):
self.setTime(Time.now())
def setTime(self, time):
self.catalog.setTime(time)
_, _, alt, _ = self.catalog.calculate()
self.alt = alt[0]
return self.alt
def isUp(self):
return self.alt > Configuration.moon_up_angle
def __str__(self):
if self.isUp():
return "Up"
else:
return "Down"
if __name__ == '__main__':
checker = MoonChecker()
if len(sys.argv) > 1:
files = SkyCameraFile.glob(sys.argv[1])
for f in files:
time = SkyCameraFile.parseTime(f)
checker.setTime(time)
print(f, checker)
else:
print(checker)