Skip to content

Commit

Permalink
Merge branch 'horizonFeatures' of https://github.com/brendanorenstein…
Browse files Browse the repository at this point in the history
…/POCS into horizonFeatures
  • Loading branch information
brendan-o committed Jun 4, 2017
2 parents 81aecff + e17d7ec commit 0ee03f3
Show file tree
Hide file tree
Showing 24 changed files with 810 additions and 448 deletions.
350 changes: 304 additions & 46 deletions bin/pocs_shell

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions conf_files/pocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ location:
- !!python/tuple [350,80] #List of azimuth, elevation tuples (Degrees)
twilight_horizon: -18 # Degrees
timezone: US/Hawaii
gmt_offset: -600
directories:
base: /var/panoptes
images: images
Expand Down
12 changes: 8 additions & 4 deletions pocs/camera/canon_gphoto2.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ def take_observation(self, observation, headers=None, filename=None, **kwargs):
}
metadata.update(headers)
exp_time = kwargs.get('exp_time', observation.exp_time.value)
self.take_exposure(seconds=exp_time, filename=file_path)
proc = self.take_exposure(seconds=exp_time, filename=file_path)

# Process the image after a set amount of time
wait_time = exp_time + self.readout_time
t = Timer(wait_time, self.process_exposure, (metadata, camera_event,))
t = Timer(wait_time, self.process_exposure, (metadata, camera_event, proc))
t.name = '{}Thread'.format(self.name)
t.start()

Expand Down Expand Up @@ -183,7 +183,7 @@ def take_exposure(self, seconds=1.0 * u.second, filename=None):
else:
return proc

def process_exposure(self, info, signal_event):
def process_exposure(self, info, signal_event, exposure_process=None):
"""Processes the exposure
Converts the CR2 to a FITS file. If the camera is a primary camera, extract the
Expand All @@ -195,7 +195,11 @@ def process_exposure(self, info, signal_event):
signal_event (threading.Event): An event that is set signifying that the
camera is done with this exposure
"""
if exposure_process:
exposure_process.wait()

image_id = info['image_id']
seq_id = info['sequence_id']
file_path = info['file_path']
self.logger.debug("Processing {}".format(image_id))

Expand Down Expand Up @@ -224,7 +228,7 @@ def process_exposure(self, info, signal_event):
'data': info,
'date': current_time(datetime=True),
'type': 'observations',
'image_id': image_id,
'sequence_id': seq_id,
})

# Mark the event as done
Expand Down
10 changes: 6 additions & 4 deletions pocs/camera/simulator.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import os
import subprocess
import random

from threading import Event
from threading import Timer
import random

import numpy as np

Expand All @@ -12,7 +11,6 @@
from astropy.time import Time

from ..utils import current_time
from ..utils import error

from .camera import AbstractCamera

Expand Down Expand Up @@ -160,7 +158,11 @@ def _fake_exposure(self, seconds, start_time, filename, exposure_event, dark):
# Write FITS file to requested location
if os.path.dirname(filename):
os.makedirs(os.path.dirname(filename), mode=0o775, exist_ok=True)
hdu_list.writeto(filename)

try:
hdu_list.writeto(filename)
except OSError:
pass

# Set event to mark exposure complete.
exposure_event.set()
57 changes: 34 additions & 23 deletions pocs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,15 @@ def is_dark(self):
bool: Is night at location
"""
if 'night' in self.config['simulator']:
self.logger.debug("Night simulator says safe")
is_dark = True
else:
is_dark = self.observatory.is_dark
# See if dark
is_dark = self.observatory.is_dark

# Check simulator
try:
if 'night' in self.config['simulator']:
is_dark = True
except KeyError:
pass

self.logger.debug("Dark Check: {}".format(is_dark))
return is_dark
Expand All @@ -305,26 +309,30 @@ def is_weather_safe(self, stale=180):
is_safe = False
record = {'safe': False}

if 'weather' in self.config['simulator']:
self.logger.debug("Weather simulator always safe")
is_safe = True
else:
try:
record = self.db.current.find_one({'type': 'weather'})
try:
if 'weather' in self.config['simulator']:
is_safe = True
self.logger.debug("Weather simulator always safe")
return is_safe
except KeyError:
pass

is_safe = record['data'].get('safe', False)
timestamp = record['date']
age = (current_time().datetime - timestamp).total_seconds()
try:
record = self.db.current.find_one({'type': 'weather'})

self.logger.debug("Weather Safety: {} [{:.0f} sec old - {}]".format(is_safe, age, timestamp))
is_safe = record['data'].get('safe', False)
timestamp = record['date']
age = (current_time().datetime - timestamp).total_seconds()

except TypeError as e:
self.logger.warning("No record found in Mongo DB")
self.logger.debug('DB: {}'.format(self.db.current))
else:
if age > stale:
self.logger.warning("Weather record looks stale, marking unsafe.")
is_safe = False
self.logger.debug("Weather Safety: {} [{:.0f} sec old - {}]".format(is_safe, age, timestamp))

except TypeError as e:
self.logger.warning("No record found in Mongo DB")
self.logger.debug('DB: {}'.format(self.db.current))
else:
if age > stale:
self.logger.warning("Weather record looks stale, marking unsafe.")
is_safe = False

self._is_safe = is_safe

Expand Down Expand Up @@ -430,7 +438,10 @@ def _setup_messaging(self):
msg_port = self.config['messaging']['msg_port']

def create_forwarder(port):
PanMessaging.create_forwarder(port, port + 1)
try:
PanMessaging.create_forwarder(port, port + 1)
except Exception:
pass

cmd_forwarder_process = Process(target=create_forwarder, args=(cmd_port,), name='CmdForwarder')
cmd_forwarder_process.start()
Expand Down
Loading

0 comments on commit 0ee03f3

Please sign in to comment.