Project

General

Profile

RE: Bad exposure shutter or normalizaton ยป findReferenceImages.py

Anchi Cheng, 02/02/2011 05:56 PM

 
#!/usr/bin/env python
import os
import leginon.leginondata

# Change filename here if you are looking for other images
filename = '11feb02c_80S-2_00013gr_00005sq_00002hl_v06_00003en'

print "Looking for gain reference images for \n%s.mrc" % (filename)
refdata = {'norm':None,'dark':None,'bright':None}
# query database for the image data object
q = leginon.leginondata.AcquisitionImageData(filename=filename)
r = q.query()
if r:
imagedata = r[0]
# Find norm and dark image data object
for reftype in ('norm','dark'):
refdata[reftype] = imagedata[reftype]
if refdata['norm']:
# Find bright image data object by timestamp since it is not referenced
# in the database. Will add this in new verion
normdata = refdata['norm']
timestamp = normdata.timestamp
normcam = normdata['camera']
qcam = leginon.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 = leginon.leginondata.ScopeEMData(tem=normscope['tem'])
qscope['high tension'] = normscope['high tension']
q = leginon.leginondata.BrightImageData(camera=qcam,scope=qscope,channel=normdata['channel'])
brightlist = q.query()
for brightdata in brightlist:
if brightdata.timestamp < timestamp:
break
refdata['bright'] = brightdata

# Display the results
for reftype in refdata.keys():
print '---------------------------'
if refdata[reftype]:
refpath = refdata[reftype]['session']['image path']
print reftype+' image used is '
print os.path.join(refpath,refdata[reftype]['filename']+'.mrc')
else:
print "no "+reftype+" image found"
    (1-1/1)