|
#!/usr/bin/env python
|
|
import sys
|
|
from appionlib import apDDprocess, apDatabase
|
|
from pyami import mrc, imagefun
|
|
|
|
def printDark(dd):
|
|
darkdata = dd.getRefImageData('dark')
|
|
nframes = dd.getNumberOfFrameSavedFromImageData(darkdata)
|
|
print 'darkdata:'
|
|
print 'number of frames:',darkdata['nframe']
|
|
print 'frame time:', darkdata['frame time']
|
|
|
|
if __name__ == '__main__':
|
|
if len(sys.argv) != 5:
|
|
print 'Usage: correctframes.py sessionname start_frame nframe image'
|
|
print ' sessionname (str): leginon sessionname used to identify dd models'
|
|
print ' start_frame (int): first frame to use (minimal=0)'
|
|
print ' nframe (int): number of frames to sum up'
|
|
print ' image (str or int): imagefilename or imageid'
|
|
sys.exit()
|
|
sessionname = sys.argv[1]
|
|
start_frame = int(sys.argv[2])
|
|
nframe = int(sys.argv[3])
|
|
imagevalue = sys.argv[4]
|
|
dd = apDDprocess.initializeDDFrameprocess(sessionname)
|
|
dd.setUseGS(False)
|
|
dd.setUseAlternativeChannelReference(False)
|
|
try:
|
|
imageid = int(imagevalue)
|
|
dd.setImageId(imageid)
|
|
except ValueError:
|
|
imgtree = apDatabase.getSpecificImagesFromDB([imagevalue])
|
|
dd.setImageData(imgtree[0])
|
|
framelist = range(start_frame,start_frame+nframe)
|
|
corrected = dd.correctFrameImage(framelist,False)
|
|
print 'corrected_frame min, max:',corrected.min(),corrected.max()
|
|
# testing
|
|
printDark(dd)
|
|
|
|
# output
|
|
outfile = 'corrected_frame%d_%d.mrc' % (start_frame,nframe)
|
|
mrc.write(corrected,outfile)
|
|
print ' '
|
|
print 'Saved as %s' % (outfile)
|