def saveImageList(self, filename, imageList, labels, csvseparator=None): if not imageList: qt.QMessageBox.information( self, "No Data", "Image list is empty.\nNothing to be saved") return if filename.lower().endswith(".edf"): ArraySave.save2DArrayListAsEDF(imageList, filename, labels) elif filename.lower().endswith(".tif"): ArraySave.save2DArrayListAsMonochromaticTiff(imageList, filename, labels) elif filename.lower().endswith(".csv"): assert csvseparator is not None ArraySave.save2DArrayListAsASCII(imageList, filename, labels, csv=True, csvseparator=csvseparator) else: ArraySave.save2DArrayListAsASCII(imageList, filename, labels, csv=False)
def saveImageList(self, filename, imageList, labels, csvseparator=None): if not imageList: qt.QMessageBox.information( self, "No Data", "Image list is empty.\nNothing to be saved") return if filename.lower().endswith(".edf"): ArraySave.save2DArrayListAsEDF(imageList, filename, labels) elif filename.lower().endswith(".tif"): ArraySave.save2DArrayListAsMonochromaticTiff( imageList, filename, labels) elif filename.lower().endswith(".csv"): assert csvseparator is not None ArraySave.save2DArrayListAsASCII(imageList, filename, labels, csv=True, csvseparator=csvseparator) else: ArraySave.save2DArrayListAsASCII(imageList, filename, labels, csv=False)
def _threadFinished(self): result = self.thread.result self.thread = None if type(result) == type((1, )): #if we receive a tuple there was an error if len(result): if result[0] == "Exception": # somehow this exception is not caught raise Exception(result[1], result[2]) #, result[3]) return if 'concentrations' in result: imageNames = result['names'] images = numpy.concatenate( (result['parameters'], result['concentrations']), axis=0) else: images = result['parameters'] imageNames = result['names'] nImages = images.shape[0] self._widget = StackPluginResultsWindow.StackPluginResultsWindow(\ usetab=False) self._widget.buildAndConnectImageButtonBox(replace=True, multiple=True) qt = StackPluginResultsWindow.qt self._widget.sigMaskImageWidgetSignal.connect(self.mySlot) self._widget.setStackPluginResults(images, image_names=imageNames) self._showWidget() # save to output directory parameters = self.configurationWidget.getParameters() outputDir = parameters["output_dir"] if outputDir in [None, ""]: if DEBUG: print("Nothing to be saved") return if parameters["file_root"] is None: fileRoot = "" else: fileRoot = parameters["file_root"].replace(" ", "") if fileRoot in [None, ""]: fileRoot = "images" if not os.path.exists(outputDir): os.mkdir(outputDir) imagesDir = os.path.join(outputDir, "IMAGES") if not os.path.exists(imagesDir): os.mkdir(imagesDir) imageList = [None] * (nImages + len(result['uncertainties'])) fileImageNames = [None] * (nImages + len(result['uncertainties'])) j = 0 for i in range(nImages): name = imageNames[i].replace(" ", "-") fileImageNames[j] = name imageList[j] = images[i] j += 1 if not imageNames[i].startswith("C("): # fitted parameter fileImageNames[j] = "s(%s)" % name imageList[j] = result['uncertainties'][i] j += 1 fileName = os.path.join(imagesDir, fileRoot + ".edf") ArraySave.save2DArrayListAsEDF(imageList, fileName, labels=fileImageNames) fileName = os.path.join(imagesDir, fileRoot + ".csv") ArraySave.save2DArrayListAsASCII(imageList, fileName, csv=True, labels=fileImageNames) if parameters["tiff"]: i = 0 for i in range(len(fileImageNames)): label = fileImageNames[i] if label.startswith("s("): continue elif label.startswith("C("): mass_fraction = "_" + label[2:-1] + "_mass_fraction" else: mass_fraction = "_" + label fileName = os.path.join(imagesDir, fileRoot + mass_fraction + ".tif") ArraySave.save2DArrayListAsMonochromaticTiff( [imageList[i]], fileName, labels=[label], dtype=numpy.float32)
def _threadFinished(self): result = self.thread.result self.thread = None if type(result) == type((1,)): #if we receive a tuple there was an error if len(result): if result[0] == "Exception": # somehow this exception is not caught raise Exception(result[1], result[2])#, result[3]) return imageNames = result['names'] images = result["images"] nImages = images.shape[0] self._widget = StackPluginResultsWindow.StackPluginResultsWindow(\ usetab=False) self._widget.buildAndConnectImageButtonBox(replace=True, multiple=True) qt = StackPluginResultsWindow.qt self._widget.sigMaskImageWidgetSignal.connect(self.mySlot) self._widget.setStackPluginResults(images, image_names=imageNames) self._showWidget() # save to output directory parameters = self.configurationWidget.getParameters() outputDir = parameters["output_dir"] if outputDir in [None, ""]: if DEBUG: print("Nothing to be saved") return if parameters["file_root"] is None: fileRoot = "" else: fileRoot = parameters["file_root"].replace(" ","") if fileRoot in [None, ""]: fileRoot = "images" if not os.path.exists(outputDir): os.mkdir(outputDir) imagesDir = os.path.join(outputDir, "IMAGES") if not os.path.exists(imagesDir): os.mkdir(imagesDir) imageList = [None] * (nImages) fileImageNames = [None] * (nImages) j = 0 for i in range(nImages): name = imageNames[i].replace(" ","-") fileImageNames[j] = name imageList[j] = images[i] j += 1 fileName = os.path.join(imagesDir, fileRoot+".edf") ArraySave.save2DArrayListAsEDF(imageList, fileName, labels=fileImageNames) fileName = os.path.join(imagesDir, fileRoot+".csv") ArraySave.save2DArrayListAsASCII(imageList, fileName, csv=True, labels=fileImageNames) if parameters["tiff"]: i = 0 for i in range(len(fileImageNames)): label = fileImageNames[i] mass_fraction = "_" + label fileName = os.path.join(imagesDir, fileRoot + mass_fraction + ".tif") ArraySave.save2DArrayListAsMonochromaticTiff([imageList[i]], fileName, labels=[label], dtype=numpy.float32)