def acquireEmptyCameraImageData(self):
     imagedata = leginondata.CameraImageData()
     imagedata['session'] = self.session
     scopedata = self.instrument.getData(leginondata.ScopeEMData)
     cameradata = self.instrument.getData(leginondata.CameraEMData)
     imagedata['scope'] = scopedata
     imagedata['camera'] = cameradata
     return imagedata
예제 #2
0
        def acquireCameraImageData(self, scopeclass=leginondata.ScopeEMData, allow_retracted=False, type='normal'):
                '''Acquire a raw image from the currently configured CCD camera'''

                ## Retract the cameras that are above this one (higher zplane)
                for name,cam in self.instrument.ccdcameras.items():
                        if cam.Zplane > self.instrument.ccdcamera.Zplane:
                                try:
                                        if cam.Inserted:
                                                cam.Inserted = False
                                                self.logger.info('retracted camera: %s' % (name,))
                                except:
                                        pass

                ## insert the current camera, unless allow_retracted
                if not allow_retracted:
                        try:
                                inserted = self.instrument.ccdcamera.Inserted
                        except:
                                inserted = True
                        if not inserted:
                                camname = self.instrument.getCCDCameraName()
                                self.logger.info('inserting camera: %s' % (camname,))
                                self.instrument.ccdcamera.Inserted = True

                ## set type to normal or dark
                self.instrument.ccdcamera.ExposureType = type

                imagedata = leginondata.CameraImageData()
                imagedata['session'] = self.session

                ## make sure shutter override is activated
                try:
                        self.instrument.tem.ShutterControl = True
                except:
                        # maybe tem has no such function
                        pass

                ## acquire image, get new scope/camera params
                try:
                        scopedata = self.instrument.getData(scopeclass)
                except:
                        raise
                #cameradata_before = self.instrument.getData(leginondata.CameraEMData)
                imagedata['scope'] = scopedata
                self.startExposureTimer()
                imagedata['image'] = self.instrument.ccdcamera.Image
                cameradata_after = self.instrument.getData(leginondata.CameraEMData)
                ## only using cameradata_after, not cameradata_before
                imagedata['camera'] = cameradata_after

                ## duplicating 'use frames' here because we may reuse same
                ## CameraEMData for multiple versions of AcquisitionImageData
                imagedata['use frames'] = cameradata_after['use frames']

                self.readout_done_event.set()
                return imagedata
예제 #3
0
    def calc_norm(self, refdata):
        scopedata = refdata['scope']
        cameradata = refdata['camera']
        channel = refdata['channel']
        if isinstance(refdata, leginondata.DarkImageData):
            dark = refdata
            bright = self.retrieveCorrectorImageData('bright', scopedata,
                                                     cameradata, channel)
            if bright is None:
                self.logger.warning(
                    'No bright reference image for normalization calculations')
                return
        if isinstance(refdata, leginondata.BrightImageData):
            bright = refdata
            dark = self.retrieveCorrectorImageData('dark', scopedata,
                                                   cameradata, channel)
            if dark is None:
                self.logger.warning(
                    'No dark reference image for normalization calculations')
                return
        try:
            darkarray = self.prepareDark(dark, bright)
        except:
            self.logger.warning('Unable to load dark image from %s' %
                                dark['session']['image path'])
            return
        try:
            brightarray = bright['image']
        except:
            self.logger.warning('Unable to load bright image from %s' %
                                bright['session']['image path'])
            return

        try:
            normarray = brightarray - darkarray
        except:
            self.logger.error('dark subtraction failed.')
            return
        normarray = numpy.asarray(normarray, numpy.float32)
        normavg = arraystats.mean(normarray)

        # division may result infinity or zero division
        # so make sure there are no zeros in norm
        normarray = numpy.clip(normarray, 0.001, sys.maxint)
        normarray = normavg / normarray
        # Avoid over correcting dead pixels
        normarray = numpy.ma.masked_greater(normarray, 20).filled(1)
        # Saving normdata
        normdata = leginondata.CameraImageData(initializer=refdata)
        normdata['image'] = normarray
        normdata['dark'] = dark
        normdata['bright'] = bright
        self.storeCorrectorImageData(normdata, 'norm', channel)
    def acquire(self):
        #This replaces the function of the same name in ManualAcquisition
        #to pretend an image acquisition
        self.logger.info('Loading image as if acquired...')
        self.instrument.ccdcamera.Settings = self.uploadedInfo[
            'camera settings']

        try:
            image = self.uploadedInfo['image']
            scope = self.instrument.getData(leginondata.ScopeEMData)
            camera = self.instrument.getData(leginondata.CameraEMData)
            imagedata = leginondata.CameraImageData(image=image,
                                                    scope=scope,
                                                    camera=camera)
            imagedata['session'] = self.session
        except Exception, e:
            self.logger.exception('Error loading image: %s' % e)
            raise AcquireError
예제 #5
0
    def acquireCameraImageData(self,
                               scopeclass=leginondata.ScopeEMData,
                               allow_retracted=False,
                               type='normal'):
        '''Acquire a raw image from the currently configured CCD camera'''
        self.prepareToAcquire(allow_retracted, exposure_type=type)
        ## set type to normal or dark
        self.instrument.ccdcamera.ExposureType = type

        imagedata = leginondata.CameraImageData()
        imagedata['session'] = self.session

        ## make sure shutter override is activated
        try:
            self.instrument.tem.ShutterControl = True
        except:
            # maybe tem has no such function
            pass

        ## acquire image, get new scope/camera params
        try:
            scopedata = self.instrument.getData(scopeclass)
        except:
            raise
        #cameradata_before = self.instrument.getData(leginondata.CameraEMData)
        imagedata['scope'] = scopedata
        self.startExposureTimer()
        imagedata['image'] = self.instrument.ccdcamera.Image
        cameradata_after = self.instrument.getData(leginondata.CameraEMData)
        ## only using cameradata_after, not cameradata_before
        imagedata['camera'] = cameradata_after

        ## duplicating 'use frames' here because we may reuse same
        ## CameraEMData for multiple versions of AcquisitionImageData
        imagedata['use frames'] = cameradata_after['use frames']

        self.readout_done_event.set()
        return imagedata
예제 #6
0
                             (i + 1, n))
            try:
                imagedata = self.acquireCameraImageData(type=exposuretype)
            except Exception, e:
                self.logger.error('Error acquiring image: %s' % e)
                raise
            if self.settings['store series']:
                self.storeCorrectorImageData(imagedata, type, channel)
            imagearray = imagedata['image']
            if i == 0:
                avg = numpy.asarray(imagearray, numpy.float32)
            else:
                delta = imagearray - avg
                avg = avg + delta / (i + 1)
        ## final image based on contents of last image in series
        finaldata = leginondata.CameraImageData(initializer=imagedata)
        finaldata['image'] = avg
        finaldata = self.storeCorrectorImageData(finaldata, type, channel)
        return finaldata

    def acquireSeriesMedian(self, n, type, channel):
        series = []
        if type == 'dark':
            exposuretype = 'dark'
        else:
            exposuretype = 'normal'
        for i in range(n):
            self.logger.info('Acquiring reference image (%s of %s)' %
                             (i + 1, n))
            try:
                imagedata = self.acquireCameraImageData(type=exposuretype)