Esempio n. 1
0
    def _readout(self, filename, width, height, header):
        exposure_status = Camera._driver.get_exposure_status(self._handle)
        if exposure_status == 'SUCCESS':
            try:
                image_data = Camera._driver.get_exposure_data(
                    self._handle, width, height, self.image_type)
            except RuntimeError as err:
                raise error.PanError(
                    'Error getting image data from {}: {}'.format(self, err))
            else:
                # Fix 'raw' data scaling by changing from zero padding of LSBs
                # to zero padding of MSBs.
                if self.image_type == 'RAW16':
                    pad_bits = 16 - int(
                        get_quantity_value(self.bit_depth, u.bit))
                    image_data = np.right_shift(image_data, pad_bits)

                fits_utils.write_fits(data=image_data,
                                      header=header,
                                      filename=filename)
        elif exposure_status == 'FAILED':
            raise error.PanError("Exposure failed on {}".format(self))
        elif exposure_status == 'IDLE':
            raise error.PanError("Exposure missing on {}".format(self))
        else:
            raise error.PanError(
                "Unexpected exposure status on {}: '{}'".format(
                    self, exposure_status))
Esempio n. 2
0
    def _readout(self, filename=None, header=None):
        self.logger.debug(f'Calling _readout for {self}')
        timer = CountdownTimer(duration=self.readout_time)
        # Get example FITS file from test data directory
        file_path = os.path.join(os.environ['POCS'], 'tests', 'data', 'unsolved.fits')
        fake_data = fits.getdata(file_path)

        if header.get('IMAGETYP') == 'Dark Frame':
            # Replace example data with a bunch of random numbers
            fake_data = np.random.randint(low=975, high=1026,
                                          size=fake_data.shape,
                                          dtype=fake_data.dtype)
        self.logger.debug(f'Writing filename={filename!r} for {self}')
        fits_utils.write_fits(fake_data, header, filename)

        # Sleep for the remainder of the readout time.
        timer.sleep()
Esempio n. 3
0
 def _readout(self, filename, width, height, header):
     # Use FLIGrabRow for now at least because I can't get FLIGrabFrame to work.
     # image_data = self._FLIDriver.FLIGrabFrame(self._handle, width, height)
     image_data = np.zeros((height, width), dtype=np.uint16)
     rows_got = 0
     try:
         for i in range(image_data.shape[0]):
             image_data[i] = self._driver.FLIGrabRow(
                 self._handle, image_data.shape[1])
             rows_got += 1
     except RuntimeError as err:
         message = 'Readout error on {}, expected {} rows, got {}: {}'.format(
             self, image_data.shape[0], rows_got, err)
         raise error.PanError(message)
     else:
         fits_utils.write_fits(data=image_data,
                               header=header,
                               filename=filename)
Esempio n. 4
0
    def _video_readout(self, width, height, image_type, timeout, filename_root,
                       file_extension, max_frames, header):

        start_time = time.monotonic()
        good_frames = 0
        bad_frames = 0

        # Calculate number of bits that have been used to pad the raw data to RAW16 format.
        if self.image_type == 'RAW16':
            pad_bits = 16 - int(get_quantity_value(self.bit_depth, u.bit))
        else:
            pad_bits = 0

        for frame_number in range(max_frames):
            if self._video_event.is_set():
                break
            # This call will block for up to timeout milliseconds waiting for a frame
            video_data = Camera._driver.get_video_data(self._handle, width,
                                                       height, image_type,
                                                       timeout)
            if video_data is not None:
                now = Time.now()
                header.set('DATE-OBS', now.fits, 'End of exposure + readout')
                filename = "{}_{:06d}.{}".format(filename_root, frame_number,
                                                 file_extension)
                # Fix 'raw' data scaling by changing from zero padding of LSBs
                # to zero padding of MSBs.
                video_data = np.right_shift(video_data, pad_bits)
                fits_utils.write_fits(video_data, header, filename)
                good_frames += 1
            else:
                bad_frames += 1

        if frame_number == max_frames - 1:
            # No one callled stop_video() before max_frames so have to call it here
            self.stop_video()

        elapsed_time = (time.monotonic() - start_time) * u.second
        self.logger.debug(
            "Captured {} of {} frames in {:.2f} ({:.2f} fps), {} frames lost".
            format(good_frames, max_frames, elapsed_time,
                   get_quantity_value(good_frames / elapsed_time), bad_frames))
Esempio n. 5
0
    def _readout(self, filename, readout_mode, top, left, height, width,
                 header):
        exposure_status = Camera._driver.get_exposure_status(self._handle)
        if exposure_status == 'CS_INTEGRATION_COMPLETE':
            try:
                image_data = Camera._driver.readout(self._handle, readout_mode,
                                                    top, left, height, width)
            except RuntimeError as err:
                raise error.PanError('Readout error on {}, {}'.format(
                    self, err))
            else:
                fits_utils.write_fits(data=image_data,
                                      header=header,
                                      filename=filename)

        elif exposure_status == 'CS_IDLE':
            raise error.PanError("Exposure missing on {}".format(self))
        else:
            raise error.PanError(
                "Unexpected exposure status on {}: '{}'".format(
                    self, exposure_status))