-
Notifications
You must be signed in to change notification settings - Fork 1
/
alcor.py
119 lines (111 loc) · 3.25 KB
/
alcor.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
#!/usr/local/python/bin/python
#
# Description:
# Script to observe with the Alcor all-sky camera
# This script applies one exptime during the day
# and another for night time.
#
# The main day/night settings are set in the
# config files in the Git repo. Check there for
# device and image settings.
#
# To do:
# add Pyro support
# add long term archiving
# run some image analysis in another subprocess?
# add logging
#
import os, time
import signal, subprocess
from astropy.time import Time
from astropy.coordinates import EarthLocation, AltAz
from astropy.coordinates import get_sun
from datetime import datetime as dt
import astropy.units as u
import argparse as ap
import warnings
warnings.filterwarnings('ignore')
# edit here
image_dir="/home/ops/allskycam"
# observatory set up
olat=-24.-(37./60.)-(38./3600.)
olon=-70.-(24./60.)-(15./3600.)
elev=2418.
obsloc=EarthLocation(lat=olat*u.deg,lon=olon*u.deg,height=elev*u.m)
# parse command line
def argParse():
description="""
Alcor all-sky camera control script.
Camera control is done using fswebcam. Edit camera\'s day/night
settings using the fswebcam .conf files in the Git repo.
"""
parser=ap.ArgumentParser(description=description)
parser.add_argument("--sunalt",type=int,help="Sun altitude limit for day/night transition")
parser.add_argument("--debug",help="Run in deugging mode",action="store_true")
parser.add_argument("--v",help="Increased verbosity",action="store_true")
return parser.parse_args()
# pre imaging checks
args=argParse()
if args.sunalt:
sun_alt_limit = args.sunalt
else:
sun_alt_limit = -5
if os.path.exists(image_dir) == False:
os.mkdir(image_dir)
live_image="%s/allsky.jpeg" % (image_dir)
die=False
# work out if it is day or night time
# based on the current Sun altitude
def dayOrNight():
tnow=Time(dt.utcnow(),scale='utc')
altazframe = AltAz(obstime=tnow, location=obsloc)
sunaltaz = get_sun(tnow).transform_to(altazframe)
sunalt=sunaltaz.alt.deg
if sunalt <= sun_alt_limit:
result='night'
else:
result='day'
if args.v:
print "%s - Sun altitude: %.2f - %s" % (dt.utcnow(),sunalt,result)
return result
# set up Ctrl+C handling
def signalHandler(signal,frame):
global die
print "Ctrl+C caught, exiting..."
die=True
signal.signal(signal.SIGINT,signalHandler)
# main function
def main():
global die
don=dayOrNight()
comm='fswebcam -c paranal_%s.conf' % (don)
if args.v:
print "%s - %s" % (dt.utcnow(),comm)
if not args.debug:
pro=subprocess.Popen(comm,subprocess.PIPE,shell=True,preexec_fn=os.setsid)
while(1):
don_new=dayOrNight()
# change from day to night, and vice versa
if don_new != don:
if args.v:
print "%s - Changing the settings to %s" % (dt.utcnow(),don)
if not args.debug:
os.killpg(os.getpgid(pro.pid), signal.SIGTERM)
time.sleep(30)
comm='fswebcam -c paranal_%s.conf' % (don_new)
if args.v:
print "%s - %s" % (dt.utcnow(),comm)
if not args.debug:
pro=subprocess.Popen(comm,subprocess.PIPE,shell=True,preexec_fn=os.setsid)
don=don_new
# wait for 5 mins between checks for change in day/night
time.sleep(300)
# if ctrl+c, die correctly
if die == True:
print "Killing fswebcam"
if not args.debug:
os.killpg(os.getpgid(pro.pid), signal.SIGTERM)
print "Exiting..."
break
if __name__ == '__main__':
main()