Project

General

Profile

RE: Super resolution format unavailable to calibrate matr... ยป copycal.py

Anchi Cheng, 03/19/2013 01:45 PM

 
#!/usr/bin/env python
import sys
from leginon import leginondata

if len(sys.argv) != 3:
print "This program copies existing GatanK2Counting matrix and stage model calibrations to GatanK2Super"
print "Usage copycal.py hostname high_tension"
print "high tension is an integer in volts, i.e., 200000"
sys.exit()

hostname = sys.argv[1]
high_tension = int(sys.argv[2])

results = leginondata.InstrumentData(hostname=hostname,name='GatanK2Counting').query(results=1)
if not results:
print "ERROR: incorrect hostname...."
r = leginondata.InstrumentData(name='GatanK2Counting').query(results=1)
if r:
print " Try %s instead" % r[0]['hostname']
else:
print " No GatanK2Counting camera found"
sys.exit()

sourcecam = results[0]
#sourcecam = leginondata.InstrumentData(hostname=hostname,name='GatanK2Super').query(results=1)[0]
destcam = leginondata.InstrumentData(hostname=hostname,name='GatanK2Super').query(results=1)[0]
pixelsize_scale = 2

def insertDest(newdata):
print "Uncomment in the script the line 'newdata.insert()' to insert to database"
#newdata.insert()
print ""
return

onecaldata = leginondata.MatrixCalibrationData(ccdcamera=sourcecam).query(results=1)[0]
temdata = onecaldata['tem']
magsdata = leginondata.MagnificationsData(instrument=temdata).query(results=1)[0]

#StageModelCalibrationData
for axis in ('x','y'):
results = leginondata.StageModelCalibrationData(ccdcamera=sourcecam,axis=axis).query(results=1)
if results:
newdata = leginondata.StageModelCalibrationData(initializer=results[0])
newdata['ccdcamera'] = destcam
print 'StageModelCalibrationData', newdata['period']
insertDest(newdata)

for mag in magsdata['magnifications']:
q = leginondata.StageModelMagCalibrationData(ccdcamera=sourcecam,axis=axis,magnification=mag)
q['high tension'] = high_tension
results = q.query(results=1)
if results:
newdata = leginondata.StageModelMagCalibrationData(initializer=results[0])
newdata['ccdcamera'] = destcam
newdata['mean'] /= pixelsize_scale
print 'StageModelMagCalibrationData', newdata['magnification'],newdata['mean']
insertDest(newdata)

for mag in magsdata['magnifications']:
# MatrixCarlibationData
for matrix_type in ('stage position','image shift','defocus','beam shift'):
q = leginondata.MatrixCalibrationData(ccdcamera=sourcecam,magnification=mag,type=matrix_type)
q['high tension']=high_tension
results = q.query(results=1)
if results:
caldata = results[0]
newdata = leginondata.MatrixCalibrationData(initializer=caldata)
newdata['ccdcamera'] = destcam
matrix = caldata['matrix']
matrix /= pixelsize_scale
newdata['matrix'] = matrix
print 'MatrixCalibrationData', newdata['type'],newdata['magnification'],newdata['matrix'][0,0]
insertDest(newdata)

raw_input('hit enter when ready to quit')
    (1-1/1)