Ejemplo n.º 1
0
        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,
                }
Ejemplo n.º 2
0
    def analyze_image(self,
                      filepath,
                      timeout=30,
                      run_callback=None) -> Union[CalibrationData, None]:
        command = self.get_analyze_command([filepath], timeout)
        output = run_command_or_die_trying(command, timeout, run_callback)
        if output is None:
            return None

        # Output example:
        #
        # [...] pixel scale 0.907073 arcsec/pix.
        # [...]
        # Field: toughstuff/s10212.tif
        # Field center: (RA,Dec) = (114.133515, 65.594210) deg.
        # Field center: (RA H:M:S, Dec D:M:S) = (07:36:32.044, +65:35:39.156).
        # Field size: 28.9649 x 16.3092 arcminutes
        # Field rotation angle: up is 1.76056 degrees E of N
        # Field parity: pos
        # [...]

        output_regexes = {
            'pixel_scale':
            r'^.*pixel scale (?P<scale>[\d\.]*) (?P<unit>[\w\/]*)\..*$',
            'center_deg':
            r'^.*Field center: \(RA,Dec\) = \((?P<ra>[\d\.]*), (?P<dec>[\-\d\.]*)\) deg\..*$',
            'center':
            r'^.*Field center: \(RA H:M:S, Dec D:M:S\) = \((?P<ra>[\d\.\:]*), (?P<dec>[\d\.\:\+\-]*)\)\..*$',
            'size':
            r'^.*Field size: (?P<width>[\d\.]*) x (?P<height>[\d\.]*) (?P<unit>\w*).*$',
            'rotation':
            r'^.*Field rotation angle: up is (?P<angle>[\-\d\.]*) degrees (?P<direction>[WE]) of N.*$',
            'parity': r'^.*Field parity: (?P<parity>pos|neg).*$',
        }

        parsed_data = {}
        for output_key, output_regex in output_regexes.items():
            rx = re.compile(output_regex, re.DOTALL)
            match = rx.match(output)
            if not match:
                print(
                    f'WARN: No match found for "{output_key}" in output of solve-field of file {filepath}.'
                )
                print(
                    f'Field may not have been solved or the output of the solver could not be parsed. Full output:\n{output}'
                )
                return None
            parsed_data[output_key] = match.groupdict()

        return CalibrationData(
            pixel_scale=float(parsed_data['pixel_scale']['scale']),
            pixel_scale_unit=str(parsed_data['pixel_scale']['unit']),
            center_deg=Coordinates(float(parsed_data['center_deg']['ra']),
                                   float(parsed_data['center_deg']['dec'])),
            rotation_angle=float(parsed_data['rotation']['angle']),
            rotation_direction=str(parsed_data['rotation']['direction']),
            parity=str(parsed_data['parity']['parity']),
        )