Exemplo n.º 1
0
    nargs='+',
    help=
    'Field name(s) to partition on. Partitioning only occurs if this is provided, otherwise partnum, partmin, and partmax are not used. Partition names appended to outfile as outfile_nm'
)

parser.add_argument(
    'infile',
    help='the dat file (or a .npz file output from datview/datexport)')
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)
Exemplo n.º 2
0
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()