partitions=None if args.partition is not None: partitions=model.partitionMulti(args.partition,args.partmin,args.partmax,args.partnum) if '%s' not in args.outfile and not args.savelst: args.outfile +="_%s" backgrounds=None if args.background is not None: backgrounds={} f=h5py.File(args.background,'r') for field in args.h5fields: backgrounds[field]=np.array(h5py[field],dtype=np.dtype('f4')) args.backgrounds=backgrounds model.saveByPartitions(args,savePowder,partitions,appendName=False) if args.savelst: if args.partition is not None and len(args.partition) >1: if '%s' not in args.outfile: args.outfile +="_%s" for major in sorted(savelst.keys()): writelst(args.outfile % major, savelst[major],args) else: writelst(args.outfile, savelst,args)
args.cols.append("average_"+c) for c in args.averageN: args.cols.append("averageN_"+c) for c in args.min: args.cols.append("min_"+c) for c in args.minN: args.cols.append("minN_"+c) for c in args.max: args.cols.append("max_"+c) for c in args.std: args.cols.append("std_"+c) for c in args.count: if len(c): args.cols.append("count_"+'_'.join(c)) else: args.cols.append("count") for c in args.countGE: args.cols.append("countGE_"+'_'.join(c)) args.cols.sort() if args.partition is not None: args.cols.insert(0,'_'.join(args.partition)) partitions=None if args.partition is not None: partitions=model.partitionMulti(args.partition,args.partmin,args.partmax,args.partnum) print(*args.cols,sep='\t',file=args.out) model.saveByPartitions(args,addline,partitions,appendName=False)
parser.add_argument( 'outfile', help='the output file, format automatically determined by line ending') args = parser.parse_args() model = DataModel(args.infile, args.group, cfg=ModelConfig(args.cfg)) if args.outfile.endswith(".npz"): model.saveAllNumpy(args.outfile) exit() if args.filter is not None: model.loadFilters(args.filter) if args.sort is not None: model.sortlst = args.sort if args.limit is not None: model.limit = args.limit model.limitModeRandom = args.limitmode == "random" model.reverseSort = args.reversesort partitions = None if args.partition is not None: partitions = model.partitionMulti(args.partition, args.partmin, args.partmax, args.partnum) if '.stream' in args.outfile: model.saveByPartitions(args.outfile, model.saveSelStream, partitions) elif '.lst' in args.outfile: model.saveByPartitions(args.outfile, model.saveSelLst, partitions) else: model.saveByPartitions(args.outfile, model.saveSelDat, partitions)
aggplot(model,qFig,args,i,p) else: print("Unrecognized plot string: ",p) if args.title is not None: qFig.fig.suptitle(args.title,fontsize=20) if args.save is not None: partitions=None if args.partition is not None: partitions=model.partitionMulti(args.partition,args.partmin,args.partmax,args.partnum) if '%' not in args.save: args.save += '_%s' args.qFig=qFig model.saveByPartitions(args,saveFigByPartitions,partitions,False,False) else: app = QApplication(sys.argv) qFig.show() r= app.exec_() app.deleteLater() sys.exit(r)
class MyMainWindow(QMainWindow): def __init__(self, datfile, groupfile, filterfile, cfg, geom, mask): QMainWindow.__init__(self) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.setAttribute(Qt.WA_DeleteOnClose) self.setWindowTitle("Datview: %s" % datfile) config = ModelConfig(cfg) self.model = DataModel(datfile, groupfile, cfg=config) self.histcolumns = config.histperrow if filterfile is not None: self.model.loadFilters(filterfile) self.ui.actionSave_Dat.triggered.connect(self.onSaveDat) self.ui.actionSave_List.setEnabled(self.model.canSaveLst()) self.ui.actionSave_List.triggered.connect(self.onSaveLst) self.ui.actionSave_Stream.setEnabled(self.model.canSaveStream()) self.ui.actionSave_Stream.triggered.connect(self.onSaveStream) self.ui.actionSave_Numpy.setEnabled(self.model.canSaveNumpy()) self.ui.actionSave_Numpy.triggered.connect(self.onSaveNumpy) self.ui.actionScatter.triggered.connect(self.onShowScatter) self.ui.action2D_Histogram.triggered.connect(self.onShowHist2d) self.ui.actionPixel.triggered.connect(self.onShowPixelPlot) self.ui.actionAggregated_Plot.triggered.connect(self.onShowAggPlot) self.ui.actionOpen.setVisible(False) self.ui.actionSave_Plot.setVisible(False) self.ui.actionComparison_Scatter.setVisible( self.model.hasComparisons()) self.ui.actionComparison_Scatter.triggered.connect( self.onShowCmpScatter) self.ui.actionComparison_2D_Histogram.setVisible( self.model.hasComparisons()) self.ui.actionComparison_2D_Histogram.triggered.connect( self.onShowCmpHist2d) self.filtmessage = QLabel(self) self.ui.statusbar.addWidget(self.filtmessage) self.onFilterChange() self.model.filterchange.connect(self.onFilterChange) # Histogram Menu self.checkedhistograms = [] self.cachedHistograms = {} self.ui.menuHistogram_Bar.removeAction(self.ui.actionReset) self.addHistogramMenu( self.model.cfg.defaultHistograms & set(self.model.cols), True) self.ui.menuHistogram_Bar.addSeparator() self.addHistogramMenu( set(self.model.cols) - self.model.cfg.defaultHistograms - self.model.cfg.internalCols, False) self.placeHistograms() # Filter Panel self.controlPanel = MyControlPanel(self.model, parent=self) self.controlPanel.setWindowFlags(Qt.Window) self.ui.actionViewControls.triggered.connect(self.controlPanel.show) self.ui.actionSave_Filters.triggered.connect( self.controlPanel.onSaveFilters) # Item Viewer itemviewer = MyItemViewer(self.model, geom, mask, parent=self) itemviewer.setWindowFlags(Qt.Window) self.ui.actionItem_Viewer.triggered.connect(itemviewer.show) self.controlPanel.flagselected.connect(itemviewer.model.setRow) if qt5: self.ui.plotScrollArea.viewport().installEventFilter(self) def eventFilter(self, source, event): if (event.type() == QEvent.Wheel and source is self.ui.plotScrollArea.viewport()): return True return super(QMainWindow, self).eventFilter(source, event) def addHistogramMenu(self, lst, checked=False): for col in sorted(lst, key=self.model.prettyname): act = QAction(self.model.prettyname(col), self) act.setCheckable(True) act.setChecked(checked) self.ui.menuHistogram_Bar.addAction(act) act.triggered.connect( lambda checked, field=col: self.onHistAction(field, checked)) if checked: self.checkedhistograms.append(col) def placeHistograms(self): spot = 0 for field in self.checkedhistograms: if field in self.cachedHistograms: h = self.cachedHistograms[field] else: h = MyFigure(parent=self.ui.scrollAreaWidgetContents) h.histogram(model=self.model, field=field) self.cachedHistograms[field] = h if spot < self.histcolumns: self.ui.gridLayout.setColumnStretch(spot, 1) if spot % self.histcolumns == 0: self.ui.gridLayout.setRowStretch(int(spot / self.histcolumns), 1) self.ui.gridLayout.addWidget(h, int(spot / self.histcolumns), spot % self.histcolumns) h.setVisible(True) spot += 1 def onHistAction(self, field, checked): if checked: self.checkedhistograms.append(field) else: self.checkedhistograms.remove(field) self.cachedHistograms[field].setVisible(False) self.placeHistograms() def onFilterChange(self): self.filtmessage.setText( '%d of %d Selected' % (len(self.model.filtered), len(self.model.data))) def getSaveName(self, title, filter): name = QFileDialog.getSaveFileName(self, title, filter=filter) if qt5: if name: return name[0] elif name is not None and len(name): return name return None def onSaveDat(self): name = self.getSaveName('Save Selected As Dat File', '*.dat') if name: self.model.saveByPartitions(name, self.model.saveSelDat, self.controlPanel.partWidget.current()) def onSaveLst(self): name = self.getSaveName('Save Selected As List File', '*.lst') if name: self.model.saveByPartitions(name, self.model.saveSelLst, self.controlPanel.partWidget.current()) def onSaveStream(self): name = self.getSaveName('Save Selected As Stream File', '*.stream') if name: try: self.model.saveByPartitions( name, self.model.saveSelStream, self.controlPanel.partWidget.current()) except FileNotFoundError as err: QMessageBox.warning(self, "Unable to Save", str(err)) def onSaveNumpy(self): name = self.getSaveName('Save ALL as compressed numpy file', '*.npz') if name: self.model.saveAllNumpy(name) def onShowScatter(self): d = MyScatterDialog(self.model, self) d.exec() def onShowCmpScatter(self): d = MyCompareScatterDialog(self.model, self) d.exec() def onShowHist2d(self): d = MyHist2dDialog(self.model, self) d.exec() def onShowCmpHist2d(self): d = MyCompare2DHistDialog(self.model, self) d.exec() def onShowPixelPlot(self): d = MyPixelPlotDialog(self.model, self) d.exec() def onShowAggPlot(self): d = MyAggPlotDialog(self.model, self) d.exec()