def start(self): ###do queries sessiondata = apDatabase.getSessionDataFromSessionName( self.params['sessionname']) self.sessiondata = sessiondata tiltseriesdata = apDatabase.getTiltSeriesDataFromTiltNumAndSessionId( self.params['tiltseries'], sessiondata) tiltseriessettings = apTomo.getTomographySettings( sessiondata, tiltseriesdata) tiltdata = apTomo.getImageList([tiltseriesdata]) description = self.params['description'] apDisplay.printMsg("getting imagelist") print "ordering list" tilts, ordered_imagelist, ordered_mrc_files, refimg = apTomo.orderImageList( tiltdata) #tilts are tilt angles, ordered_imagelist are imagedata, ordered_mrc_files are paths to files, refimg is an int ###set up files seriesname = 'series' + str(self.params['tiltseries']) tiltfilename = seriesname + '.tlt' param_out = seriesname + '.param' maxtilt = max([abs(tilts[0]), abs(tilts[-1])]) apDisplay.printMsg("highest tilt angle is %f" % maxtilt) self.params['cos_alpha'] = math.cos(maxtilt * math.pi / 180) self.params['raw_path'] = os.path.join(self.params['rundir'], 'raw') rawexists = apParam.createDirectory(self.params['raw_path']) apDisplay.printMsg("copying raw images") newfilenames = apProTomo.getImageFiles(ordered_imagelist, self.params['raw_path'], link=False) #get alignment data alignerdata = apTomo.getAlignerdata(self.params['alignerid']) imgshape = apTomo.getTomoImageShape(ordered_imagelist[0]) imgcenter = {'x': self.imgshape[1] / 2, 'y': self.imgshape[0] / 2} specimen_euler, azimuth, origins, rotations = apTomo.getAlignmentFromDB( alignerdata, imgcenter) #write protomo2 tilt file outtltfile = 'series.tlt' seriesname = 'series' apProTomo.writeTiltFile2(outfilename, seriesname, specimen_eulers, azimuth, referenceimage)
def start(self): ### some of this should go in preloop functions ###do queries sessiondata = apDatabase.getSessionDataFromSessionName(self.params['sessionname']) self.sessiondata = sessiondata tiltseriesdata = apDatabase.getTiltSeriesDataFromTiltNumAndSessionId(self.params['tiltseries'],sessiondata) tiltdata=apTomo.getImageList([tiltseriesdata]) description = self.params['description'] apDisplay.printMsg("getting imagelist") tilts,ordered_imagelist,ordered_mrc_files,refimg = apTomo.orderImageList(tiltdata) #tilts are tilt angles, ordered_imagelist are imagedata, ordered_mrc_files are paths to files, refimg is an int ###set up files seriesname='series'+str(self.params['tiltseries']) tiltfilename=seriesname+'.tlt' param_out=seriesname+'.param' maxtilt=max([abs(tilts[0]),abs(tilts[-1])]) apDisplay.printMsg("highest tilt angle is %f" % maxtilt) self.params['cos_alpha']=math.cos(maxtilt*math.pi/180) self.params['raw_path']=os.path.join(self.params['rundir'],'raw') rawexists=apParam.createDirectory(self.params['raw_path']) apDisplay.printMsg("copying raw images") newfilenames=apProTomo.getImageFiles(ordered_imagelist,self.params['raw_path'], link=False) ###create tilt file #get image size from the first image imagesizex=tiltdata[0]['image'].shape[0] imagesizey=tiltdata[0]['image'].shape[1] #shift half tilt series relative to eachother #SS I'm arbitrarily making the bin parameter here 1 because it's not necessary to sample at this point shifts = apTomo.getGlobalShift(ordered_imagelist, 1, refimg) #OPTION: refinement might be more robust by doing one round of IMOD aligment to prealign images before doing protomo refine origins=apProTomo2Prep.convertShiftsToOrigin(shifts, imagesizex, imagesizey) #determine azimuth azimuth=apTomo.getAverageAzimuthFromSeries(ordered_imagelist) apProTomo2Prep.writeTileFile2(tiltfilename, seriesname, newfilenames, origins, tilts, azimuth, refimg)
def prepareTiltFile(sessionname, seriesname, tiltfilename, tiltseriesnumber, raw_path, frame_aligned_images, link=False, coarse=True): ''' Creates tlt file from basic image information and copies raw images ''' sessiondata = apDatabase.getSessionDataFromSessionName(sessionname) tiltseriesdata = apDatabase.getTiltSeriesDataFromTiltNumAndSessionId(tiltseriesnumber,sessiondata) tiltdata = apTomo.getImageList([tiltseriesdata]) apDisplay.printMsg("getting imagelist") frame_tiltdata, non_frame_tiltdata = frameOrNonFrameTiltdata(tiltdata) tilts,ordered_imagelist,accumulated_dose_list,ordered_mrc_files,refimg = apTomo.orderImageList(frame_tiltdata, non_frame_tiltdata, frame_aligned=frame_aligned_images) if frame_aligned_images == "True": #Azimuth is only present in the non-frame aligned images a,ordered_imagelist_for_azimuth,c,d,e = apTomo.orderImageList(frame_tiltdata, non_frame_tiltdata, frame_aligned="False") #tilts are tilt angles, ordered_imagelist are imagedata, ordered_mrc_files are paths to files, refimg is an int maxtilt = max([abs(tilts[0]),abs(tilts[-1])]) apDisplay.printMsg("highest tilt angle is %f" % maxtilt) if coarse == "True": if frame_aligned_images == "True": #Azimuth is only present in the non-frame aligned images azimuth = apTomo.getAverageAzimuthFromSeries(ordered_imagelist_for_azimuth) else: azimuth = apTomo.getAverageAzimuthFromSeries(ordered_imagelist) rawexists = apParam.createDirectory(raw_path) apDisplay.printMsg("Copying raw images, y-flipping, normalizing, and converting images to float32 for Protomo...") #Linking removed because raw images need to be y-flipped for Protomo:(. newfilenames, new_ordered_imagelist = apProTomo.getImageFiles(ordered_imagelist, raw_path, link=False, copy="True") ###create tilt file #get image size from the first image imagesizex = tiltdata[0]['image'].shape[1] imagesizey = tiltdata[0]['image'].shape[0] #shift half tilt series relative to eachother #SS I'm arbitrarily making the bin parameter here 1 because it's not necessary to sample at this point shifts = apTomo.getGlobalShift(ordered_imagelist, 1, refimg) #OPTION: refinement might be more robust by doing one round of IMOD aligment to prealign images before doing protomo refine origins = convertShiftsToOrigin(shifts, imagesizex, imagesizey) writeTiltFile2(tiltfilename, seriesname, newfilenames, origins, tilts, azimuth, refimg) return tilts, accumulated_dose_list, new_ordered_imagelist, maxtilt
def doseCompensate(seriesname, rundir, sessionname, tiltseriesnumber, frame_aligned_images, raw_path, pixelsize, dose_presets, dose_a, dose_b, dose_c): """ Images will be lowpass filtered using equation (3) from Grant & Grigorieff, 2015. No changes to the database are made. No backups are made. """ sessiondata = apDatabase.getSessionDataFromSessionName(sessionname) tiltseriesdata = apDatabase.getTiltSeriesDataFromTiltNumAndSessionId(tiltseriesnumber,sessiondata) tiltdata = apTomo.getImageList([tiltseriesdata]) frame_tiltdata, non_frame_tiltdata = frameOrNonFrameTiltdata(tiltdata) tilts, ordered_imagelist, accumulated_dose_list, ordered_mrc_files, refimg = apTomo.orderImageList(frame_tiltdata, non_frame_tiltdata, frame_aligned="False") if frame_aligned_images == "True": #For different image filenames a, ordered_imagelist, c, d, e = apTomo.orderImageList(frame_tiltdata, non_frame_tiltdata, frame_aligned=frame_aligned_images) newfilenames, new_ordered_imagelist = apProTomo.getImageFiles(ordered_imagelist, raw_path, link=False, copy=False) if (dose_presets == "Light"): dose_a = 0.245 dose_b = -1.6 dose_c = 12 elif (dose_presets == "Moderate"): dose_a = 0.245 dose_b = -1.665 dose_c = 2.81 elif (dose_presets == "Heavy"): dose_a = 0.245 dose_b = -1.4 dose_c = 2 apDisplay.printMsg('Dose compensating all tilt images with a=%s, b=%s, and c=%s...' % (dose_a, dose_b, dose_c)) for image, j in zip(new_ordered_imagelist, range(len(new_ordered_imagelist))): lowpass = float(np.real(complex(dose_a/(accumulated_dose_list[j] - dose_c))**(1/dose_b))) #equation (3) from Grant & Grigorieff, 2015 if lowpass < 0.0: lowpass = 0.0 im = mrc.read(image) im = imagefilter.lowPassFilter(im, apix=pixelsize, radius=lowpass, msg=False) im=imagenorm.normStdev(im) mrc.write(im, image) #Make plots apProTomo2Aligner.makeDosePlots(rundir, seriesname, tilts, accumulated_dose_list, dose_a, dose_b, dose_c) apDisplay.printMsg("Dose compensation finished for tilt-series #%s!" % tiltseriesnumber) return
def start(self): ###do queries sessiondata = apDatabase.getSessionDataFromSessionName(self.params['sessionname']) self.sessiondata = sessiondata tiltseriesdata = apDatabase.getTiltSeriesDataFromTiltNumAndSessionId(self.params['tiltseries'],sessiondata) tiltseriessettings= apTomo.getTomographySettings(sessiondata,tiltseriesdata) tiltdata=apTomo.getImageList([tiltseriesdata]) description = self.params['description'] apDisplay.printMsg("getting imagelist") print "ordering list" tilts,ordered_imagelist,ordered_mrc_files,refimg = apTomo.orderImageList(tiltdata) #tilts are tilt angles, ordered_imagelist are imagedata, ordered_mrc_files are paths to files, refimg is an int ###set up files seriesname='series'+str(self.params['tiltseries']) tiltfilename=seriesname+'.tlt' param_out=seriesname+'.param' maxtilt=max([abs(tilts[0]),abs(tilts[-1])]) apDisplay.printMsg("highest tilt angle is %f" % maxtilt) self.params['cos_alpha']=math.cos(maxtilt*math.pi/180) self.params['raw_path']=os.path.join(self.params['rundir'],'raw') rawexists=apParam.createDirectory(self.params['raw_path']) apDisplay.printMsg("copying raw images") newfilenames=apProTomo.getImageFiles(ordered_imagelist,self.params['raw_path'], link=False) #get alignment data alignerdata = apTomo.getAlignerdata(self.params['alignerid']) imgshape = apTomo.getTomoImageShape(ordered_imagelist[0]) imgcenter = {'x':self.imgshape[1]/2,'y':self.imgshape[0]/2} specimen_euler, azimuth, origins, rotations = apTomo.getAlignmentFromDB(alignerdata,imgcenter) #write protomo2 tilt file outtltfile='series.tlt' seriesname='series' apProTomo.writeTiltFile2(outfilename, seriesname, specimen_eulers, azimuth, referenceimage )
param_out = seriesname+'.param' maxtilt = max([abs(tilts[0]),abs(tilts[-1])]) >>>>>>> .r18846 apDisplay.printMsg("highest tilt angle is %f" % maxtilt) self.params['cos_alpha'] = math.cos(maxtilt*math.pi/180) self.params['raw_path'] = os.path.join(self.params['rundir'],'raw') rawexists = apParam.createDirectory(self.params['raw_path']) <<<<<<< .mine ======= rawexists = apParam.createDirectory(self.params['raw_path']) >>>>>>> .r18846 apDisplay.printMsg("copying raw images") newfilenames = apProTomo.getImageFiles(ordered_imagelist,self.params['raw_path'], link=False) ###create tilt file #get image size from the first image <<<<<<< .mine imagesizex = tiltdata[0]['image'].shape[1] imagesizey = tiltdata[0]['image'].shape[0] ======= imagesizex = tiltdata[0]['image'].shape[0] imagesizey = tiltdata[0]['image'].shape[1] >>>>>>> .r18846 #shift half tilt series relative to eachother #SS I'm arbitrarily making the bin parameter here 1 because it's not necessary to sample at this point