Skip to content

Commit

Permalink
Cem40 improvements (#1206)
Browse files Browse the repository at this point in the history
* Allow for mount testing on the `loop` dummy serial line.

* * Overriding `set_target_coordinates` for the cem40 so it reports possible number of positions.
* Cleanup.

* * Small cleanup.

* Trying to fix scheduling error test.

* Update the date on a failing test.

* Don't use compound exposure for testing or simple example yet.

* Reset scheduler each time.

* Still trying to figure out why this changed.

* Still trying to figure out why this changed.

* Changing test function scopes to ensure a proper reset of scheduler.

* Tests of scheduler

* Adding a small time delay. This appears to be a race condition with setting the sequence_id too quickly.
  • Loading branch information
wtgee authored Nov 17, 2023
1 parent 91598c9 commit f878b6b
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 54 deletions.
12 changes: 2 additions & 10 deletions conf_files/fields/simple.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,14 @@
position: "05h35m17.2992s -05d23m27.996s"
observation:
exp_set_size: 5
type: "panoptes.pocs.scheduler.observation.compound.Observation"
exptime:
- 15
- 45
- 90
min_nexp: 10
exptime: 30
priority: 75
- field:
name: M45
position: "03h47m24s +24d07m01.20s"
observation:
exp_set_size: 5
type: "panoptes.pocs.scheduler.observation.compound.Observation"
exptime:
- 15
- 45
- 90
exptime: 30
min_nexp: 10
priority: 100
5 changes: 4 additions & 1 deletion src/panoptes/pocs/mount/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ def create_mount_from_config(mount_info=None,
port = mount_info['serial']['port']
logger.info(f'Looking for {driver} on {port}.')
if port is None or len(glob(port)) == 0:
raise error.MountNotFound(msg=f'Mount {port=} not available.')
if port == 'loop://':
logger.warning('Using loop:// for mount connection.')
else:
raise error.MountNotFound(msg=f'Mount {port=} not available.')
except KeyError:
# See Issue 866
if model == 'bisque':
Expand Down
27 changes: 18 additions & 9 deletions src/panoptes/pocs/mount/ioptron/cem40.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
import re
import time

from astropy import units as u
from astropy.time import Time

from panoptes.pocs.mount.ioptron.base import Mount as BaseMount
from panoptes.pocs.mount.ioptron import MountState
from panoptes.pocs.mount.ioptron.base import Mount as BaseMount


class Mount(BaseMount):
"""
Mount class for iOptron mounts. Overrides the base `initialize` method
and providers some helper methods to convert coordinates.
"""

def __init__(self, location, mount_version='0040', *args, **kwargs):
self._mount_version = mount_version
Expand All @@ -30,3 +22,20 @@ def search_for_home(self):
while self.status.get('state') != MountState.AT_HOME:
self.logger.trace(f'Searching for home position.')
time.sleep(1)

def set_target_coordinates(self, *args, **kwargs):
"""After setting target coordinates, check number of positions.
The CEM40 can determine if there are 0, 1, or 2 possible positions
for the given RA/Dec, with the latter being the case for the meridian
flip.
"""
target_set = super().set_target_coordinates(*args, **kwargs)
self.logger.debug(f'Checking number of possible positions for {self._target_coordinates}')
num_possible_positions = self.query('query_positions')
self.logger.debug(f'Number of possible positions: {num_possible_positions}')

if num_possible_positions == 0:
self.logger.warning(f'No possible positions for {self._target_coordinates}')
target_set = False

return target_set
8 changes: 0 additions & 8 deletions src/panoptes/pocs/mount/ioptron/ieq30pro.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import re

from astropy.time import Time

from panoptes.pocs.mount.ioptron.base import Mount as BaseMount


class Mount(BaseMount):
"""
Mount class for iOptron mounts. Overrides the base `initialize` method
and providers some helper methods to convert coordinates.
"""

def __init__(self, location, mount_version='0030', *args, **kwargs):
self._mount_version = mount_version
Expand Down
10 changes: 5 additions & 5 deletions src/panoptes/pocs/scheduler/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@ def get_observation(self, time=None, show_all=False, constraints=None, read_file
self.logger.info(f'Best observation: {top_obs_name}\tScore: {top_obs_score:.02f}')

# Check new best against current_observation
if self.current_observation is not None \
and top_obs_name != self.current_observation.name:
if self.current_observation is not None and top_obs_name != self.current_observation.name:
self.logger.debug(f'Checking if {self.current_observation} is still valid')

# Favor the current observation if still available
end_of_next_set = time + self.current_observation.set_duration
if self.observation_available(self.current_observation, end_of_next_set):

# If current is better or equal to top, use it
self.logger.debug(f'{self.current_observation.merit=}')
self.logger.debug(f'{top_obs_score=}')
if self.current_observation.merit >= top_obs_score:
best_obs.insert(0, (self.current_observation,
self.current_observation.merit))
best_obs.insert(0, (self.current_observation, self.current_observation.merit))

# Set the current
self.current_observation = self.observations[top_obs_name]
Expand Down
3 changes: 1 addition & 2 deletions src/panoptes/pocs/scheduler/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from astropy import units as u
from astropy.coordinates import get_body
from panoptes.utils import error
from panoptes.utils.library import load_module
from panoptes.utils.serializers import from_yaml
from panoptes.utils.time import current_time

Expand Down Expand Up @@ -121,7 +120,7 @@ def current_observation(self, new_observation):
# Add the new observation to the list
self.observed_list[new_observation.seq_time] = new_observation

self.logger.info("Setting new observation to {}".format(new_observation))
self.logger.info(f'Setting new observation to {new_observation}')
self._current_observation = new_observation

@property
Expand Down
36 changes: 17 additions & 19 deletions tests/scheduler/test_dispatch_scheduler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import yaml
import pytest
import time

from astropy import units as u
from astropy.coordinates import EarthLocation
Expand All @@ -19,14 +20,14 @@ def constraints():
return [MoonAvoidance(), Duration(30 * u.deg)]


@pytest.fixture
@pytest.fixture(scope='function')
def observer():
loc = get_config('location')
location = EarthLocation(lon=loc['longitude'], lat=loc['latitude'], height=loc['elevation'])
return Observer(location=location, name="Test Observer", timezone=loc['timezone'])


@pytest.fixture()
@pytest.fixture(scope='function')
def field_file():
scheduler_config = get_config('scheduler', default={})

Expand All @@ -37,7 +38,7 @@ def field_file():
return fields_path


@pytest.fixture()
@pytest.fixture(scope='function')
def field_list():
return yaml.full_load("""
-
Expand Down Expand Up @@ -97,8 +98,12 @@ def field_list():
""")


@pytest.fixture
@pytest.fixture(scope='function')
def scheduler(field_list, observer, constraints):
try:
del os.environ['POCSTIME']
except Exception:
pass
return Scheduler(observer,
fields_list=field_list,
constraints=constraints)
Expand Down Expand Up @@ -179,11 +184,6 @@ def test_continue_observation(scheduler):


def test_set_observation_then_reset(scheduler):
try:
del os.environ['POCSTIME']
except Exception:
pass

time = Time('2016-08-13 05:00:00')
scheduler.get_observation(time=time)

Expand Down Expand Up @@ -246,23 +246,21 @@ def test_new_observation_seq_time(scheduler):
def test_observed_list(scheduler):
assert len(scheduler.observed_list) == 0

time = Time('2016-09-11 07:08:00')
scheduler.get_observation(time=time)

time0 = Time('2016-09-11 07:08:00')
scheduler.get_observation(time=time0)
assert len(scheduler.observed_list) == 1

# A few hours later should now be different
time = Time('2016-09-11 10:30:00')
scheduler.get_observation(time=time)

time.sleep(1)
time1 = Time('2016-09-11 10:08:00')
scheduler.get_observation(time=time1)
assert len(scheduler.observed_list) == 2

# A few hours later should be the same
time = Time('2016-09-11 14:30:00')
scheduler.get_observation(time=time)

time.sleep(1)
time2 = Time('2016-09-11 14:38:00')
scheduler.get_observation(time=time2)
assert len(scheduler.observed_list) == 2

scheduler.reset_observed_list()

assert len(scheduler.observed_list) == 0

0 comments on commit f878b6b

Please sign in to comment.