def _getImgPath(self, mdFn, imgFn): """ Get ups and ups until finding the relative location to images. """ path = os.path.dirname(mdFn) index, fn = emlib.FileName(imgFn).decompose() while path and path != '/': newFn = os.path.join(path, fn) if os.path.exists(newFn): if index: newFn = '%d@%s' % (index, newFn) return newFn path = os.path.dirname(path) return None
def openPath(self, path): """Try to open the selected path""" path = expandPattern(path) # If the path is a dir, open it with scipion browser dir <path> if os.path.isdir(path): dpath = (path if os.path.isabs(path) else os.path.join( os.getcwd(), path)) subprocess.Popen([pw.PYTHON, pw.getViewerScript(), dpath]) return # If it is a file, interpret it correctly and open it with DataView dirname = os.path.dirname(path) fname = os.path.basename(path) if '@' in fname: path = os.path.join(dirname, fname.split('@', 1)[-1]) else: path = os.path.join(dirname, fname) if os.path.exists(path): from pwem import emlib fn = emlib.FileName(path) if fn is not None and (fn.isImage() or fn.isMetaData()): # fn is None if xmippLib is the xmippLib ghost library from pwem.viewers import DataView DataView(path).show() else: _open_cmd(path) else: # This is probably one special reference, like sci-open:... that # can be interpreted with our handlers. tag = path.split(':', 1)[0] if ':' in path else None if tag in self.handlers: self.handlers[tag](path.split(':', 1)[-1]) else: print("Can't find %s" % path)
def runCreateOutputStep(self): ''' Create standard output results_images, result_classes''' #creating results files imgSet = self.inputParticles.get() lastIter = self.numberOfIterations.get() Ts = imgSet.getSamplingRate() if self.numberOfReferences != 1: inDocfile = self._getFileName('docfileInputAnglesIters', iter=lastIter) ClassFnTemplate = '%(rootDir)s/reconstruction_Ref3D_%(ref)03d.vol' allExpImagesinDocfile = emlib.FileName() all_exp_images = "all_exp_images" allExpImagesinDocfile.compose(all_exp_images, inDocfile) dataClasses = self._getFileName('sqliteClasses') createClassesFromImages(imgSet, str(allExpImagesinDocfile), dataClasses, SetOfClasses3D, emlib.MDL_REF3D, ClassFnTemplate, lastIter) classes = self._createSetOfClasses3D(imgSet) clsSet = SetOfClasses3D(dataClasses) classes.appendFromClasses(clsSet) volumes = self._createSetOfVolumes() volumes.setSamplingRate(Ts) for refN in self.allRefs(): volFn = self._getFileName('reconstructedFileNamesIters', iter=lastIter, ref=refN) volFn = convertToMrc(self, volFn, Ts, True) vol = Volume() vol.setFileName(volFn) volumes.append(vol) self._defineOutputs(outputVolumes=volumes) self._defineOutputs(outputClasses=classes) self._defineSourceRelation(self.inputParticles, volumes) self._defineSourceRelation(self.inputParticles, classes) self._defineSourceRelation(self.input3DReferences, volumes) self._defineSourceRelation(self.input3DReferences, classes) else: volFn = self._getFileName('reconstructedFileNamesIters', iter=lastIter, ref=1) halfMap1 = self._getFileName('reconstructedFileNamesItersSplit1', iter=lastIter, ref=1) halfMap2 = self._getFileName('reconstructedFileNamesItersSplit2', iter=lastIter, ref=1) volFn = convertToMrc(self, volFn, Ts, True) halfMap1 = convertToMrc(self, halfMap1, Ts, True) halfMap2 = convertToMrc(self, halfMap2, Ts, True) vol = Volume() vol.setFileName(volFn) vol.setSamplingRate(Ts) vol.setHalfMaps([halfMap1, halfMap2]) self._defineOutputs(outputVolume=vol) self._defineSourceRelation(self.inputParticles, vol) self._defineSourceRelation(self.input3DReferences, vol) #create set of images imgSetOut = self._createSetOfParticles("_iter_%03d" % lastIter) self._fillParticlesFromIter(imgSetOut, lastIter) self._defineOutputs(outputParticles=imgSetOut) self._defineSourceRelation(self.inputParticles, imgSetOut) self._defineSourceRelation(self.input3DReferences, imgSetOut)