def produceAlignedImagesStep(self, volumeIsCTFCorrected, fn, images): from numpy import array, dot fnOut = 'classes_aligned@' + fn MDin = MetaData(images) MDout = MetaData() n = 1 hasCTF = MDin.containsLabel(xmipp.MDL_CTF_MODEL) for i in MDin: fnImg = MDin.getValue(xmipp.MDL_IMAGE, i) fnImgRef = MDin.getValue(xmipp.MDL_IMAGE_REF, i) maxCC = MDin.getValue(xmipp.MDL_MAXCC, i) rot = MDin.getValue(xmipp.MDL_ANGLE_ROT, i) tilt = MDin.getValue(xmipp.MDL_ANGLE_TILT, i) psi = -1. * MDin.getValue(xmipp.MDL_ANGLE_PSI, i) flip = MDin.getValue(xmipp.MDL_FLIP, i) if flip: psi = -psi eulerMatrix = Euler_angles2matrix(0., 0., psi) x = MDin.getValue(xmipp.MDL_SHIFT_X, i) y = MDin.getValue(xmipp.MDL_SHIFT_Y, i) shift = array([x, y, 0]) shiftOut = dot(eulerMatrix, shift) [x, y, z] = shiftOut if flip: x = -x id = MDout.addObject() MDout.setValue(xmipp.MDL_IMAGE, fnImg, id) MDout.setValue(xmipp.MDL_IMAGE_REF, fnImgRef, id) MDout.setValue(xmipp.MDL_IMAGE1, "%05d@%s" % (n, self._getExtraPath("diff.stk")), id) if hasCTF: fnCTF = MDin.getValue(xmipp.MDL_CTF_MODEL, i) MDout.setValue(xmipp.MDL_CTF_MODEL, fnCTF, id) MDout.setValue(xmipp.MDL_MAXCC, maxCC, id) MDout.setValue(xmipp.MDL_ANGLE_ROT, rot, id) MDout.setValue(xmipp.MDL_ANGLE_TILT, tilt, id) MDout.setValue(xmipp.MDL_ANGLE_PSI, psi, id) MDout.setValue(xmipp.MDL_SHIFT_X, x, id) MDout.setValue(xmipp.MDL_SHIFT_Y, y, id) MDout.setValue(xmipp.MDL_FLIP, flip, id) MDout.setValue(xmipp.MDL_ENABLED, 1, id) n += 1 MDout.write(fnOut, xmipp.MD_APPEND) # Actually create the differences img = Image() imgRef = Image() if hasCTF and volumeIsCTFCorrected: Ts = MDin.getValue(xmipp.MDL_SAMPLINGRATE, MDin.firstObject()) for i in MDout: img.readApplyGeo(MDout, i) imgRef.read(MDout.getValue(xmipp.MDL_IMAGE_REF, i)) if hasCTF and volumeIsCTFCorrected: fnCTF = MDout.getValue(xmipp.MDL_CTF_MODEL, i) imgRef.applyCTF(fnCTF, Ts) img.convert2DataType(DT_DOUBLE) imgDiff = img - imgRef imgDiff.write(MDout.getValue(xmipp.MDL_IMAGE1, i))
def produceAlignedImagesStep(self, volumeIsCTFCorrected, fn, images): from numpy import array, dot fnOut = "classes_aligned@" + fn MDin = MetaData(images) MDout = MetaData() n = 1 hasCTF = MDin.containsLabel(xmipp.MDL_CTF_MODEL) for i in MDin: fnImg = MDin.getValue(xmipp.MDL_IMAGE, i) fnImgRef = MDin.getValue(xmipp.MDL_IMAGE_REF, i) maxCC = MDin.getValue(xmipp.MDL_MAXCC, i) rot = MDin.getValue(xmipp.MDL_ANGLE_ROT, i) tilt = MDin.getValue(xmipp.MDL_ANGLE_TILT, i) psi = -1.0 * MDin.getValue(xmipp.MDL_ANGLE_PSI, i) flip = MDin.getValue(xmipp.MDL_FLIP, i) if flip: psi = -psi eulerMatrix = Euler_angles2matrix(0.0, 0.0, psi) x = MDin.getValue(xmipp.MDL_SHIFT_X, i) y = MDin.getValue(xmipp.MDL_SHIFT_Y, i) shift = array([x, y, 0]) shiftOut = dot(eulerMatrix, shift) [x, y, z] = shiftOut if flip: x = -x id = MDout.addObject() MDout.setValue(xmipp.MDL_IMAGE, fnImg, id) MDout.setValue(xmipp.MDL_IMAGE_REF, fnImgRef, id) MDout.setValue(xmipp.MDL_IMAGE1, "%05d@%s" % (n, self._getExtraPath("diff.stk")), id) if hasCTF: fnCTF = MDin.getValue(xmipp.MDL_CTF_MODEL, i) MDout.setValue(xmipp.MDL_CTF_MODEL, fnCTF, id) MDout.setValue(xmipp.MDL_MAXCC, maxCC, id) MDout.setValue(xmipp.MDL_ANGLE_ROT, rot, id) MDout.setValue(xmipp.MDL_ANGLE_TILT, tilt, id) MDout.setValue(xmipp.MDL_ANGLE_PSI, psi, id) MDout.setValue(xmipp.MDL_SHIFT_X, x, id) MDout.setValue(xmipp.MDL_SHIFT_Y, y, id) MDout.setValue(xmipp.MDL_FLIP, flip, id) MDout.setValue(xmipp.MDL_ENABLED, 1, id) n += 1 MDout.write(fnOut, xmipp.MD_APPEND) # Actually create the differences img = Image() imgRef = Image() if hasCTF and volumeIsCTFCorrected: Ts = MDin.getValue(xmipp.MDL_SAMPLINGRATE, MDin.firstObject()) for i in MDout: img.readApplyGeo(MDout, i) imgRef.read(MDout.getValue(xmipp.MDL_IMAGE_REF, i)) if hasCTF and volumeIsCTFCorrected: fnCTF = MDout.getValue(xmipp.MDL_CTF_MODEL, i) imgRef.applyCTF(fnCTF, Ts) img.convert2DataType(DT_DOUBLE) imgDiff = img - imgRef imgDiff.write(MDout.getValue(xmipp.MDL_IMAGE1, i))
def preRun(self): self.ImportProtocol() self.Iteration_Working_Directory = os.path.join(self.pmprotWorkingDir,'Iter_00'+ str(self.iterationNo)) self.subtractionDir = self.workingDirPath(self.RunName) self.volsDir = self.workingDirPath(self.volsDir) self.referenceDir = self.workingDirPath(self.referenceDir) self.subImgsDir = self.workingDirPath(self.subImgsDir) self.scaledImages = self.workingDirPath(self.scaledImages) self.resultsImagesName = self.workingDirPath(self.resultsImagesName) self.localFilenameCurrentAngles = self.workingDirPath(self.localCurrentAngles) self.CtfGroupDirectory = self.workingDirPath(self.CtfGroupDirectoryName) tmpCTFname = join(self.CtfGroupDirectoryName,self.localStackCTFs) self.projmatchStackCTFs = join(self.pmprotWorkingDir,tmpCTFname) self.localStackCTFs = self.workingDirPath(tmpCTFname) tmpCTFname = join(self.CtfGroupDirectoryName,self.localDocCTFs) self.projmatchDocCTFs = join(self.pmprotWorkingDir,tmpCTFname) self.localDocCTFs = self.workingDirPath(tmpCTFname) if(self.MaxChangeInAngles > 100): self.MaxChangeInAngles=-1 tmpFilename = self.current_angles self.filename_currentAngles = os.path.join(self.Iteration_Working_Directory,tmpFilename) if(self.doScaleImages): md = MetaData(self.filename_currentAngles) img = Image() img.readApplyGeo(md, 1, False, DATA, ALL_IMAGES,False) x=y=z=n=0 (x,y,z,n) = img.getDimensions() factorX = x / self.dimX if (self.dimY<0): factorY = y / self.dimX else: factorY = y / self.dimY self.dRradiusMax = round(self.dRradiusMax/factorX) self.dRradiusMin = round(self.dRradiusMin/factorY)