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

Observation current_exp change #668

Merged
merged 29 commits into from
Oct 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
41c8544
Observation current_exp change
wtgee Oct 3, 2018
79d2dd4
Merge branch 'develop' of https://github.com/panoptes/POCS into curre…
wtgee Oct 3, 2018
6bce61b
Merge branch 'develop' of https://github.com/panoptes/POCS into curre…
wtgee Oct 4, 2018
599b985
Merge branch 'develop' of https://github.com/panoptes/POCS into curre…
wtgee Oct 4, 2018
54d1c3f
Merge branch 'develop' of https://github.com/panoptes/POCS into curre…
wtgee Oct 5, 2018
458e8e6
Some work on the filename for camera simulator
wtgee Oct 5, 2018
f88c941
Merge branch 'develop' of https://github.com/panoptes/POCS into curre…
wtgee Oct 5, 2018
e435071
Merge branch 'develop' of https://github.com/panoptes/POCS into curre…
wtgee Oct 5, 2018
1eefb5c
Merge branch 'develop' of https://github.com/panoptes/POCS into curre…
wtgee Oct 6, 2018
a8f1a8b
Adding a small addition to dome test to try and force coverage
wtgee Oct 6, 2018
cf0844d
Merge branch 'develop' of https://github.com/panoptes/POCS into curre…
wtgee Oct 6, 2018
a8ce53c
Fixing change from merge
wtgee Oct 6, 2018
a500ee5
Fixing directory test after #680 (not sure why failing here)
wtgee Oct 6, 2018
8f69364
Add primary image identifier to camera string
wtgee Oct 6, 2018
8f8f2d2
Remov
wtgee Oct 6, 2018
b7abb8f
Add a random number of seconds to a set POCSTIME
wtgee Oct 6, 2018
87a8ff1
Add some random seconds to the POCSTIME. Helps with many filename issues
wtgee Oct 6, 2018
2179bf3
Changing moon values for this test. Not sure why needed
wtgee Oct 6, 2018
ab0d6c4
Merge branch 'develop' of https://github.com/panoptes/POCS into curre…
wtgee Oct 7, 2018
90296ac
Remove random seconds from current_time
wtgee Oct 7, 2018
9b723d6
Skip exception for coverage
wtgee Oct 10, 2018
ac47678
Merge branch 'develop' of https://github.com/panoptes/POCS into curre…
wtgee Oct 10, 2018
30fb42d
Reset observation at start so always in sync
wtgee Oct 10, 2018
79ae630
Deal with pointing images in a smarter fashion
wtgee Oct 10, 2018
620f10b
Don't try to assign pointing image.
wtgee Oct 10, 2018
e2f0e61
Store solved image object for pointing
wtgee Oct 10, 2018
6bb3e8b
Properly get the pointing image
wtgee Oct 10, 2018
9cb3da2
Test for lack of pointing image
wtgee Oct 10, 2018
cba763d
Properly fetch the pointing image
wtgee Oct 10, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions pocs/camera/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,10 @@ def take_observation(self, observation, headers=None, filename=None, *args, **kw

# Add most recent exposure to list
if self.is_primary:
observation.exposure_list[image_id] = file_path
if 'POINTING' in headers:
observation.pointing_images[image_id] = file_path
else:
observation.exposure_list[image_id] = file_path

# Process the exposure once readout is complete
t = Thread(target=self.process_exposure, args=(
Expand Down Expand Up @@ -493,7 +496,12 @@ def _process_fits(self, file_path, info):
return file_path

def __str__(self):
s = "{} ({}) on {}".format(self.name, self.uid, self.port)
name = self.name
if self.is_primary:
name += ' [Primary]'

s = "{} ({}) on {}".format(name, self.uid, self.port)

if hasattr(self, 'focuser') and self.focuser is not None:
s += ' with {}'.format(self.focuser.name)

Expand Down
5 changes: 0 additions & 5 deletions pocs/camera/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ def take_observation(self, observation, headers=None, filename=None, *args, **kw
kwargs['exp_time'] = 1
self.logger.debug("Trimming camera simulator exposure to 1 s")

# If POCSTIME is set for testing then the simulator will generate
# duplicate filenames each time so we pass a filename here. Full path
# is added in `camera._setup_observation`.
filename = 'simulator_{:02d}.{}'.format(observation.current_exp, self.file_extension)

return super().take_observation(observation,
headers,
filename,
Expand Down
5 changes: 3 additions & 2 deletions pocs/observatory.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def analyze_recent(self):
# Clear the offset info
self.current_offset_info = None

pointing_image = self.current_observation.pointing_image
pointing_image_id, pointing_image = self.current_observation.pointing_image
self.logger.debug(
"Analyzing recent image using pointing image: '{}'".format(pointing_image))

Expand Down Expand Up @@ -430,7 +430,8 @@ def update_tracking(self):
self.logger.debug("Updating the tracking")

# Get the pier side of pointing image
pointing_ha = self.current_observation.pointing_image.header_ha
_, pointing_image = self.current_observation.pointing_image
pointing_ha = pointing_image.header_ha

try:
pointing_ha = pointing_ha.value
Expand Down
35 changes: 28 additions & 7 deletions pocs/scheduler/observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,24 @@ def __init__(self, field, exp_time=120 * u.second, min_nexp=60,

self.field = field

self.current_exp = 0

self.exp_time = exp_time
self.min_nexp = min_nexp
self.exp_set_size = exp_set_size
self.exposure_list = OrderedDict()
self.pointing_images = OrderedDict()

self.priority = float(priority)

self._min_duration = self.exp_time * self.min_nexp
self._set_duration = self.exp_time * self.exp_set_size

self.pointing_image = None

self._image_dir = self.config['directories']['images']
self._seq_time = None

self.merit = 0.0

self.reset()

self.logger.debug("Observation created: {}".format(self))


Expand Down Expand Up @@ -127,6 +126,15 @@ def directory(self):
self.field.field_name)
return self._directory

@property
def current_exp_num(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

What if we're currently taking another exposure? Is that counted or not?

Copy link
Member Author

Choose a reason for hiding this comment

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

This value will go up inside the camera.take_observation method but before the call to take_exposure. So yes, the current_exp_num will reflect an image in the process of being taken.

""" Return the current number of exposures.
wtgee marked this conversation as resolved.
Show resolved Hide resolved

Returns:
int: The size of `self.exposure_list`.
"""
return len(self.exposure_list)

@property
def first_exposure(self):
""" Return the latest exposure information
Expand All @@ -151,16 +159,29 @@ def last_exposure(self):
except IndexError:
self.logger.warning("No exposure available")

@property
def pointing_image(self):
"""Return the last pointing image.

Returns:
tuple: `image_id` and full path of most recent pointing image from
the primary camera.
"""
try:
return list(self.pointing_images.items())[-1]
except IndexError:
self.logger.warning("No pointing image available")


##################################################################################################
# Methods
##################################################################################################

def reset(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be great if this method were called by __init__, so that they can't get out of sync.

"""Resets the exposure values for the observation """
"""Resets the exposure information for the observation """
self.logger.debug("Resetting observation {}".format(self))

self.current_exp = 0
self.exposure_list = OrderedDict()
self.merit = 0.0
self.seq_time = None

Expand All @@ -179,7 +200,7 @@ def status(self):
equinox = 'J2000'

status = {
'current_exp': self.current_exp,
'current_exp': self.current_exp_num,
'dec_mnt': self.field.coord.dec.value,
'equinox': equinox,
'exp_set_size': self.exp_set_size,
Expand Down
6 changes: 3 additions & 3 deletions pocs/state/states/default/analyzing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def on_enter(event_data):

observation = pocs.observatory.current_observation

pocs.say("Analyzing image {} / {}".format(observation.current_exp, observation.min_nexp))
pocs.say("Analyzing image {} / {}".format(observation.current_exp_num, observation.min_nexp))

pocs.next_state = 'tracking'
try:
Expand All @@ -16,9 +16,9 @@ def on_enter(event_data):
pocs.next_state = 'scheduling'

# Check for minimum number of exposures
if observation.current_exp >= observation.min_nexp:
if observation.current_exp_num >= observation.min_nexp:
# Check if we have completed an exposure block
if observation.current_exp % observation.exp_set_size == 0:
if observation.current_exp_num % observation.exp_set_size == 0:
pocs.next_state = 'scheduling'
except Exception as e:
pocs.logger.error("Problem in analyzing: {}".format(e))
Expand Down
2 changes: 0 additions & 2 deletions pocs/state/states/default/observing.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,5 @@ def on_enter(event_data):
pocs.logger.warning("Problem with imaging: {}".format(e))
pocs.say("Hmm, I'm not sure what happened with that exposure.")
else:
pocs.observatory.current_observation.current_exp += 1
pocs.logger.debug('Finished with observing, going to analyze')

pocs.next_state = 'analyzing'
12 changes: 6 additions & 6 deletions pocs/state/states/default/pointing.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ def on_enter(event_data):

# Analyze pointing
if observation is not None:
pointing_id, pointing_path = observation.last_exposure
pointing_id, pointing_path = observation.pointing_image
pointing_image = Image(
pointing_path,
location=pocs.observatory.earth_location
)
pointing_image.solve_field()

observation.pointing_image = pointing_image

pocs.logger.debug("Pointing file: {}".format(pointing_image))
pocs.logger.debug("Pointing image: {}".format(pointing_image))

pocs.say("Ok, I've got the pointing picture, let's see how close we are.")
pointing_image.solve_field()

# Store the solved image object
observation.pointing_images[pointing_id] = pointing_image

pocs.logger.debug("Pointing Coords: {}", pointing_image.pointing)
pocs.logger.debug("Pointing Error: {}", pointing_image.pointing_error)
Expand Down
2 changes: 1 addition & 1 deletion pocs/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,4 @@ def test_location_positive_elevation(config):


def test_directories(config):
assert config['directories']['data'] == '{}/data'.format(os.getenv('PANDIR'))
assert config['directories']['data'] == os.path.join(os.getenv('PANDIR'), 'data')
17 changes: 10 additions & 7 deletions pocs/tests/test_observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,34 +92,37 @@ def test_no_exposures(field):
obs = Observation(field, exp_time=17.5 * u.second, min_nexp=27, exp_set_size=9)
assert obs.first_exposure is None
assert obs.last_exposure is None
assert obs.pointing_image is None


def test_last_exposure_and_reset(field):
obs = Observation(field, exp_time=17.5 * u.second, min_nexp=27, exp_set_size=9)
status = obs.status()
assert status['current_exp'] == obs.current_exp
assert status['current_exp'] == obs.current_exp_num

# Mimic taking exposures
obs.merit = 112.5

for i in range(5):
obs.current_exp += 1
obs.exposure_list['image_{}'.format(i)] = 'full_image_path_{}'.format(i)

last = obs.last_exposure
assert isinstance(last, tuple)
assert obs.merit > 0.0
assert obs.current_exp == 5
assert obs.current_exp_num == 5

assert last[0] == 'image_4'
assert last[1] == 'full_image_path_4'

assert isinstance(obs.first_exposure, tuple)
assert obs.first_exposure[0] == 'image_0'
assert obs.first_exposure[1] == 'full_image_path_0'

obs.reset()
status2 = obs.status()

assert status2['current_exp'] == 0
assert status2['merit'] == 0.0

assert isinstance(obs.first_exposure, tuple)
assert obs.first_exposure[0] == 'image_0'
assert obs.first_exposure[1] == 'full_image_path_0'
assert obs.first_exposure is None
assert obs.last_exposure is None
assert obs.seq_time is None
4 changes: 2 additions & 2 deletions pocs/tests/test_observatory.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ def test_observe(observatory):

assert len(observatory.scheduler.observed_list) == 1

assert observatory.current_observation.current_exp == 0
assert observatory.current_observation.current_exp_num == 0
observatory.observe()
assert observatory.current_observation.current_exp == 1
assert observatory.current_observation.current_exp_num == 1

observatory.cleanup_observations()
assert len(observatory.scheduler.observed_list) == 0
Expand Down