diff --git a/src/panoptes/pocs/mount/__init__.py b/src/panoptes/pocs/mount/__init__.py index af7695a3b..1c31fd120 100644 --- a/src/panoptes/pocs/mount/__init__.py +++ b/src/panoptes/pocs/mount/__init__.py @@ -54,7 +54,7 @@ def create_mount_from_config(mount_info=None, # Get details from config. site_details = create_location_from_config() - earth_location = site_details['earth_location'] + earth_location = site_details.earth_location brand = mount_info.get('brand') driver = mount_info.get('driver') @@ -122,7 +122,7 @@ def create_mount_simulator(mount_info=None, # Set mount device info to simulator set_config('mount', mount_config) - earth_location = earth_location or create_location_from_config()['earth_location'] + earth_location = earth_location or create_location_from_config().earth_location logger.debug(f"Loading mount driver: {mount_config['driver']}") try: diff --git a/src/panoptes/pocs/observatory.py b/src/panoptes/pocs/observatory.py index 82b3a32e4..c498a22f7 100644 --- a/src/panoptes/pocs/observatory.py +++ b/src/panoptes/pocs/observatory.py @@ -42,9 +42,9 @@ def __init__(self, cameras=None, scheduler=None, dome=None, mount=None, *args, * # Setup information about site location self.logger.info('Setting up location') site_details = create_location_from_config() - self.location = site_details['location'] - self.earth_location = site_details['earth_location'] - self.observer = site_details['observer'] + self.location = site_details.location + self.earth_location = site_details.earth_location + self.observer = site_details.observer # Do some one-time calculations now = current_time() diff --git a/src/panoptes/pocs/scheduler/__init__.py b/src/panoptes/pocs/scheduler/__init__.py index 6a4a59061..365c91597 100644 --- a/src/panoptes/pocs/scheduler/__init__.py +++ b/src/panoptes/pocs/scheduler/__init__.py @@ -35,7 +35,7 @@ def create_scheduler_from_config(config=None, observer=None, iers_url=None, *arg if not observer: logger.debug(f'No Observer provided, creating location from config.') site_details = create_location_from_config() - observer = site_details['observer'] + observer = site_details.observer # Read the targets from the file fields_file = scheduler_config.get('fields_file', 'simple.yaml') diff --git a/src/panoptes/pocs/state/machine.py b/src/panoptes/pocs/state/machine.py index eb201e0a9..3833eccfd 100644 --- a/src/panoptes/pocs/state/machine.py +++ b/src/panoptes/pocs/state/machine.py @@ -80,7 +80,8 @@ def next_state(self, value): # Methods ################################################################################################ - def run(self, exit_when_done=False, run_once=False, park_when_done=True, initial_next_state='ready'): + def run(self, exit_when_done=False, run_once=False, park_when_done=True, + initial_next_state='ready'): """Runs the state machine loop. This runs the state machine in a loop. Setting the machine property @@ -188,7 +189,7 @@ def run(self, exit_when_done=False, run_once=False, park_when_done=True, initial else: if park_when_done: self.logger.info(f'Run loop ended, parking mount') - self.observatory.mount.park() + self.observatory.mount.park() def goto_next_state(self): """Make a transition to the next state. diff --git a/src/panoptes/pocs/utils/error.py b/src/panoptes/pocs/utils/error.py index 78a01e8cc..5b3a2fed9 100644 --- a/src/panoptes/pocs/utils/error.py +++ b/src/panoptes/pocs/utils/error.py @@ -47,4 +47,4 @@ class NotSafeError(PanError): """ Error for when safety fails. """ def __init__(self, msg='Not safe', **kwargs): - super().__init__(msg, **kwargs) \ No newline at end of file + super().__init__(msg, **kwargs) diff --git a/src/panoptes/pocs/utils/location.py b/src/panoptes/pocs/utils/location.py index d596c0e35..9b3e76f65 100644 --- a/src/panoptes/pocs/utils/location.py +++ b/src/panoptes/pocs/utils/location.py @@ -1,3 +1,4 @@ +from dataclasses import dataclass from astroplan import Observer from astropy import units as u from astropy.coordinates import EarthLocation @@ -9,7 +10,14 @@ logger = get_logger() -def create_location_from_config(): +@dataclass +class SiteDetails: + observer: Observer + earth_location: EarthLocation + location: dict + + +def create_location_from_config() -> SiteDetails: """ Sets up the site and location details. @@ -63,11 +71,11 @@ def create_location_from_config(): earth_location = EarthLocation(lat=latitude, lon=longitude, height=elevation) observer = Observer(location=earth_location, name=name, timezone=timezone) - site_details = { - "location": location, - "earth_location": earth_location, - "observer": observer - } + site_details = SiteDetails( + location=location, + earth_location=earth_location, + observer=observer + ) return site_details diff --git a/tests/scheduler/test_scheduler.py b/tests/scheduler/test_scheduler.py index 35d626ef7..5247242a0 100644 --- a/tests/scheduler/test_scheduler.py +++ b/tests/scheduler/test_scheduler.py @@ -22,10 +22,10 @@ def test_bad_scheduler_namespace(config_host, config_port): set_config('scheduler.type', 'dispatch') site_details = create_location_from_config() with pytest.raises(error.NotFound): - create_scheduler_from_config(observer=site_details['observer']) + create_scheduler_from_config(observer=site_details.observer) set_config('scheduler.type', 'panoptes.pocs.scheduler.dispatch') - scheduler = create_scheduler_from_config(observer=site_details['observer']) + scheduler = create_scheduler_from_config(observer=site_details.observer) assert isinstance(scheduler, BaseScheduler) @@ -36,7 +36,7 @@ def test_bad_scheduler_type(config_host, config_port): set_config('scheduler.type', 'foobar') site_details = create_location_from_config() with pytest.raises(error.NotFound): - create_scheduler_from_config(observer=site_details['observer']) + create_scheduler_from_config(observer=site_details.observer) reset_conf(config_host, config_port) @@ -45,7 +45,7 @@ def test_bad_scheduler_fields_file(config_host, config_port): set_config('scheduler.fields_file', 'foobar') site_details = create_location_from_config() with pytest.raises(error.NotFound): - create_scheduler_from_config(observer=site_details['observer']) + create_scheduler_from_config(observer=site_details.observer) reset_conf(config_host, config_port) @@ -58,5 +58,5 @@ def test_no_scheduler_in_config(config_host, config_port): set_config('scheduler', None) site_details = create_location_from_config() assert create_scheduler_from_config( - observer=site_details['observer']) is None + observer=site_details.observer) is None reset_conf(config_host, config_port) diff --git a/tests/test_ioptron.py b/tests/test_ioptron.py index 02b9b5edb..68cf657c3 100644 --- a/tests/test_ioptron.py +++ b/tests/test_ioptron.py @@ -44,9 +44,7 @@ def setup(self): with pytest.raises(AssertionError): mount = Mount(location) - earth_location = location['earth_location'] - - mount = Mount(earth_location) + mount = Mount(location.earth_location) assert mount is not None self.mount = mount diff --git a/tests/test_mount.py b/tests/test_mount.py index 63bc37609..901ef0fba 100644 --- a/tests/test_mount.py +++ b/tests/test_mount.py @@ -68,7 +68,7 @@ def test_create_mount_with_earth_location(config_host, config_port): # Set config to not have a location. set_config('location', None) set_config('simulator', hardware.get_all_names()) - assert isinstance(create_mount_from_config(earth_location=loc['earth_location']), + assert isinstance(create_mount_from_config(earth_location=loc.earth_location), AbstractMount) is True reset_conf(config_host, config_port) diff --git a/tests/test_observatory.py b/tests/test_observatory.py index 1f3908e21..3adb739eb 100644 --- a/tests/test_observatory.py +++ b/tests/test_observatory.py @@ -45,7 +45,7 @@ def observatory(mount, cameras, images_dir): """Return a valid Observatory instance with a specific config.""" site_details = create_location_from_config() - scheduler = create_scheduler_from_config(observer=site_details['observer']) + scheduler = create_scheduler_from_config(observer=site_details.observer) obs = Observatory(scheduler=scheduler) obs.set_mount(mount) @@ -83,7 +83,7 @@ def test_cannot_observe(caplog): time.sleep(0.5) # log sink time log_record = caplog.records[-1] assert log_record.message.endswith("not present") and log_record.levelname == "WARNING" - obs.scheduler = create_scheduler_from_config(observer=site_details['observer']) + obs.scheduler = create_scheduler_from_config(observer=site_details.observer) assert obs.can_observe is False time.sleep(0.5) # log sink time @@ -126,7 +126,7 @@ def test_primary_camera_no_primary_camera(observatory): def test_set_scheduler(observatory, caplog): site_details = create_location_from_config() - scheduler = create_scheduler_from_config(observer=site_details['observer']) + scheduler = create_scheduler_from_config(observer=site_details.observer) assert observatory.current_observation is None diff --git a/tests/test_pocs.py b/tests/test_pocs.py index a02e15a53..e2ed09459 100644 --- a/tests/test_pocs.py +++ b/tests/test_pocs.py @@ -53,7 +53,7 @@ def site_details(): @pytest.fixture(scope='function') def scheduler(site_details): - return create_scheduler_from_config(observer=site_details['observer']) + return create_scheduler_from_config(observer=site_details.observer) @pytest.fixture(scope='function')