Skip to content

Commit

Permalink
AlreadyVisited Constraint
Browse files Browse the repository at this point in the history
Only allow an object to be visited once. This is mostly useful for something like an engineering run where you have a set list of objects you want to observe once.

Note that the "best" object is still selected for each call, i.e. this is __not__ a sequential scheduler.

See also #402 for implementation.

Thanks @jermainegug !
  • Loading branch information
jermainegug authored and wtgee committed Jan 21, 2018
1 parent 4e247d9 commit 9d6fe5b
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 58 deletions.
124 changes: 67 additions & 57 deletions examples/notebooks/Scheduler Playground.ipynb

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions pocs/scheduler/constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,31 @@ def get_score(self, time, observer, observation, **kwargs):

def __str__(self):
return "Moon Avoidance"


class AlreadyVisited(BaseConstraint):

""" Simple Already Visited Constraint
A simple already visited constraint that determines if the given `observation`
has already been visited before. If given `observation` has already been
visited then it will not be considered for a call to become the `current observation`.
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def get_score(self, time, observer, observation, **kwargs):
veto = False
score = self._score

observed_list = kwargs.get('observed_list')

observed_field_list = [obs.field for obs in observed_list.values()]

if observation.field in observed_field_list:
veto = True

return veto, score * self.weight

def __str__(self):
return "Already Visited"
3 changes: 2 additions & 1 deletion pocs/scheduler/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def get_observation(self, time=None, show_all=False, reread_fields_file=False):

common_properties = {
'end_of_night': self.observer.tonight(time=time, horizon=-18 * u.degree)[-1],
'moon': get_moon(time, self.observer.location)
'moon': get_moon(time, self.observer.location),
'observed_list': self.observed_list
}

for constraint in listify(self.constraints):
Expand Down
29 changes: 29 additions & 0 deletions pocs/tests/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
from astropy.coordinates import get_moon
from astropy.time import Time

from collections import OrderedDict

from pocs.scheduler.field import Field
from pocs.scheduler.observation import Observation

from pocs.scheduler.constraint import Altitude
from pocs.scheduler.constraint import BaseConstraint
from pocs.scheduler.constraint import Duration
from pocs.scheduler.constraint import MoonAvoidance
from pocs.scheduler.constraint import AlreadyVisited

from pocs.utils import horizon as horizon_utils


Expand Down Expand Up @@ -229,3 +233,28 @@ def test_moon_avoidance(observer):

assert veto1 is False and veto2 is False
assert score2 > score1


def test_already_visited(observer):
avc = AlreadyVisited()

time = Time('2016-08-13 10:00:00')

observation1 = Observation(Field('HD189733', '20h00m43.7135s +22d42m39.0645s')) # HD189733
observation2 = Observation(Field('Hat-P-16', '00h38m17.59s +42d27m47.2s')) # Hat-P-16
observation3 = Observation(Field('Sabik', '17h10m23s -15d43m30s')) # Sabik

observed_list = OrderedDict()

observation1.seq_time = '01:00'
observation2.seq_time = '02:00'
observation3.seq_time = '03:00'

observed_list[observation1.seq_time] = observation1
observed_list[observation2.seq_time] = observation2

veto1, score1 = avc.get_score(time, observer, observation1, observed_list=observed_list)
veto2, score2 = avc.get_score(time, observer, observation3, observed_list=observed_list)

assert veto1 is True
assert veto2 is False

0 comments on commit 9d6fe5b

Please sign in to comment.