Skip to content

Commit

Permalink
Allow filters specific to cameras in Observation (#470)
Browse files Browse the repository at this point in the history
* first

* tests

* fix tests

* fix tests
  • Loading branch information
danjampro authored Jun 7, 2021
1 parent 87a1290 commit 7ec8e26
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/huntsman/pocs/observatory.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,13 @@ def take_observation_block(self, observation, cameras=None, timeout=60 * u.secon

events = {}
for cam_name, camera in cameras.items():

# This is a temporary solution for having different filters on different cameras
# TODO: Refactor and remove
with suppress(AttributeError):
if observation.filter_names_per_camera is not None:
observation.filter_name = observation.filter_names_per_camera[cam_name]

try:
events[cam_name] = camera.take_observation(observation, headers=headers)
except error.PanError as err:
Expand Down
11 changes: 10 additions & 1 deletion src/huntsman/pocs/scheduler/observation/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from copy import deepcopy
from abc import ABC, abstractmethod
from collections import OrderedDict
from astropy import units as u
Expand All @@ -12,7 +13,8 @@ class AbstractObservation(PanBase, ABC):
""" Abstract base class for Observation objects. """

def __init__(self, field, exptime=120 * u.second, min_nexp=1, exp_set_size=1, priority=1,
dark=False, filter_name=None, directory=None, focus_offset=0, **kwargs):
dark=False, filter_name=None, directory=None, focus_offset=0,
filter_names_per_camera=None, **kwargs):
""" An observation of a given `panoptes.pocs.scheduler.field.Field`.
An observation consists of a minimum number of exposures (`min_nexp`) that
Expand All @@ -29,6 +31,8 @@ def __init__(self, field, exptime=120 * u.second, min_nexp=1, exp_set_size=1, pr
exp_set_size (int): Number of exposures to take per set, default: 1.
focus_offset (int, optional): Apply this focus offset for defocused observations.
Default 0.
filter_names_per_camera (dict, optional): If provided, this should be a dictionary
of camera_name: filter_name. If will take priority over filter_name.
"""
super().__init__(**kwargs)

Expand Down Expand Up @@ -56,8 +60,13 @@ def __init__(self, field, exptime=120 * u.second, min_nexp=1, exp_set_size=1, pr

self.dark = bool(dark)
self.priority = float(priority)

self.filter_name = filter_name

# This is a temporary solution for having different filters on different cameras
# TODO: Refactor and remove
self.filter_names_per_camera = filter_names_per_camera

self.focus_offset = focus_offset

if directory is None:
Expand Down
13 changes: 13 additions & 0 deletions tests/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,16 @@ def test_compound_dithered_observation_batch(field_config_1, field_config_2):
assert not obs.set_is_finished
obs.mark_exposure_complete()
assert obs.set_is_finished


def test_filter_names_per_camera(field_config_1):

cam_name = "dslr.00"
filter_names_per_camera = {cam_name: "deux"}

field = Field(**field_config_1)
obs = obsbase.Observation(field=field, filter_names_per_camera=filter_names_per_camera,
filter_name="one")

obs.filter_name = obs.filter_names_per_camera[cam_name]
assert obs.filter_name == "deux"

0 comments on commit 7ec8e26

Please sign in to comment.