Esempio n. 1
0
class Camera(BaseCamera):
    MODE_CONTINUOUS = 1
    MODE_SINGLE_SHOT = 0

    def __init__(self, camera):
        super().__init__(camera)

        self.running = False
        self.xsize = 1080
        self.ysize = 720
        self.sb = SimBrownian((self.xsize, self.ysize))
        self.maxX = 1800
        self.maxY = 720
        self.exposure = Q_('10ms')
        self.X = [0, self.maxX-1]
        self.Y = [0, self.maxY-1]
        self.logger = get_logger(name=__name__)

    def initialize(self):
        """Initializes the camera.
        """
        self.logger.info('Initializing camera')
        self.maxWidth = self.GetCCDWidth()
        self.maxHeight = self.GetCCDHeight()
        return True

    def trigger_camera(self):
        """Triggers the camera.
        """
        return True

    def set_acquisition_mode(self, mode):
        """
        Set the readout mode of the camera: Single or continuous.

        :param: int mode: One of self.MODE_CONTINUOUS, self.MODE_SINGLE_SHOT
        """
        self.logger.debug('Setting acquisition mode')
        return self.get_acquisition_mode()

    def get_acquisition_mode(self):
        """Returns the acquisition mode, either continuous or single shot.
        """
        return self.MODE_CONTINUOUS

    def acquisition_ready(self):
        """Checks if the acquisition in the camera is over.
        """
        return True

    def set_exposure(self, exposure):
        """Sets the exposure of the camera.
        """
        self.exposure = exposure
        self.sb.time_step = self.exposure.m_as('s')

    def get_exposure(self):
        """Gets the exposure time of the camera.
        """
        return self.exposure

    def read_camera(self):
        moment = time.time()
        sample = self.sb.gen_image()
        sample = sample.astype('uint8')
        elapsed = time.time() - moment
        if elapsed > self.exposure.m_as('s'):
            self.logger.warning('Generating a frame takes longer than exposure time')
        else:
            self.logger.debug('Sleeping for {}'.format(self.exposure.m_as('s') - elapsed))
            time.sleep(self.exposure.m_as('s') - elapsed)  # to simulate exposure time corrected for data generation delay
        return [sample]

    def set_ROI(self, X, Y):
        """
        Sets up the ROI. Not all cameras are 0-indexed, so this is an important
        place to define the proper ROI.

        :param X: array type with the coordinates for the ROI X[0], X[1]
        :param Y: array type with the coordinates for the ROI Y[0], Y[1]
        :return:
        """
        X = np.sort(X)
        Y = np.sort(Y)
        self.xsize = abs(X[1] - X[0])+1
        self.ysize = abs(Y[1] - Y[0])+1
        # self.sb.resize_view((self.xsize, self.ysize))
        self.X = X
        self.Y = Y
        self.X[1] -= 1
        self.Y[1] -= 1
        return self.get_size()

    def get_size(self):
        """
        :return: Returns the size in pixels of the image being acquired. This is useful for checking the ROI settings.
        """

        return self.xsize, self.ysize

    def getSerialNumber(self):
        """Returns the serial number of the camera.
        """
        return "Serial Number"

    def GetCCDWidth(self):
        """
        :return: The CCD width in pixels
        """
        return self.maxX

    def GetCCDHeight(self):
        """
        :return: The CCD height in pixels
        """
        return self.maxY

    def set_binning(self, xbin, ybin):
        """Sets the binning of the camera if supported. Has to check if binning in X/Y can be different or not, etc.

        :param: xbin: binning in x
        :param: ybin: binning in y
        """
        self.xbin = xbin
        self.ybin = ybin

    def stopAcq(self):
        pass

    def stop_camera(self):
        pass
Esempio n. 2
0
 def set_exposure(self, exposure: Q_) -> Q_:
     self.camera.ExposureTime.SetValue(exposure.m_as('us'))
     self.exposure = exposure
     return self.get_exposure()