def researchCorrectorImageData(self, type, scopedata, cameradata, channel):
        if type == 'dark':
            imagetemp = leginondata.DarkImageData()
        elif type == 'bright':
            imagetemp = leginondata.BrightImageData()
        elif type == 'norm':
            imagetemp = leginondata.NormImageData()
        else:
            return None

        ## query only based on certain camera parameters, not all
        imagetemp['camera'] = leginondata.CameraEMData()
        for key in ('ccdcamera', 'dimension', 'binning', 'offset',
                    'gain index'):
            imagetemp['camera'][key] = cameradata[key]
        # query only based on certain scope parameters, not all
        imagetemp['scope'] = leginondata.ScopeEMData()
        for key in ('tem', 'high tension'):
            imagetemp['scope'][key] = scopedata[key]
        imagetemp['channel'] = channel
        try:
            ref = imagetemp.query(results=1)
        except Exception, e:
            self.logger.warning('Reference image query failed: %s' % e)
            ref = None
    def findBrightImageFromNorm(self, normdata):
        '''
		Find BrighetImageData based on imported NormImageData.
		This is needed for older data since BrightImageData was
		not linked to AcquisitionImages previously.
		'''
        if normdata['bright']:
            return normdata['bright']
        timestamp = normdata.timestamp
        normcam = normdata['camera']
        qcam = leginondata.CameraEMData(dimension=normcam['dimension'],
                                        offset=normcam['offset'],
                                        binning=normcam['binning'],
                                        ccdcamera=normcam['ccdcamera'])
        qcam['exposure type'] = 'normal'
        qcam['energy filtered'] = normcam['energy filtered']

        normscope = normdata['scope']
        qscope = leginondata.ScopeEMData(tem=normscope['tem'])
        qscope['high tension'] = normscope['high tension']
        q = leginondata.BrightImageData(camera=qcam,
                                        scope=qscope,
                                        channel=normdata['channel'])
        brightlist = q.query()
        for brightdata in brightlist:
            if brightdata.timestamp < timestamp:
                break
        return brightdata
    def storeRef(self, type, numdata, camstate, scopedata, channel):
        ## another way to do the cache would be to use the local
        ## data keeper

        ccdcameraname = self.node.instrument.getCCDCameraName()
        ht = scopedata['high tension']
        ## store in cache
        key = self.refKey(camstate, type, ccdcameraname, scopedata, channel)
        self.cache[key] = numdata

        ## store in database
        if type == 'dark':
            imagetemp = leginondata.DarkImageData()
        elif type == 'bright':
            imagetemp = leginondata.BrightImageData()
        elif type == 'flat':
            imagetemp = leginondata.NormImageData()
        imagetemp['image'] = numdata
        imagetemp['camstate'] = camstate
        imagetemp['filename'] = self.filename(type, imagetemp.dmid[-1])
        imagetemp['session'] = self.node.session
        imagetemp['tem'] = self.node.instrument.getTEMData()
        imagetemp['ccdcamera'] = self.node.instrument.getCCDCameraData()
        imagetemp['scope'] = scopedata
        imagetemp['channel'] = channel
        self.node.logger.info('Publishing reference image...')
        try:
            self.node.publish(imagetemp, pubevent=True, database=True)
        except node.PublishError, e:
            self.node.logger.error('Publishing reference image failed: %s' %
                                   (e, ))
            return None
 def createRefQuery(self,reftype,qcam,qscope,channel):
         if reftype == 'norm':
                 q = leginondata.NormImageData(camera=qcam,scope=qscope,channel=channel)
         elif reftype == 'bright':
                 q = leginondata.BrightImageData(camera=qcam,scope=qscope,channel=channel)
         elif reftype == 'dark':
                 q = leginondata.DarkImageData(camera=qcam,scope=qscope,channel=channel)
         return q
    def getBrightImageFromNorm(self, normdata):
        '''
		Get bright image used to produce the norm image
		This is made to be back compatible to early leginondata that
		has no bright image association but would be the closest in time before
		the norm was calculated
		'''
        if normdata is None:
            return None
        # newer leginon data will have bright image associated with norm image
        if 'bright' in normdata.keys() and normdata['bright'] is not None:
            return normdata['bright']
        # bright image may have the same CameraEMData
        q = leginondata.BrightImageData(camera=normdata['camera'])
        brightresults = q.query(results=1)
        if brightresults:
            return brightresults[0]
        # otherwise need to look up timestamp
        timestamp = normdata.timestamp
        normcam = normdata['camera']
        qcam = leginondata.CameraEMData(dimension=normcam['dimension'],
                                        offset=normcam['offset'],
                                        binning=normcam['binning'],
                                        ccdcamera=normcam['ccdcamera'])
        qcam['exposure type'] = 'normal'
        qcam['energy filtered'] = normcam['energy filtered']
        qcam['gain index'] = normcam['gain index']

        normscope = normdata['scope']
        qscope = leginondata.ScopeEMData(tem=normscope['tem'])
        qscope['high tension'] = normscope['high tension']
        q = leginondata.BrightImageData(camera=qcam,
                                        scope=qscope,
                                        channel=normdata['channel'])
        brightlist = q.query()
        for brightdata in brightlist:
            if brightdata.timestamp < timestamp:
                break
        return brightdata
Ejemplo n.º 6
0
    args = parseArguments()
    totalimages = args.n
    sinedon.setConfig('leginondata')

    darkq = leginondata.DarkImageData()
    camq = leginondata.CameraEMData()
    camq['binning'] = {'y': long(args.b), 'x': long(args.b)}
    camq['dimension'] = {'y': long(args.y), 'x': long(args.x)}
    darkq['camera'] = camq
    print "querying dark images"
    darkdata = darkq.query(results=totalimages)
    darkdata.reverse()
    darkd = getGainInfo(darkdata, totalimages)

    brightq = leginondata.BrightImageData()
    brightq['camera'] = camq
    print "querying bright images"
    brightdata = brightq.query(results=totalimages)
    brightdata.reverse()
    brightd = getGainInfo(brightdata, totalimages)

    fig_base = plt.figure()
    fig1 = fig_base.add_subplot(111)
    plt.grid(True)

    #l1=fig1.errorbar(timelst,meanlst, 'bo', label='Dark mean', yerr=stdlst)
    fig1.plot(brightd['timelst'],
              brightd['meanlst'],
              'rv',
              label='Bright mean')