def _writeFreqsMetaData(self, pattern, outputFn): """ Glob and read frequencies either from reconstruction or noise and write the proper metadata file. """ fnFreqs = sorted(glob.glob(self._getExtraPath(pattern))) subset = 0 numberOfParticles = getFloatListFromValues( self.numberOfParticles.get()) validationMd = xmipp.MetaData() for fnFreq in fnFreqs: print fnFreq data = [] fnFreqOpen = open(fnFreq, "r") for line in fnFreqOpen: fields = line.split() rowdata = map(float, fields) data.extend(rowdata) meanRes = (sum(data) / len(data)) data[:] = [(x - meanRes)**2 for x in data] varRes = (sum(data) / (len(data) - 1)) stdRes = sqrt(varRes) objId = validationMd.addObject() validationMd.setValue(xmipp.MDL_COUNT, long(numberOfParticles[subset]), objId) validationMd.setValue(xmipp.MDL_AVG, meanRes, objId) validationMd.setValue(xmipp.MDL_STDDEV, stdRes, objId) subset += 1 validationMd.write(outputFn)
def _writeFreqsMetaData(self, pattern, outputFn): """ Glob and read frequencies either from reconstruction or noise and write the proper metadata file. """ fnFreqs = sorted(glob.glob(self._getExtraPath(pattern))) subset = 0 numberOfParticles = getFloatListFromValues(self.numberOfParticles.get()) validationMd = xmipp.MetaData() for fnFreq in fnFreqs: print fnFreq data = [] fnFreqOpen = open(fnFreq, "r") for line in fnFreqOpen: fields = line.split() rowdata = map(float, fields) data.extend(rowdata) meanRes = (sum(data) / len(data)) data[:] = [(x-meanRes) ** 2 for x in data] varRes = (sum(data) / (len(data) - 1)) stdRes = sqrt(varRes) objId = validationMd.addObject() validationMd.setValue(xmipp.MDL_COUNT, long(numberOfParticles[subset]), objId) validationMd.setValue(xmipp.MDL_AVG,meanRes, objId) validationMd.setValue(xmipp.MDL_STDDEV,stdRes,objId) subset += 1 validationMd.write(outputFn)
def itersFloatValues(self, attributeName, firstValue=-1): """ Take the string of a given attribute and create a list of floats that will be used by the iteratioins. An special first value will be added to the list for iteration 0. """ valuesStr = self.getAttributeValue(attributeName) if valuesStr is None: raise Exception('None value for attribute: %s' % attributeName) return [firstValue] + getFloatListFromValues(valuesStr, length=self.numberOfIterations.get())
def _writeFreqsMetaData(self, pattern, outputFn): """ Glob and read frequencies either from reconstruction or noise and write the proper metadata file. """ fnFreqs = sorted(glob.glob(self._getExtraPath(pattern))) subset = 0 numberOfParticles = getFloatListFromValues( self.numberOfParticles.get()) validationMd = xmippLib.MetaData() fnOut = open(outputFn, 'w') for fnFreq in fnFreqs: print fnFreq data = [] dataInv = [] fnFreqOpen = open(fnFreq, "r") for line in fnFreqOpen: fields = line.split() rowdata = map(float, fields) print("rowdata", rowdata) #AJ cambio val = 1.0 / (float(rowdata[0]) * float(rowdata[0])) dataInv.append(val) #FIN AJ data.extend(rowdata) print("data", data, dataInv) meanRes = (sum(data) / len(data)) data[:] = [(x - meanRes)**2 for x in data] varRes = (sum(data) / (len(data) - 1)) stdRes = sqrt(varRes) meanResInv = (sum(dataInv) / len(dataInv)) dataInv[:] = [(x - meanResInv)**2 for x in dataInv] varResInv = (sum(dataInv) / (len(dataInv) - 1)) stdResInv = sqrt(varResInv) fnOut.write( str(numberOfParticles[subset]) + ' ' + str(meanRes) + ' ' + str(stdRes) + ' ' + str(meanResInv) + ' ' + str(stdResInv) + '\n') # # objId = validationMd.addObject() # validationMd.setValue(xmippLib.MDL_COUNT, # long(numberOfParticles[subset]), # objId) # validationMd.setValue(xmippLib.MDL_AVG, meanRes, objId) # validationMd.setValue(xmippLib.MDL_STDDEV, stdRes, objId) subset += 1 # validationMd.write(outputFn) fnOut.close()
def _summary(self): """ Should be overriden in subclasses to return summary message for NORMAL EXECUTION. """ numberOfParticles = getFloatListFromValues(self.numberOfParticles.get()) maxNumberOfParticles = 0.5 * self.inputParticles.get().getSize() intNumberOfParticles = [int(float(x)) for x in numberOfParticles] particlesNumber = '' for number in intNumberOfParticles: if number <= maxNumberOfParticles: particlesNumber += str(number)+' ' msg = [] msg.append("Number of particles: " + particlesNumber) msg.append("Number of times that reconstruction is performed per each " "particles subset: %d" % self.numberOfIterations) return msg
def _summary(self): """ Should be overriden in subclasses to return summary message for NORMAL EXECUTION. """ numberOfParticles = getFloatListFromValues( self.numberOfParticles.get()) maxNumberOfParticles = 0.5 * self.inputParticles.get().getSize() intNumberOfParticles = [int(float(x)) for x in numberOfParticles] particlesNumber = '' for number in intNumberOfParticles: if number <= maxNumberOfParticles: particlesNumber += str(number) + ' ' msg = [] msg.append("Number of particles: " + particlesNumber) msg.append("Number of times that reconstruction is performed per each " "particles subset: %d" % self.numberOfIterations) return msg
def _insertAllSteps(self): self._createFilenameTemplates() #convertInputStep particlesMd = self._getFileName('input_xmd') imgSet = self.inputParticles.get() writeSetOfParticles(imgSet, particlesMd) #for debugging purpose debugging = False inputNameRefVol = self.input3DReference.get().getFileName() fnNewVol = self._getExtraPath('newVolume.vol') fnNewImgStk = self._getExtraPath('newImages.stk') fnNewImgMd = self._getExtraPath('newImages.xmd') #do resizing if self.doResize.get(): args = "-i %s " "-o %s --fourier %f " % (inputNameRefVol, fnNewVol, self.newSize) self.runJob("xmipp_image_resize", args) args = "-i %s -o %s --fourier %f" % (particlesMd, fnNewImgStk, self.newSize) args += " --save_metadata_stack %s" % fnNewImgMd args += " --keep_input_columns" self.runJob("xmipp_image_resize", args) oldSize = self.inputParticles.get().getDim()[0] scaleFactor = oldSize / self.newSize.get() args = "-i %s" % fnNewImgMd args += " --operate modify_values 'shiftX=shiftX*%f'" % scaleFactor self.runJob('xmipp_metadata_utilities', args) args = "-i %s" % fnNewImgMd args += " --operate modify_values 'shiftY=shiftY*%f'" % scaleFactor self.runJob('xmipp_metadata_utilities', args) #projections from reference volume if self.doResize.get(): args = "-i %s -o %s" % (fnNewVol, self._getExtraPath('Ref_Projections.stk')) args += " --experimental_images %s" % fnNewImgMd else: args = "-i %s -o %s" % (self.input3DReference.get().getFileName(), self._getExtraPath('Ref_Projections.stk')) args += " --experimental_images %s" % particlesMd args += " --sampling_rate %f --sym %s" % (self.angSampRate, self.symmetryGroup.get()) args += " --min_tilt_angle 0 --max_tilt_angle 90" args += " --compute_neighbors --angular_distance -1" self.runJob("xmipp_angular_project_library", args, numberOfMpi=self.numberOfMpi.get() * self.numberOfThreads.get()) numberOfParticles = getFloatListFromValues( self.numberOfParticles.get()) fractionCounter = 0 maxNumberOfParticles = 0.5 * self.inputParticles.get().getSize() for number in numberOfParticles: if number <= maxNumberOfParticles: for iteration in range(0, self.numberOfIterations.get()): self._insertFunctionStep('reconstructionStep', number, fractionCounter, iteration, debugging, fnNewImgMd, particlesMd) fractionCounter += 1 self._insertFunctionStep('gatherResultsStep', debugging)
def _insertAllSteps(self): self._createFilenameTemplates() #convertInputStep particlesMd = self._getFileName('input_xmd') imgSet = self.inputParticles.get() writeSetOfParticles(imgSet, particlesMd) #for debugging purpose debugging = False inputNameRefVol = self.input3DReference.get().getFileName() fnNewVol = self._getExtraPath('newVolume.vol') fnNewImgStk = self._getExtraPath('newImages.stk') fnNewImgMd = self._getExtraPath('newImages.xmd') #do resizing if self.doResize.get(): args = "-i %s ""-o %s --fourier %f " % (inputNameRefVol, fnNewVol, self.newSize) self.runJob("xmipp_image_resize", args) args = "-i %s -o %s --fourier %f" % (particlesMd, fnNewImgStk, self.newSize) args += " --save_metadata_stack %s" % fnNewImgMd args += " --keep_input_columns" self.runJob("xmipp_image_resize", args) oldSize = self.inputParticles.get().getDim()[0] scaleFactor = float(self.newSize.get())/float(oldSize) args = "-i %s" % fnNewImgMd args += " --operate modify_values 'shiftX=shiftX*%f'" % scaleFactor self.runJob('xmipp_metadata_utilities', args, numberOfMpi=1) args = "-i %s" % fnNewImgMd args += " --operate modify_values 'shiftY=shiftY*%f'" % scaleFactor self.runJob('xmipp_metadata_utilities', args, numberOfMpi=1) #projections from reference volume if self.doResize.get(): args = "-i %s -o %s" % (fnNewVol, self._getExtraPath('Ref_Projections.stk')) args += " --experimental_images %s" % fnNewImgMd else: args = "-i %s -o %s" % (self.input3DReference.get().getFileName(), self._getExtraPath('Ref_Projections.stk')) args += " --experimental_images %s" % particlesMd args += " --sampling_rate %f --sym %s" % (self.angSampRate, self.symmetryGroup.get()) args += " --min_tilt_angle 0 --max_tilt_angle 90" args += " --compute_neighbors --angular_distance -1" self.runJob("xmipp_angular_project_library", args, numberOfMpi = self.numberOfMpi.get() * self.numberOfThreads.get()) numberOfParticles = getFloatListFromValues(self.numberOfParticles.get()) fractionCounter = 0 maxNumberOfParticles = 0.5 * self.inputParticles.get().getSize() for number in numberOfParticles: if number <= maxNumberOfParticles: for iteration in range(0,self.numberOfIterations.get()): self._insertFunctionStep('reconstructionStep', number, fractionCounter, iteration, debugging, fnNewImgMd, particlesMd) fractionCounter+=1 self._insertFunctionStep('gatherResultsStep', debugging)