Exemplo n.º 1
0
    def add_grid_headers(self):
        self.header_grid = QtWidgets.QGridLayout()
        self.header_widget = NXWidget()
        self.header_widget.set_layout(self.header_grid)

        row = 0
        columns = [
            'Scan', 'data', 'link', 'copy', 'max', 'find', 'refine', 'prepare',
            'transform', 'masked_transform', 'combine', 'masked_combine',
            'pdf', 'masked_pdf', 'overwrite', 'sync'
        ]
        header = {}
        for col, column in enumerate(columns):
            header[column] = NXLabel(column,
                                     bold=True,
                                     width=75,
                                     align='center')
            if column == 'transform' or column == 'combine' or column == 'pdf':
                self.header_grid.addWidget(header[column], row, col, 1, 2,
                                           QtCore.Qt.AlignHCenter)
            elif 'masked' not in column:
                self.header_grid.addWidget(header[column], row, col)
                header[column].setAlignment(QtCore.Qt.AlignHCenter)
        row = 1
        columns = 3 * ['regular', 'masked']
        for col, column in enumerate(columns):
            header[column] = NXLabel(column, width=75, align='center')
            self.header_grid.addWidget(header[column], row, col + 8)
        self.header_grid.setSpacing(0)
        self.header_widget.setFixedHeight(60)
        self.insert_layout(2, self.header_widget)
Exemplo n.º 2
0
 def make_filterbox(self):
     filterbox = QtWidgets.QWidget()
     layout = QtWidgets.QGridLayout()
     layout.setSpacing(10)
     prefix_label = NXLabel('File Prefix')
     self.prefix_box = NXLineEdit()
     self.prefix_box.editingFinished.connect(self.set_range)
     suffix_label = NXLabel('File Suffix')
     self.suffix_box = NXLineEdit('')
     self.suffix_box.editingFinished.connect(self.get_prefixes)
     extension_label = NXLabel('File Extension')
     self.extension_box = NXLineEdit()
     self.extension_box.editingFinished.connect(self.set_extension)
     layout.addWidget(prefix_label, 0, 0)
     layout.addWidget(self.prefix_box, 0, 1)
     layout.addWidget(suffix_label, 0, 2)
     layout.addWidget(self.suffix_box, 0, 3)
     layout.addWidget(extension_label, 0, 4)
     layout.addWidget(self.extension_box, 0, 5)
     self.prefix_combo = QtWidgets.QComboBox()
     self.prefix_combo.setSizeAdjustPolicy(
         QtWidgets.QComboBox.AdjustToContents)
     self.prefix_combo.activated.connect(self.choose_prefix)
     self.extension_combo = QtWidgets.QComboBox()
     self.extension_combo.setSizeAdjustPolicy(
         QtWidgets.QComboBox.AdjustToContents)
     self.extension_combo.activated.connect(self.choose_extension)
     layout.addWidget(self.prefix_combo, 1, 1, 
                      alignment=QtCore.Qt.AlignHCenter)
     layout.addWidget(self.extension_combo, 1, 5, 
                      alignment=QtCore.Qt.AlignHCenter)
     filterbox.setLayout(layout)
     filterbox.setVisible(False)
     return filterbox
Exemplo n.º 3
0
 def make_filterbox(self):
     filterbox = QtWidgets.QWidget()
     layout = QtWidgets.QGridLayout()
     layout.setSpacing(10)
     prefix_label = NXLabel('File Prefix')
     self.prefix_box = NXLineEdit(slot=self.set_range)
     suffix_label = NXLabel('File Suffix')
     self.suffix_box = NXLineEdit(slot=self.get_prefixes)
     extension_label = NXLabel('File Extension')
     self.extension_box = NXLineEdit(slot=self.set_extension)
     layout.addWidget(prefix_label, 0, 0)
     layout.addWidget(self.prefix_box, 0, 1)
     layout.addWidget(suffix_label, 0, 2)
     layout.addWidget(self.suffix_box, 0, 3)
     layout.addWidget(extension_label, 0, 4)
     layout.addWidget(self.extension_box, 0, 5)
     self.prefix_combo = NXComboBox(self.choose_prefix)
     self.extension_combo = NXComboBox(self.choose_extension)
     layout.addWidget(self.prefix_combo, 1, 1,
                      alignment=QtCore.Qt.AlignHCenter)
     layout.addWidget(self.extension_combo, 1, 5,
                      alignment=QtCore.Qt.AlignHCenter)
     filterbox.setLayout(layout)
     filterbox.setVisible(False)
     return filterbox
Exemplo n.º 4
0
    def scanbox(self):
        """Create widgets for specifying scan range to import."""
        scanminlabel = NXLabel("Min. Scan")
        self.scanmin = NXLineEdit(width=100, align='right')
        scanmaxlabel = NXLabel("Max. Scan")
        self.scanmax = NXLineEdit(width=100, align='right')

        scanbox = QtWidgets.QHBoxLayout()
        scanbox.addWidget(scanminlabel)
        scanbox.addWidget(self.scanmin)
        scanbox.addWidget(scanmaxlabel)
        scanbox.addWidget(self.scanmax)
        return scanbox
Exemplo n.º 5
0
 def make_rangebox(self):
     rangebox = QtWidgets.QWidget()
     layout = QtWidgets.QHBoxLayout()
     rangeminlabel = NXLabel("Min. index")
     self.rangemin = NXLineEdit(width=150, align='right')
     rangemaxlabel = NXLabel("Max. index")
     self.rangemax = NXLineEdit(width=150, align='right')
     layout.addWidget(rangeminlabel)
     layout.addWidget(self.rangemin)
     layout.addStretch()
     layout.addWidget(rangemaxlabel)
     layout.addWidget(self.rangemax)
     rangebox.setLayout(layout)
     rangebox.setVisible(False)
     return rangebox
Exemplo n.º 6
0
    def __init__(self, parent=None):

        super(ImportDialog, self).__init__(parent)

        self.file_type = None

        layout = QtWidgets.QVBoxLayout()
        layout.addLayout(self.filebox())

        title_layout = QtWidgets.QHBoxLayout()
        title_label = NXLabel('Title')
        self.title_box = NXLineEdit()
        title_layout.addWidget(title_label)
        title_layout.addWidget(self.title_box)
        layout.addLayout(title_layout)
        
        energy_layout = QtWidgets.QHBoxLayout()
        energy_label = NXLabel('Incident Energy')
        self.energy_box = NXLineEdit()
        self.energy_box.setFixedWidth(150)
        energy_layout.addWidget(energy_label)
        energy_layout.addWidget(self.energy_box)
        energy_layout.addStretch()
        layout.addLayout(energy_layout)

        step_layout = QtWidgets.QHBoxLayout()
        Q_label = NXLabel('dQ')
        self.Q_box = NXLineEdit()
        self.Q_box.setFixedWidth(75)
        E_label = NXLabel('dE')
        self.E_box = NXLineEdit()
        self.E_box.setFixedWidth(75)
        self.convert_box = QtWidgets.QCheckBox('Convert to S(Q,E)')
        self.convert_box.setChecked(False)
        step_layout.addWidget(self.convert_box)
        step_layout.addStretch()
        step_layout.addWidget(Q_label)
        step_layout.addWidget(self.Q_box)
        step_layout.addWidget(E_label)
        step_layout.addWidget(self.E_box)
        step_layout.addStretch()
        layout.addLayout(step_layout)

        layout.addWidget(self.close_buttons())

        self.setLayout(layout)
  
        self.setWindowTitle("Import "+str(filetype))
Exemplo n.º 7
0
    def scanbox(self):
        '''create widgets for specifying scan range to import'''
        scanminlabel = NXLabel("Min. Scan")
        self.scanmin = NXLineEdit()
        self.scanmin.setFixedWidth(100)
        self.scanmin.setAlignment(QtCore.Qt.AlignRight)
        scanmaxlabel = NXLabel("Max. Scan")
        self.scanmax = NXLineEdit()
        self.scanmax.setFixedWidth(100)
        self.scanmax.setAlignment(QtCore.Qt.AlignRight)

        scanbox = QtWidgets.QHBoxLayout()
        scanbox.addWidget(scanminlabel)
        scanbox.addWidget(self.scanmin)
        scanbox.addWidget(scanmaxlabel)
        scanbox.addWidget(self.scanmax)
        return scanbox
Exemplo n.º 8
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self.select_entry(self.choose_entry)

        self.parameters = GridParameters()
        self.parameters.add('first', '', 'First Frame')
        self.parameters.add('last', '', 'Last Frame')

        self.output = NXLabel('Maximum Value:')
        self.set_layout(
            self.entry_layout, self.output, self.parameters.grid(),
            self.action_buttons(('Find Maximum', self.find_maximum)),
            self.progress_layout(save=True))
        self.progress_bar.setVisible(False)
        self.progress_bar.setValue(0)
        self.set_title('Find Maximum Value')
        self.reduce = None
Exemplo n.º 9
0
 def make_rangebox(self):
     rangebox = QtWidgets.QWidget()
     layout = QtWidgets.QHBoxLayout()
     rangeminlabel = NXLabel("Min. index")
     self.rangemin = NXLineEdit()
     self.rangemin.setFixedWidth(150)
     self.rangemin.setAlignment(QtCore.Qt.AlignRight)
     rangemaxlabel = NXLabel("Max. index")
     self.rangemax = NXLineEdit()
     self.rangemax.setFixedWidth(150)
     self.rangemax.setAlignment(QtCore.Qt.AlignRight)
     layout.addWidget(rangeminlabel)
     layout.addWidget(self.rangemin)
     layout.addStretch()
     layout.addWidget(rangemaxlabel)
     layout.addWidget(self.rangemax)
     rangebox.setLayout(layout)
     rangebox.setVisible(False)
     return rangebox
Exemplo n.º 10
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self.select_entry(self.choose_entry)

        self.Qgrid = QtWidgets.QGridLayout()
        self.Qgrid.setSpacing(10)
        headers = ['Axis', 'Q', 'dQ', 'N', 'Max']
        width = [25, 50, 50, 25, 50]
        column = 0
        for header in headers:
            label = NXLabel(header, bold=True, align='center')
            self.Qgrid.addWidget(label, 0, column)
            self.Qgrid.setColumnMinimumWidth(column, width[column])
            column += 1
        self.Qbox = {}
        self.dQbox = {}
        self.Nbox = {}
        self.maxbox = {}
        for i, label in enumerate(['H', 'K', 'L']):
            self.Qgrid.addWidget(NXLabel(label, align='center'), i + 1, 0)
            self.Qbox[label] = NXLineEdit(slot=self.calculate,
                                          width=100,
                                          align='right')
            self.Qgrid.addWidget(self.Qbox[label], i + 1, 1)
            self.dQbox[label] = NXLineEdit(slot=self.calculate,
                                           width=100,
                                           align='right')
            self.Qgrid.addWidget(self.dQbox[label], i + 1, 2)
            self.Nbox[label] = NXLabel(align='center')
            self.Qgrid.addWidget(self.Nbox[label], i + 1, 3)
            self.maxbox[label] = NXLabel(align='center')
            self.Qgrid.addWidget(self.maxbox[label], i + 1, 4)
        self.set_layout(self.entry_layout, self.close_buttons(save=True))
        self.setWindowTitle('Transforming Data')
        try:
            self.initialize_grid()
        except Exception:
            pass
Exemplo n.º 11
0
 def __init__(self, parent=None):
     super().__init__(parent)
     self.scans = None
     self.prefix_box = NXLineEdit()
     self.prefix_box.textChanged.connect(self.select_prefix)
     prefix_layout = self.make_layout(NXLabel('Prefix'), self.prefix_box)
     self.set_layout(
         self.directorybox("Choose Sample Directory", self.choose_sample),
         self.action_buttons(('Select All', self.select_scans),
                             ('Clear All', self.clear_scans),
                             ('Sum Scans', self.sum_scans)),
         self.checkboxes(('update', 'Update Existing Sums', False),
                         ('overwrite', 'Overwrite Existing Sums', False)),
         prefix_layout, self.close_layout(close=True))
     self.set_title('Sum Files')
Exemplo n.º 12
0
    def __init__(self, parent=None):

        super(ImportDialog, self).__init__(parent)

        skippedbox = QtWidgets.QHBoxLayout()
        skippedlabel = NXLabel("No. of skipped rows")
        self.skiprows = NXLineEdit()
        self.skiprows.setText('0')
        self.skiprows.setFixedWidth(20)
        skippedbox.addWidget(skippedlabel)
        skippedbox.addWidget(self.skiprows)

        layout = QtWidgets.QVBoxLayout()
        layout.addLayout(self.filebox())
        layout.addLayout(skippedbox)
        layout.addWidget(self.buttonbox())
        self.setLayout(layout)

        self.setWindowTitle("Import " + str(filetype))
Exemplo n.º 13
0
    def update(self):
        if not self.sample_directory:
            raise NeXusError("No sample directory declared")

        if self.grid:
            self.delete_grid(self.grid)
            del self.grid_widget

        if self.scroll_area:
            self.scroll_area.close()
            self.scroll_area.deleteLater()

        # Map from wrapper files to scan directories
        wrapper_files = {
            w: self.get_scan(w)
            for w in sorted([
                os.path.join(self.sample_directory, filename)
                for filename in os.listdir(self.sample_directory)
                if self.is_valid(filename)
            ],
                            key=natural_sort)
        }
        self.grid = QtWidgets.QGridLayout()
        self.grid_widget = NXWidget()
        self.grid_widget.set_layout(self.grid, 'stretch')
        self.scroll_area = NXScrollArea(self.grid_widget)
        self.scroll_area.setMinimumSize(1250, 300)
        self.insert_layout(3, self.scroll_area)
        self.grid.setSpacing(1)

        self.scans = {}
        self.scans_backup = {}

        row = 0
        # Create (unchecked) checkboxes
        for wrapper_file, scan in wrapper_files.items():
            scan_label = os.path.basename(scan)
            status = {}
            status['scan'] = NXLabel(scan_label)
            if self.parent_file == wrapper_file:
                status['scan'].setStyleSheet('font-weight:bold')
            status['entries'] = []
            status['data'] = self.new_checkbox()
            status['link'] = self.new_checkbox()
            status['copy'] = self.new_checkbox()
            status['max'] = self.new_checkbox()
            status['find'] = self.new_checkbox()
            status['refine'] = self.new_checkbox()
            status['prepare'] = self.new_checkbox()
            status['transform'] = self.new_checkbox()
            status['masked_transform'] = self.new_checkbox()
            status['combine'] = self.new_checkbox()
            status['masked_combine'] = self.new_checkbox()
            status['pdf'] = self.new_checkbox()
            status['masked_pdf'] = self.new_checkbox()
            status['overwrite'] = self.new_checkbox(self.select_scans)
            status['sync'] = self.new_checkbox()
            self.grid.addWidget(status['scan'], row, 0, QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['data'], row, 1, QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['link'], row, 2, QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['copy'], row, 3, QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['max'], row, 4, QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['find'], row, 5, QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['refine'], row, 6,
                                QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['prepare'], row, 7,
                                QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['transform'], row, 8,
                                QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['masked_transform'], row, 9,
                                QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['combine'], row, 10,
                                QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['masked_combine'], row, 11,
                                QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['pdf'], row, 12, QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['masked_pdf'], row, 13,
                                QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['overwrite'], row, 14,
                                QtCore.Qt.AlignCenter)
            self.grid.addWidget(status['sync'], row, 15, QtCore.Qt.AlignCenter)
            self.scans[scan] = status
            row += 1
        self.grid.addWidget(NXLabel('All'), row, 0, QtCore.Qt.AlignCenter)
        all_boxes = {}
        all_boxes['link'] = self.new_checkbox(
            lambda: self.select_status('link'))
        all_boxes['copy'] = self.new_checkbox(
            lambda: self.select_status('copy'))
        all_boxes['max'] = self.new_checkbox(lambda: self.select_status('max'))
        all_boxes['find'] = self.new_checkbox(
            lambda: self.select_status('find'))
        all_boxes['refine'] = self.new_checkbox(
            lambda: self.select_status('refine'))
        all_boxes['prepare'] = self.new_checkbox(
            lambda: self.select_status('prepare'))
        all_boxes['transform'] = self.new_checkbox(
            lambda: self.select_status('transform'))
        all_boxes['masked_transform'] = self.new_checkbox(
            lambda: self.select_status('masked_transform'))
        all_boxes['combine'] = self.new_checkbox(
            lambda: self.select_status('combine'))
        all_boxes['masked_combine'] = self.new_checkbox(
            lambda: self.select_status('masked_combine'))
        all_boxes['pdf'] = self.new_checkbox(lambda: self.select_status('pdf'))
        all_boxes['masked_pdf'] = self.new_checkbox(
            lambda: self.select_status('masked_pdf'))
        all_boxes['overwrite'] = self.new_checkbox(self.select_all)
        all_boxes['sync'] = self.new_checkbox(self.select_all)
        self.grid.addWidget(all_boxes['link'], row, 2, QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['copy'], row, 3, QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['max'], row, 4, QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['find'], row, 5, QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['refine'], row, 6, QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['prepare'], row, 7,
                            QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['transform'], row, 8,
                            QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['masked_transform'], row, 9,
                            QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['combine'], row, 10,
                            QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['masked_combine'], row, 11,
                            QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['pdf'], row, 12, QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['masked_pdf'], row, 13,
                            QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['overwrite'], row, 14,
                            QtCore.Qt.AlignCenter)
        self.grid.addWidget(all_boxes['sync'], row, 15, QtCore.Qt.AlignCenter)
        self.all_scans = all_boxes
        self.start_progress((0, len(wrapper_files)))

        # Populate the checkboxes based on the entries in self.db.File
        for i, (wrapper, scan) in enumerate(wrapper_files.items()):
            status = self.scans[scan]
            status['data'].setEnabled(False)
            f = self.db.get_file(wrapper)
            status['entries'] = f.get_entries()
            for task_name in self.db.task_names:
                # Database columns use nx* names while columns don't
                if task_name.startswith('nx'):
                    col_name = task_name[2:]
                else:
                    col_name = task_name
                checkbox = status[col_name]
                file_status = getattr(f, task_name)
                if file_status == self.db.DONE:
                    checkbox.setCheckState(QtCore.Qt.Checked)
                    checkbox.setEnabled(False)
                elif file_status == self.db.IN_PROGRESS:
                    checkbox.setCheckState(QtCore.Qt.PartiallyChecked)
                    checkbox.setEnabled(True)
                    checkbox.setStyleSheet("color: green")
                elif file_status == self.db.QUEUED:
                    checkbox.setCheckState(QtCore.Qt.PartiallyChecked)
                    checkbox.setEnabled(True)
                    checkbox.setStyleSheet("color: blue")
                elif file_status == self.db.FAILED:
                    checkbox.setCheckState(QtCore.Qt.PartiallyChecked)
                    checkbox.setEnabled(True)
                    checkbox.setStyleSheet("color: red")
            if status['data'].checkState() == QtCore.Qt.Unchecked:
                for task in [
                        'link', 'max', 'find', 'prepare', 'transform',
                        'masked_transform'
                ]:
                    status[task].setEnabled(False)
            self.update_progress(i)

        self.stop_progress()
        self.backup_scans()
        return self.grid
Exemplo n.º 14
0
    def __init__(self, parent=None):

        super().__init__(parent=parent)

        self.textbox = QtWidgets.QTextEdit()
        self.textbox.setMinimumWidth(400)
        self.textbox.setMinimumHeight(200)
        self.textbox.setReadOnly(True)

        self.skipbox = NXLineEdit(0, width=20, align='center')
        self.headbox = NXCheckBox()
        self.delimiters = {
            'Whitespace': None,
            'Tab': '\t',
            'Space': ' ',
            'Comma': ',',
            'Colon': ':',
            'Semicolon': ';'
        }
        self.delcombo = NXComboBox(items=self.delimiters)

        self.groupbox = NXLineEdit('data')
        standard_groups = sorted(
            list(set([g for g in self.mainwindow.nxclasses['NXentry'][2]])))
        other_groups = sorted(
            [g for g in self.mainwindow.nxclasses if g not in standard_groups])
        self.groupcombo = NXComboBox(self.select_class, standard_groups)
        self.groupcombo.insertSeparator(self.groupcombo.count())
        self.groupcombo.add(*other_groups)
        self.groupcombo.select('NXdata')
        self.fieldcombo = NXComboBox(self.select_field)
        self.fieldbox = NXLineEdit(slot=self.update_field)
        self.typecombo = NXComboBox(self.update_field,
                                    self.data_types,
                                    default='float64')
        self.signalcombo = NXComboBox(
            self.update_field,
            ['field', 'signal', 'axis', 'errors', 'exclude'],
            default='field')
        self.field_layout = self.make_layout(
            NXLabel('Output Fields', bold=True),
            self.make_layout(self.fieldcombo, self.fieldbox, self.typecombo,
                             self.signalcombo),
            spacing=5,
            vertical=True)
        self.customizebutton = NXPushButton('Customize Fields',
                                            self.customize_data)

        self.set_layout(self.filebox(slot=self.read_file),
                        self.textbox,
                        self.make_layout('Header Row', self.headbox, 'stretch',
                                         'Skipped Rows', self.skipbox,
                                         'stretch', 'Delimiters',
                                         self.delcombo),
                        NXLabel('Output Group', bold=True),
                        self.make_layout('Class',
                                         self.groupcombo,
                                         'Name',
                                         self.groupbox,
                                         align='left'),
                        self.make_layout(self.customizebutton,
                                         self.close_buttons(save=True),
                                         align='justified'),
                        spacing=5)
        self.set_title("Import " + str(filetype))
        self.data = None
Exemplo n.º 15
0
class MaximumDialog(NXDialog):
    def __init__(self, parent=None):
        super().__init__(parent)

        self.select_entry(self.choose_entry)

        self.parameters = GridParameters()
        self.parameters.add('first', '', 'First Frame')
        self.parameters.add('last', '', 'Last Frame')

        self.output = NXLabel('Maximum Value:')
        self.set_layout(
            self.entry_layout, self.output, self.parameters.grid(),
            self.action_buttons(('Find Maximum', self.find_maximum)),
            self.progress_layout(save=True))
        self.progress_bar.setVisible(False)
        self.progress_bar.setValue(0)
        self.set_title('Find Maximum Value')
        self.reduce = None

    def choose_entry(self):
        self.reduce = NXReduce(self.entry)
        self.maximum = self.reduce.maximum
        if self.reduce.first:
            self.parameters['first'].value = self.reduce.first
        if self.reduce.last:
            self.parameters['last'].value = self.reduce.last

    @property
    def first(self):
        try:
            _first = np.int32(self.parameters['first'].value)
            if _first >= 0:
                return _first
            else:
                return None
        except Exception as error:
            return None

    @property
    def last(self):
        try:
            _last = np.int32(self.parameters['last'].value)
            if _last > 0:
                return _last
            else:
                return None
        except Exception as error:
            return None

    @property
    def maximum(self):
        return np.float(self.output.text().split()[-1])

    @maximum.setter
    def maximum(self, value):
        self.output.setText(f'Maximum Value: {value}')

    def find_maximum(self):
        if is_file_locked(self.reduce.data_file):
            return
        self.start_thread()
        self.reduce = NXReduce(self.entry,
                               first=self.first,
                               last=self.last,
                               maxcount=True,
                               overwrite=True,
                               gui=True)
        self.reduce.moveToThread(self.thread)
        self.reduce.start.connect(self.start_progress)
        self.reduce.update.connect(self.update_progress)
        self.reduce.result.connect(self.get_maximum)
        self.reduce.stop.connect(self.stop)
        self.thread.started.connect(self.reduce.nxmax)
        self.thread.finished.connect(self.stop)
        self.thread.start(QtCore.QThread.LowestPriority)

    def get_maximum(self, maximum):
        self.maximum = maximum

    def stop(self):
        self.stop_progress()
        if self.thread and self.thread.isRunning():
            self.reduce.stopped = True
        self.stop_thread()

    def accept(self):
        try:
            self.reduce.write_maximum(self.maximum)
            self.reduce.record('nxmax',
                               maximum=self.maximum,
                               first_frame=self.first,
                               last_frame=self.last)
            self.reduce.record_end('nxmax')
            self.stop()
            super().accept()
        except Exception as error:
            report_error("Finding Maximum", error)

    def reject(self):
        self.stop()
        super().reject()
Exemplo n.º 16
0
    def list_peaks(self):
        if self.peaks_box in self.mainwindow.dialogs:
            self.update_table()
            return
        self.peaks_box = NXDialog(self)
        self.peaks_box.setMinimumWidth(600)
        self.peaks_box.setMinimumHeight(600)
        header = [
            'i', 'x', 'y', 'z', 'Polar', 'Azi', 'Intensity', 'H', 'K', 'L',
            'Diff'
        ]
        peak_list = self.refine.get_peaks()
        self.refine.assign_rings()
        self.rings = self.refine.make_rings()
        self.ring_list = self.refine.get_ring_list()
        if self.refine.primary is None:
            self.refine.primary = 0
        if self.refine.secondary is None:
            self.refine.secondary = 1
        self.primary_box = NXLineEdit(self.refine.primary,
                                      width=80,
                                      align='right')
        self.secondary_box = NXLineEdit(self.refine.secondary,
                                        width=80,
                                        align='right')
        orient_button = NXPushButton('Orient', self.choose_peaks)
        orient_layout = self.make_layout(NXLabel('Primary'),
                                         self.primary_box,
                                         NXLabel('Secondary'),
                                         self.secondary_box,
                                         'stretch',
                                         orient_button,
                                         align='right')

        self.table_view = QtWidgets.QTableView()
        self.table_model = NXTableModel(self, peak_list, header)
        self.table_view.setModel(self.table_model)
        self.table_view.resizeColumnsToContents()
        self.table_view.horizontalHeader().stretchLastSection()
        self.table_view.setSelectionBehavior(
            QtWidgets.QAbstractItemView.SelectRows)
        self.table_view.doubleClicked.connect(self.plot_peak)
        self.table_view.setSortingEnabled(True)
        self.table_view.sortByColumn(0, QtCore.Qt.AscendingOrder)
        self.status_text = NXLabel(f'Score: {self.refine.score():.4f}')
        self.tolerance_box = NXLineEdit(self.refine.hkl_tolerance,
                                        width=80,
                                        slot=self.update_table,
                                        align='right')
        self.tolerance_box.setMaxLength(5)
        export_button = NXPushButton('Export', self.export_peaks)
        save_button = NXPushButton('Save', self.save_orientation)
        close_button = NXPushButton('Close', self.close_peaks_box)
        close_layout = self.make_layout(self.status_text, 'stretch',
                                        NXLabel('Threshold'),
                                        self.tolerance_box, 'stretch',
                                        export_button, save_button,
                                        close_button)
        self.peaks_box.set_layout(orient_layout, self.table_view, close_layout)
        self.peaks_box.set_title(f'{self.refine.name} Peak Table')
        self.peaks_box.adjustSize()
        self.peaks_box.show()
        self.plotview = None