def generateMicImage(self, input_file, output_file=None): if not output_file: output_file = os.path.splitext(input_file)[0] + '.png' img = ImageHandler().createImage() img.read(input_file) pimg = getPILImage(img) pwutils.makeFilePath(output_file) pimg.save(output_file, "PNG")
def projectStep(self, start, end, samplingRate, threadNumber): # Project md = xmipp.MetaData(self._getInputParticlesSubsetFn(threadNumber)) ## projection = xmipp.Image() projection.setDataType(xmipp.DT_DOUBLE) ## for id in md: rot = md.getValue(xmipp.MDL_ANGLE_ROT, id) tilt = md.getValue(xmipp.MDL_ANGLE_TILT, id) psi = md.getValue(xmipp.MDL_ANGLE_PSI, id) ##projection =self.vol.projectVolumeDouble(rot, tilt, psi) self.fourierProjectVol.projectVolume(projection, rot, tilt, psi) ## # Apply CTF if self.projType == self.CORRECT_NONE: pass elif self.projType == self.CORRECT_FULL_CTF: projection.applyCTF(md, samplingRate, id, False) elif self.projType == self.CORRECT_PHASE_FLIP: projection.applyCTF(md, samplingRate, id, True) else: raise Exception("ERROR: Unknown projection mode: %d" % self.projType) # Shift image projection.applyGeo(md, id, True, False) #onlyapplyshist, wrap ih = ImageHandler() expProj = ih.read(md.getValue(xmipp.MDL_IMAGE, id)) expProj.convert2DataType(xmipp.DT_DOUBLE) # Subtract from experimental and write result projection.resetOrigin() if self.normalize: expProj = expProj.adjustAndSubtract(projection) else: expProj.inplaceSubtract(projection) expProj.write(self._getProjGalleryIndexFn(id + start - 1))
def projectStep(self, start, end, samplingRate, threadNumber): # Project md = xmipp.MetaData(self._getInputParticlesSubsetFn(threadNumber)) ## projection = xmipp.Image() projection.setDataType(xmipp.DT_DOUBLE) ## for id in md: rot = md.getValue(xmipp.MDL_ANGLE_ROT, id) tilt = md.getValue(xmipp.MDL_ANGLE_TILT, id) psi = md.getValue(xmipp.MDL_ANGLE_PSI, id) ##projection =self.vol.projectVolumeDouble(rot, tilt, psi) self.fourierProjectVol.projectVolume(projection, rot, tilt, psi) ## # Apply CTF if self.projType == self.CORRECT_NONE: pass elif self.projType == self.CORRECT_FULL_CTF: projection.applyCTF(md, samplingRate, id, False) elif self.projType == self.CORRECT_PHASE_FLIP: projection.applyCTF(md, samplingRate, id, True) else: raise Exception("ERROR: Unknown projection mode: %d" % self.projType) # Shift image projection.applyGeo(md,id,True,False)#onlyapplyshist, wrap ih = ImageHandler() expProj = ih.read(md.getValue(xmipp.MDL_IMAGE, id)) expProj.convert2DataType(xmipp.DT_DOUBLE) # Subtract from experimental and write result projection.resetOrigin() if self.normalize: expProj = expProj.adjustAndSubtract(projection) else: expProj.inplaceSubtract(projection) expProj.write( self._getProjGalleryIndexFn(id+start-1))
def createOutputStep(self, particlesId, coordsId, boxSize): """ Create the input file in STAR format as expected by Relion. Params: particlesId: use this parameters just to force redo of convert if the input particles are changed. """ ih = ImageHandler() outputStack = self._getPath('particles.mrcs') outputImg = ih.createImage() inputParticles = self._getInputParticles() inputCoords = self.inputCoordinates.get() outputSet = self._createSetOfParticles() outputSet.copyInfo(inputParticles) boxSize = self.boxSize.get() b2 = int(round(boxSize / 2)) center = np.zeros((boxSize, boxSize)) ih = ImageHandler() i = 0 outliers = 0 partIdExcluded = [] lastPartId = None for coord in inputCoords.iterItems( orderBy=['_subparticle._micId', '_micId', 'id']): # The original particle id is stored in the sub-particle as micId partId = coord._micId.get() # Load the particle if it has changed from the last sub-particle if partId != lastPartId: particle = inputParticles[partId] if particle is None: partIdExcluded.append(partId) self.info("WARNING: Missing particle with id %s from " "input particles set" % partId) else: # Now load the particle image to extract later sub-particles img = ih.read(particle) x, y, _, _ = img.getDimensions() data = img.getData() lastPartId = partId # If particle is not in inputParticles, subparticles will not be # generated. Now, subtract from a subset of original particles is # supported. if not partId in partIdExcluded: xpos = coord.getX() ypos = coord.getY() # Check that the sub-particle will not lay out of the particle if (ypos - b2 < 0 or ypos + b2 > y or xpos - b2 < 0 or xpos + b2 > x): outliers += 1 continue # Crop the sub-particle data from the whole particle image center[:, :] = data[ypos - b2:ypos + b2, xpos - b2:xpos + b2] outputImg.setData(center) i += 1 outputImg.write((i, outputStack)) subpart = coord._subparticle subpart.setLocation( (i, outputStack)) # Change path to new stack subpart.setObjId(None) # Force to insert as a new item outputSet.append(subpart) if outliers: self.info( "WARNING: Discarded %s particles because laid out of the " "particle (for a box size of %d" % (outliers, boxSize)) self._defineOutputs(outputParticles=outputSet) self._defineSourceRelation(self.inputParticles, outputSet)
def createOutputStep(self, particlesId, coordsId, boxSize): """ Create the input file in STAR format as expected by Relion. Params: particlesId: use this parameters just to force redo of convert if the input particles are changed. """ ih = ImageHandler() outputStack = self._getPath('particles.mrcs') outputImg = ih.createImage() inputParticles = self._getInputParticles() inputCoords = self.inputCoordinates.get() outputSet = self._createSetOfParticles() outputSet.copyInfo(inputParticles) boxSize = self.boxSize.get() b2 = int(round(boxSize / 2)) center = np.zeros((boxSize, boxSize)) ih = ImageHandler() i = 0 outliers = 0 partIdExcluded = [] lastPartId = None for coord in inputCoords.iterItems(orderBy=['_subparticle._micId', '_micId', 'id']): # The original particle id is stored in the sub-particle as micId partId = coord._micId.get() # Load the particle if it has changed from the last sub-particle if partId != lastPartId: particle = inputParticles[partId] if particle is None: partIdExcluded.append(partId) self.info("WARNING: Missing particle with id %s from " "input particles set" % partId) else: # Now load the particle image to extract later sub-particles img = ih.read(particle) x, y, _, _ = img.getDimensions() data = img.getData() lastPartId = partId # If particle is not in inputParticles, subparticles will not be # generated. Now, subtract from a subset of original particles is # supported. if not partId in partIdExcluded: xpos = coord.getX() ypos = coord.getY() # Check that the sub-particle will not lay out of the particle if (ypos - b2 < 0 or ypos + b2 > y or xpos - b2 < 0 or xpos + b2 > x): outliers += 1 continue # Crop the sub-particle data from the whole particle image center[:, :] = data[ypos-b2:ypos+b2, xpos-b2:xpos+b2] outputImg.setData(center) i += 1 outputImg.write((i, outputStack)) subpart = coord._subparticle subpart.setLocation((i, outputStack)) # Change path to new stack subpart.setObjId(None) # Force to insert as a new item outputSet.append(subpart) if outliers: self.info("WARNING: Discarded %s particles because laid out of the " "particle (for a box size of %d" % (outliers, boxSize)) self._defineOutputs(outputParticles=outputSet) self._defineSourceRelation(self.inputParticles, outputSet)