def getCCDCameraData(self, name=None):
     if name is None:
         if self.ccdcamera is None:
             return None
         else:
             name = self.ccdcamera._name
             #dbtype = self.ccdcamera.DatabaseType
     else:
         if name not in self.ccdcameras:
             raise RuntimeError('no CCD camera \'%s\' available' % name)
     instrumentdata = leginondata.InstrumentData()
     instrumentdata['name'] = name
     #instrumentdata['type'] = dbtype
     #print dbtype
     try:
         instrumentdata['hostname'] = self.ccdcameras[name].Hostname
     except:
         raise RuntimeError('unable to get TEM hostname')
     results = instrumentdata.query(results=1)
     ## save in DB if not already there
     if results:
         dbinstrumentdata = results[0]
     else:
         dbinstrumentdata = instrumentdata
         dbinstrumentdata.insert()
     return dbinstrumentdata
Ejemplo n.º 2
0
	def getRelatedFrameCameras(self,camdata):
		r = leginondata.InstrumentData(hostname=camdata['ccdcamera']['hostname']).query()
		k2cameras = []
		for instrumentdata in r:
			if instrumentdata['name'] in VALID_CAMERA_NAMES:
				k2cameras.append(instrumentdata)
		return k2cameras
    def importInstrument(self):
        print "Importing instrument...."
        self.is_upload = False
        # guess instrument from the last image
        sinedon.setConfig('leginondata', db=self.source_dbname)
        q = leginondata.AcquisitionImageData(session=self.getSourceSession())
        last_image = self.research(q, True)
        # we know there are images for the session.
        tem = last_image['scope']['tem']
        camera = last_image['camera']['ccdcamera']
        if tem is None:
            # old uploaded session such as 12jun29b
            self.is_upload = True
            return None, None, 200000

        high_tension = last_image['scope']['high tension']
        q = leginondata.InstrumentData()
        source_temdata = q.direct_query(tem.dbid)
        source_cameradata = q.direct_query(camera.dbid)

        if 'appion' in source_temdata['name'].lower():
            self.is_upload = True

        sinedon.setConfig('leginondata', db=self.destination_dbname)
        tem.insert(archive=True)
        camera.insert(archive=True)

        return source_cameradata, source_temdata, high_tension
def querypoints(axis, label, hostname):
    tem = leginondata.InstrumentData(hostname=hostname)
    sm = leginondata.StageMeasurementData(label=label, axis=axis, tem=tem)
    points = sm.query()
    xy = []
    for point in points:
        x = point[axis]
        y = math.hypot(point['imagex'], point['imagey']) / abs(point['delta'])
        xy.append((x, y))
    return xy
def querymodelmag(axis, label, hostname):
    tem = leginondata.InstrumentData(hostname=hostname)
    sm = leginondata.StageModelMagCalibrationData(axis=axis,
                                                  label=label,
                                                  tem=tem)
    magcal = sm.query(results=1)
    magcal = magcal[0]
    print 'MAGCAL', magcal.timestamp
    print magcal
    mean = magcal['mean']
    return 1.0 / mean
Ejemplo n.º 6
0
    def saveMagnifications(self, instance, tem_name):
        self.logger.info('Saving...')
        instrumentdata = leginondata.InstrumentData()
        instrumentdata['name'] = tem_name
        instrumentdata['hostname'] = instance.getHostname()

        instrumentdata['cs'] = instance.getCs()
        magnificationsdata = leginondata.MagnificationsData()
        magnificationsdata['instrument'] = instrumentdata
        magnificationsdata['magnifications'] = instance.getMagnifications()
        self.publish(magnificationsdata, database=True, dbforce=True)
        self.logger.info('Magnifications saved.')
        return magnificationsdata
def querymodel(axis, hostname, label=None):
    tem = leginondata.InstrumentData(hostname=hostname)
    sm = leginondata.StageModelCalibrationData(axis=axis, tem=tem, label=label)
    model = sm.query(results=1)
    if not model:
        return None
    model = model[0]
    print 'MODEL', model.timestamp
    print model
    model['a'].shape = (-1, )
    model['b'].shape = (-1, )
    mod = gonmodel.GonModel()
    mod.fromDict(model)
    return mod
    def upgradeLeginonDB(self):
        if not self.leginon_dbupgrade.columnExists(
                'AcquisitionImageData',
                'REF|CorrectorPlanData|corrector plan'):
            self.leginon_dbupgrade.addColumn(
                'AcquisitionImageData', 'REF|CorrectorPlanData|corrector plan',
                self.leginon_dbupgrade.int)

        results = leginondata.InstrumentData(name='DE12').query(results=1)
        if not results:
            return
        decameradata = results[0]

        dim = {'x': 4096, 'y': 3072}
        camq = leginondata.CameraEMData(ccdcamera=decameradata, dimension=dim)
        plans = leginondata.CorrectorPlanData(camera=camq).query()
        pairs = {}
        ordered_keys = []
        for i, plan in enumerate(plans):
            if i == 0:
                ordered_keys.append(i)
                pairs[i] = (plan.timestamp.now(), plan.timestamp)
            else:
                ordered_keys.append(i)
                pairs[i] = (plans[i - 1].timestamp, plan.timestamp)
        camq = leginondata.CameraEMData(ccdcamera=decameradata, dimension=dim)
        camq['save frames'] = True
        imageq = leginondata.AcquisitionImageData(camera=camq)
        print 'Query all DE12 images.  This may take some time...'
        images = imageq.query()
        print 'Total of %d images' % (len(images), )
        for image in images:
            if image['corrector plan']:
                continue
            for key in ordered_keys:
                if image.timestamp > pairs[key][1] and image.timestamp < pairs[
                        key][0]:
                    print key, image.dbid, image['filename'], image.timestamp
                    status = self.leginon_dbupgrade.updateColumn(
                        'AcquisitionImageData',
                        'REF|CorrectorPlanData|corrector plan',
                        '%d' % plans[key].dbid, '`DEF_id`=%d' % image.dbid,
                        True)
                    if not status:
                        print break_from_failed_update
 def getMagnifications(self, name):
     try:
         instance = self.instruments[name]
     except KeyError:
         raise ValueError('no instrument %s' % name)
     self.logger.info('Getting magnifications from the instrument...')
     instance.findMagnifications()
     self.logger.info('Saving...')
     instrumentdata = leginondata.InstrumentData()
     instrumentdata['name'] = name
     instrumentdata['hostname'] = instance.getHostname()
     instrumentdata['cs'] = instance.getCs()
     magnificationsdata = leginondata.MagnificationsData()
     magnificationsdata['instrument'] = instrumentdata
     magnificationsdata['magnifications'] = instance.getMagnifications()
     self.publish(magnificationsdata, database=True, dbforce=True)
     self.logger.info('Magnifications saved.')
     self.panel.onGetMagnificationsDone()
 def initializeMagnifications(self, name):
     try:
         instance = self.instruments[name]
     except KeyError:
         raise ValueError('no instrument %s' % name)
     if instance.getMagnificationsInitialized():
         return
     instrumentdata = leginondata.InstrumentData()
     instrumentdata['name'] = name
     instrumentdata['hostname'] = instance.getHostname()
     queryinstance = leginondata.MagnificationsData()
     queryinstance['instrument'] = instrumentdata
     try:
         result = self.research(queryinstance, results=1)[0]
     except IndexError:
         self.logger.warning('No magnifications saved for %s' % name)
         return
     instance.setMagnifications(result['magnifications'])
 def getTEMData(self, name=None):
     if name is None:
         if self.tem is None:
             return None
         else:
             name = self.tem._name
             cs = self.tem.Cs
             #dbtype = self.tem.DatabaseType
     else:
         if name not in self.tems:
             raise RuntimeError('no TEM \'%s\' available' % name)
         else:
             cs = None
     instrumentdata = leginondata.InstrumentData()
     instrumentdata['name'] = name
     #instrumentdata['type'] = dbtype
     #print dbtype
     try:
         instrumentdata['hostname'] = self.tems[name].Hostname
     except:
         raise RuntimeError('unable to get TEM hostname')
     results = instrumentdata.query(results=1)
     ## save in DB if not already there
     if results:
         dbinstrumentdata = results[0]
         if dbinstrumentdata['cs'] is None:
             raise RuntimeError(
                 'You must run db schema update script on existing TEMs before using this version of Leginon'
             )
         elif cs is not None and dbinstrumentdata['cs'] != cs:
             raise RuntimeError(
                 'TEM Cs in instruments.cfg does not match database value. Correct either one to use it in Leginon'
             )
     else:
         if cs is None:
             cs = 2.0e-3
         instrumentdata['cs'] = cs
         dbinstrumentdata = instrumentdata
         dbinstrumentdata.insert()
     return dbinstrumentdata
def msgExit(msg=''):
    if msg:
        print msg
    format_input('Hit Enter to exit')
    if msg != ok_msg:
        sys.exit(1)


def format_input(msg=''):
    print ''
    return raw_input(msg)


jeolcom_classname = format_input(
    'Enter scope classname in instruments.cfg (Case sensitive): ')
scopes = leginondata.InstrumentData(name=jeolcom_classname).query()

if len(scopes) > 1:
    print ''
    print "There are more than one instrument using jeolcom class"
    jeolcom_hostname = format_input(
        'Enter the hostname where the magnifications need registering: ')
    scopes = leginondata.InstrumentData(name=jeolcom_classname,
                                        hostname=jeolcom_hostname).query()
if not scopes:
    msg = "Error: Can not find a scope matching the description"
    msgExit(msg)

# There should be only one scope now.
j = jeolcom.Jeol()
j.findMagnifications()
Ejemplo n.º 13
0
#!/usr/bin/env python

from leginon import leginondata
import sys
from sinedon import newdict

host = sys.argv[1]
i = leginondata.InstrumentData(hostname=host)
s = leginondata.StageModelCalibrationData(tem=i)
models = s.query()

labels = newdict.OrderedDict()
for model in models:
    label = model['label']
    labels[label] = None
for label in labels.keys():
    print label