def test_solve_timeout(tiny_fits_file): im0 = Image(tiny_fits_file) with pytest.raises(Timeout): im0.solve_field(verbose=True, replace=False, radius=4, timeout=1) try: os.remove(tiny_fits_file.replace('.fits', '.axy')) except Exception: pass
def test_fail_solve(tiny_fits_file): im0 = Image(tiny_fits_file) with pytest.raises(SolveError): im0.solve_field(verbose=True, replace=False, radius=4) try: os.remove(tiny_fits_file.replace('.fits', '.axy')) except Exception: # pragma: no cover pass
def test_pointing_error(solved_fits_file): im0 = Image(solved_fits_file) im0.solve_field(verbose=True, replace=False, radius=4) perr = im0.pointing_error assert isinstance(perr, OffsetError) assert (perr.delta_ra.to(u.degree).value - 1.647535444553057) < 1e-5 assert (perr.delta_dec.to(u.degree).value - 1.560722632731533) < 1e-5 assert (perr.magnitude.to(u.degree).value - 1.9445870862060288) < 1e-5
def test_solve_field_solved(solved_fits_file): im0 = Image(solved_fits_file) assert isinstance(im0, Image) assert im0.wcs is not None assert im0.wcs_file is not None assert im0.pointing is not None assert im0.ra is not None assert im0.dec is not None assert im0.ha is not None im0.solve_field(verbose=True, radius=4) assert isinstance(im0.pointing, SkyCoord)
def test_solve_field_unsolved(unsolved_fits_file): im0 = Image(unsolved_fits_file) assert isinstance(im0, Image) assert im0.wcs is None assert im0.pointing is None im0.solve_field(verbose=True, replace=False, radius=4) assert im0.wcs is not None assert im0.wcs_file is not None assert isinstance(im0.pointing, SkyCoord) assert im0.ra is not None assert im0.dec is not None assert im0.ha is not None # Remove extra files os.remove(unsolved_fits_file.replace('.fits', '.solved')) os.remove(unsolved_fits_file.replace('.fits', '.new'))
def analyze_recent(self): """Analyze the most recent exposure Compares the most recent exposure to the reference exposure and determines the offset between the two. Returns: dict: Offset information """ # Clear the offset info self.current_offset_info = None pointing_image = self.current_observation.pointing_image try: # Get the image to compare image_id, image_path = self.current_observation.last_exposure current_image = Image(image_path, location=self.earth_location) solve_info = current_image.solve_field() self.logger.debug("Solve Info: {}".format(solve_info)) # Get the offset between the two self.current_offset_info = current_image.compute_offset( pointing_image) self.logger.debug('Offset Info: {}'.format( self.current_offset_info)) # Update the observation info with the offsets self.db.observations.update({'data.image_id': image_id}, { '$set': { 'offset_info': { 'd_ra': self.current_offset_info.delta_ra.value, 'd_dec': self.current_offset_info.delta_dec.value, 'magnitude': self.current_offset_info.magnitude.value, 'unit': 'arcsec' } }, }) except error.SolveError: self.logger.warning("Can't solve field, skipping") except Exception as e: self.logger.warning("Problem in analyzing: {}".format(e)) return self.current_offset_info
def on_enter(event_data): """Pointing State Take 30 second exposure and plate-solve to get the pointing error """ pocs = event_data.model # point_config = pocs.config.get('pointing', {}) pocs.next_state = 'parking' try: pocs.say("Taking pointing picture.") observation = pocs.observatory.current_observation fits_headers = pocs.observatory.get_standard_headers( observation=observation) fits_headers['POINTING'] = 'True' pocs.logger.debug("Pointing headers: {}".format(fits_headers)) for img_num in range(num_pointing_images): camera_events = dict() for cam_name, camera in pocs.observatory.cameras.items(): pocs.logger.debug("Exposing for camera: {}".format(cam_name)) if camera.is_primary: try: # Start the exposures camera_event = camera.take_observation( observation, fits_headers, exp_time=30., filename='pointing{:02d}'.format(img_num)) camera_events[cam_name] = camera_event except Exception as e: pocs.logger.error( "Problem waiting for images: {}".format(e)) wait_time = 0. while not all([event.is_set() for event in camera_events.values()]): pocs.check_messages() if pocs.interrupted: pocs.say("Observation interrupted!") break pocs.logger.debug( 'Waiting for images: {} seconds'.format(wait_time)) pocs.status() if wait_interval > timeout: raise error.Timeout sleep(wait_interval) wait_time += wait_interval if pocs.observatory.current_observation is not None: pointing_id, pointing_path = pocs.observatory.current_observation.last_exposure 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.say( "Ok, I've got the pointing picture, let's see how close we are.") pocs.logger.debug("Pointing Coords: {}".format( pointing_image.pointing)) pocs.logger.debug("Pointing Error: {}".format( pointing_image.pointing_error)) # separation = pointing_image.pointing_error.magnitude.value # if separation > point_config.get('pointing_threshold', 0.05): # pocs.say("I'm still a bit away from the field so I'm going to try and get a bit closer.") # # Tell the mount we are at the field, which is the center # pocs.say("Syncing with the latest image...") # has_field = pocs.observatory.mount.set_target_coordinates(pointing_image.pointing) # pocs.logger.debug("Coords set, calibrating") # pocs.observatory.mount.serial_query('calibrate_mount') # # Now set back to field # if has_field: # if observation.field is not None: # pocs.logger.debug("Slewing back to target") # pocs.observatory.mount.set_target_coordinates(observation.field) # pocs.observatory.mount.slew_to_target() pocs.next_state = 'tracking' except Exception as e: pocs.say( "Hmm, I had a problem checking the pointing error. Sending to parking. {}".format(e))
def on_enter(event_data): """Pointing State Take 30 second exposure and plate-solve to get the pointing error """ pocs = event_data.model # point_config = pocs.config.get('pointing', {}) pocs.next_state = 'parking' try: pocs.say("Taking pointing picture.") observation = pocs.observatory.current_observation fits_headers = pocs.observatory.get_standard_headers( observation=observation) fits_headers['POINTING'] = 'True' pocs.logger.debug("Pointing headers: {}".format(fits_headers)) for img_num in range(num_pointing_images): camera_events = dict() for cam_name, camera in pocs.observatory.cameras.items(): pocs.logger.debug("Exposing for camera: {}".format(cam_name)) if camera.is_primary: try: # Start the exposures camera_event = camera.take_observation( observation, fits_headers, exp_time=30., filename='pointing{:02d}'.format(img_num)) camera_events[cam_name] = camera_event except Exception as e: pocs.logger.error( "Problem waiting for images: {}".format(e)) wait_time = 0. while not all([event.is_set() for event in camera_events.values()]): pocs.check_messages() if pocs.interrupted: pocs.say("Observation interrupted!") break pocs.logger.debug( 'Waiting for images: {} seconds'.format(wait_time)) pocs.status() if wait_interval > timeout: raise error.Timeout sleep(wait_interval) wait_time += wait_interval if pocs.observatory.current_observation is not None: pointing_id, pointing_path = pocs.observatory.current_observation.last_exposure 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.say( "Ok, I've got the pointing picture, let's see how close we are." ) pocs.logger.debug("Pointing Coords: {}".format( pointing_image.pointing)) pocs.logger.debug("Pointing Error: {}".format( pointing_image.pointing_error)) # separation = pointing_image.pointing_error.magnitude.value # if separation > point_config.get('pointing_threshold', 0.05): # pocs.say("I'm still a bit away from the field so I'm going to try and get a bit closer.") # # Tell the mount we are at the field, which is the center # pocs.say("Syncing with the latest image...") # has_field = pocs.observatory.mount.set_target_coordinates(pointing_image.pointing) # pocs.logger.debug("Coords set, calibrating") # pocs.observatory.mount.serial_query('calibrate_mount') # # Now set back to field # if has_field: # if observation.field is not None: # pocs.logger.debug("Slewing back to target") # pocs.observatory.mount.set_target_coordinates(observation.field) # pocs.observatory.mount.slew_to_target() pocs.next_state = 'tracking' except Exception as e: pocs.say( "Hmm, I had a problem checking the pointing error. Sending to parking. {}" .format(e))