Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default to rereading the fields file #488

Merged
merged 9 commits into from
Apr 12, 2018
1 change: 1 addition & 0 deletions conf_files/pocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ db:
scheduler:
type: dispatch
fields_file: simple.yaml
check_file: False
mount:
brand: ioptron
model: 30
Expand Down
3 changes: 2 additions & 1 deletion pocs/observatory.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ def get_observation(self, *args, **kwargs):

# If observation list is empty or a reread is requested
if (self.scheduler.has_valid_observations is False or
kwargs.get('reread_fields_file', False)):
kwargs.get('reread_fields_file', False) or
self.config['scheduler'].get('check_file', False)):
self.scheduler.read_field_list()

# This will set the `current_observation`
Expand Down
2 changes: 2 additions & 0 deletions pocs/scheduler/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def get_observation(self, time=None, show_all=False, reread_fields_file=False):
defaults to time called
show_all (bool, optional): Return all valid observations along with
merit value, defaults to False to only get top value
reread_fields_file (bool, optional): If the fields file should be reread
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the reason for not making the change here in the params list (i.e. default =True).

before scheduling occurs, defaults to False.

Returns:
tuple or list: A tuple (or list of tuples) with name and score of ranked observations
Expand Down
5 changes: 2 additions & 3 deletions pocs/scheduler/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,6 @@ def add_observation(self, field_config):
Args:
field_config (dict): Configuration items for `Observation`
"""
assert field_config['name'] not in self._observations.keys(), \
self.logger.error("Cannot add duplicate field name")

if 'exp_time' in field_config:
field_config['exp_time'] = float(field_config['exp_time']) * u.second

Expand All @@ -233,6 +230,8 @@ def add_observation(self, field_config):
self.logger.warning("Skipping invalid field config: {}".format(field_config))
self.logger.warning(e)
else:
if field.name in self._observations:
self.logger.debug("Overriding existing entry for {}".format(field.name))
self._observations[field.name] = obs

def remove_observation(self, field_name):
Expand Down
3 changes: 2 additions & 1 deletion pocs/state/states/default/scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def on_enter(event_data):
pocs.logger.warning("Error in scheduling: {}".format(e))
else:

if observation != existing_observation:
if ((observation and existing_observation) and
(observation.name != existing_observation.name)):
pocs.say("Got it! I'm going to check out: {}".format(observation.name))

pocs.logger.debug("Setting Observation coords: {}".format(observation.field))
Expand Down
15 changes: 10 additions & 5 deletions pocs/tests/test_base_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,18 @@ def test_scheduler_add_duplicate_field(scheduler):
scheduler.add_observation({
'name': 'Duplicate Field',
'position': '12h30m01s +08d08m08s',
'priority': 100
})

with pytest.raises(AssertionError):
scheduler.add_observation({
'name': 'Duplicate Field',
'position': '12h30m01s +08d08m08s',
})
assert scheduler.observations['Duplicate Field'].priority == 100

scheduler.add_observation({
'name': 'Duplicate Field',
'position': '12h30m01s +08d08m08s',
'priority': 500
})

assert scheduler.observations['Duplicate Field'].priority == 500


def test_scheduler_add_duplicate_field_different_name(scheduler):
Expand Down