Example #1
0
    def get(self, query):
        parsed_coordinates = Coordinates.parse(query)
        if parsed_coordinates is not None:
            target = {
                'ra': parsed_coordinates.ra,
                'dec': parsed_coordinates.dec
            }
            get_app_state().target = parsed_coordinates
            return jsonify(target)

        catalog_result = get_catalog().get_entry(query.upper())
        if catalog_result is not None:
            parsed_coordinates = Coordinates.parse_csvformat(
                catalog_result['RA'], catalog_result['Dec'])
            target = {
                'name': catalog_result['Name'],
                'ra': parsed_coordinates.ra,
                'dec': parsed_coordinates.dec,
                'type': catalog_result.get('Type'),
                'const': catalog_result.get('Const'),
                'minAx': catalog_result.get('MinAx'),
                'majAx': catalog_result.get('MajAx'),
                'posAng': catalog_result.get('PosAng'),
            }
            get_app_state().target = parsed_coordinates
            return jsonify(target)

        return '', 404
Example #2
0
 def gen():
     q = queue.Queue()
     subscribe_for_events(q)
     # Send an event with the current app state
     get_app_state().send_event()
     while True:
         data = q.get()
         # convert objects to dicts and make keys camel case
         data_dict = to_dict_recursively(data)
         camel_case_dict = camel_case_keys_recursively(data_dict)
         yield f'data: {json.dumps(camel_case_dict)}\n\n'
Example #3
0
    def post(self):
        app_state = get_app_state()
        if app_state.capturing or app_state.running_sequence:
            return 'Cannot do this while capturing', 400

        app_state.running_sequence = True

        print('Running auto-focus')
        hfd = self.determine_hfd(num_samples=10)
        print(f'HFD at start: {hfd}')

        self.move_focus(-700)
        self.move_focus(+200)

        hfd = self.determine_hfd(num_samples=10)
        print(f'HFD now: {hfd}')

        self.run_focus_sequence(increment=100, num_samples=10)

        self.move_focus(-300)
        self.move_focus(200)

        hfd = self.determine_hfd(num_samples=10)
        print(f'HFD now: {hfd}')

        self.run_focus_sequence(increment=25, num_samples=10)

        hfd = self.determine_hfd(num_samples=10)
        print(f'HFD in the end: {hfd}')

        print('All done')
        app_state.running_sequence = False
        return '', 200
Example #4
0
    def post(self):
        """
        Start a capturing sequence
        """
        body = request.json
        device_name = body['device']

        app_state = get_app_state()
        cam_state = app_state.cameras[device_name]

        def run_sequence():
            try:
                cam_controller = get_camera_controller()
                frame_manager = get_frame_manager()

                for frame in cam_controller.capture_sequence(
                        device_name, cam_state):
                    frame_manager.add_frame(frame, persist=cam_state.persist)
                    image_event(device_name, frame.path)
                    log_event(f'New frame: {frame.path}')

            except Exception as e:
                log_event(f'Capture error: {e}')
            finally:
                cam_state.sequence_stop_requested = False
                cam_state.running_sequence = False
                app_state.send_event()

        cam_state.running_sequence = True
        app_state.send_event()
        Thread(target=run_sequence).start()
        return '', 204
Example #5
0
    def post(self):
        # abort any steering maneuver
        app_state = get_app_state()
        if app_state.steering:
            app_state.steering = False
            time.sleep(1)

        get_axis_control().set_resting()
        return '', 200
Example #6
0
 def delete(self):
     """
     Stop the running sequence
     """
     device_name = request.args.get('device')
     app_state = get_app_state()
     app_state.cameras[device_name].sequence_stop_requested = True
     app_state.send_event()
     return '', 200
Example #7
0
    def post(self):
        body = request.json
        device_name = body['device']
        guide_settings = body['settings']

        # all numbers sent by the FE are in degrees/hour,
        # from here on we use degrees per second (dps).
        guide_settings = {
            key: float(value) / 3600 if not isinstance(value, bool) else value
            for key, value in guide_settings.items()
        }

        app_state = get_app_state()
        axis_control = get_axis_control()

        config = {
            "sigma_threshold": 5.0,
            "ra": {
                "enable": guide_settings["raEnable"],
                "range": guide_settings["raRange"],
                "invert": guide_settings["raInvert"],
                "pid_p": guide_settings["raP"],
                "pid_i": guide_settings["raI"],
                "pid_d": guide_settings["raD"]
            },
            "dec": {
                "enable": guide_settings["decEnable"],
                "range": guide_settings["decRange"],
                "invert": guide_settings["decInvert"],
                "pid_p": guide_settings["decP"],
                "pid_i": guide_settings["decI"],
                "pid_d": guide_settings["decD"]
            }
        }

        tracker = AutoGuider(
            config=config,
            device=device_name,
            axis_control=axis_control,
            ra_resting_speed_dps=axis_control.speeds.ra_dps,  # use current speeds as defaults
            dec_resting_speed_dps=axis_control.speeds.dec_dps,
        )

        def run_while():
            return app_state.guiding

        frame_manager = get_frame_manager()
        app_state.guiding = True
        threading.Thread(
            target=AutoGuider.run_loop,
            args=(tracker, frame_manager, run_while),
            daemon=True,
        ).start()
        return '', 200
Example #8
0
    def post(self):
        body = request.json
        frame_path = body['framePath']
        timeout = float(body['timeout'])

        frame = get_frame_manager().get_frame_by_path(frame_path)
        if frame is None:
            return 'Frame not found', 404

        here = os.path.dirname(os.path.abspath(__file__))
        hti_static_dir = os.path.join(here, '..', '..', 'static')

        if not frame.persisted:
            frame.persist(hti_static_dir)

        filepath = os.path.join(hti_static_dir, frame.path)

        app_state = get_app_state()

        def analyze_fun():
            app_state.calibrating = True
            calibration_data = Solver().analyze_image(
                filepath,
                timeout,
                run_callback=lambda: app_state.calibrating,
            )
            app_state.calibrating = False

            timestamp = int(datetime.datetime.now().timestamp())

            if calibration_data is None:
                log_event('Calibration failed')
            else:
                rotation_angle = calibration_data.rotation_angle
                position = calibration_data.center_deg

                log_event(
                    f'Image center: {position} Rotation: {rotation_angle}')

                if app_state.target is not None:
                    target_distance = Coordinates(
                        app_state.target.ra - position.ra,
                        app_state.target.dec - position.dec)
                    log_event(f'Distance to target: {target_distance}')

                app_state.last_known_position = {
                    'timestamp': timestamp,
                    'position': position,
                }

        Thread(target=analyze_fun).start()
        return '', 200
Example #9
0
    def post(self):
        app_state = get_app_state()
        axis_control = get_axis_control()

        def steer_fun():
            app_state.steering = True
            axis_control.go_to(here=app_state.last_known_position['position'],
                               target=app_state.target,
                               run_callback=lambda: app_state.steering)
            app_state.steering = False

        Thread(target=steer_fun).start()
        return '', 200
Example #10
0
    def put(self):
        """
        Overwrite capturing settings
        """
        body = request.json
        device_name = body['device']

        app_state = get_app_state()
        cam_state = app_state.cameras[device_name]
        cam_state.exposure = float(body['exposure'])
        cam_state.gain = float(body['gain'])
        cam_state.region = body['region']
        cam_state.persist = bool(body['persist'])
        app_state.send_event()
Example #11
0
    def post(self):
        body = request.json
        ra_speed = float(body['ra'])
        dec_speed = float(body['dec'])

        # abort any steering maneuver
        app_state = get_app_state()
        if app_state.steering:
            app_state.steering = False
            time.sleep(1)

        axis_control = get_axis_control()
        mode = 'manual' if ra_speed or dec_speed else 'stopped'
        axis_control.set_axis_speeds(ra_dps=ra_speed,
                                     dec_dps=dec_speed,
                                     mode=mode)
        return '', 200
Example #12
0
        def exp():
            app_state = get_app_state()
            cam_state = app_state.cameras[device_name]
            cam_controller = get_camera_controller()
            frame_manager = get_frame_manager()
            try:
                cam_state.capturing = True
                app_state.send_event()
                frame = cam_controller.capture_image(device_name, cam_state)
                frame_manager.add_frame(frame, persist=cam_state.persist)
                cam_state.capturing = False
                app_state.send_event()

                image_event(device_name, frame.path)
                log_event(f'New frame: {frame.path}')

            except TypeError as e:
                log_event(f'Capture error: {e}')
                cam_state.capturing = False
                app_state.send_event()
Example #13
0
 def delete(self):
     get_app_state().guiding = False
     return '', 200
Example #14
0
 def post(self):
     body = request.json
     factor = float(body['factor'])
     get_app_state().pec_state.factor = factor
     get_app_state().send_event()
Example #15
0
 def post(self):
     get_app_state().calibrating = False
     return '', 200
Example #16
0
 def delete(self):
     get_app_state().steering = False
     return '', 200
Example #17
0
 def delete(self):
     get_app_state().pec_state.replaying = False
     return '', 200