コード例 #1
0
    def __init__(self, parent=None):

        super(ImportDialog, self).__init__(parent)

        try:
            import spec2nexus
        except ImportError:
            raise NeXusError("Please install the 'spec2nexus' module")

        self.accepted = False
        self.import_file = None  # must set in self.get_data()
        self.spec = None

        # progress bar is updated via calls to pdate_progress()
        self.progress_bar = QtWidgets.QProgressBar()
        self.progress_bar.setVisible(False)

        status_layout = QtWidgets.QHBoxLayout()
        status_layout.addWidget(self.progress_bar)
        status_layout.addStretch()
        status_layout.addWidget(self.close_buttons())

        self.layout = QtWidgets.QVBoxLayout()
        self.layout.addLayout(self.filebox())
        self.layout.addLayout(self.scanbox())
        self.layout.addLayout(status_layout)
        self.setLayout(self.layout)

        self.setWindowTitle("Import " + str(filetype))
コード例 #2
0
    def make_filter_box(self):
        filter_box = QtWidgets.QWidget()
        layout = QtWidgets.QGridLayout()
        layout.setSpacing(10)
        prefix_label = QtWidgets.QLabel('File Prefix')
        self.prefix_box = QtWidgets.QLineEdit()
        self.prefix_box.editingFinished.connect(self.set_range)
        extension_label = QtWidgets.QLabel('File Extension')
        self.extension_box = QtWidgets.QLineEdit()
        self.extension_box.editingFinished.connect(self.set_extension)
        suffix_label = QtWidgets.QLabel('File Suffix')
        self.suffix_box = QtWidgets.QLineEdit('')
        self.suffix_box.editingFinished.connect(self.get_prefixes)
        layout.addWidget(prefix_label, 0, 0)
        layout.addWidget(self.prefix_box, 0, 1)
        layout.addWidget(extension_label, 0, 2)
        layout.addWidget(self.extension_box, 0, 3)
        layout.addWidget(suffix_label, 0, 4)
        layout.addWidget(self.suffix_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, 3, alignment=QtCore.Qt.AlignHCenter)

        filter_box.setLayout(layout)
        filter_box.setVisible(False)
        return filter_box
コード例 #3
0
ファイル: find_peaks.py プロジェクト: pat-gardner/nxrefine
    def __init__(self, parent=None):
        super(FindDialog, self).__init__(parent)

        self.select_entry(self.choose_entry)

        self.parameters = GridParameters()
        self.parameters.add('threshold', '', 'Threshold')
        self.parameters.add('first', '', 'First Frame')
        self.parameters.add('last', '', 'Last Frame')
        find_layout = QtWidgets.QHBoxLayout()
        self.find_button = QtWidgets.QPushButton('Find Peaks')
        self.find_button.clicked.connect(self.find_peaks)
        self.peak_count = QtWidgets.QLabel()
        self.peak_count.setVisible(False)
        find_layout.addStretch()
        find_layout.addWidget(self.find_button)
        find_layout.addWidget(self.peak_count)
        find_layout.addStretch()
        self.set_layout(self.entry_layout, 
                        self.parameters.grid(),
                        find_layout,
                        self.progress_layout(save=True))
        self.progress_bar.setVisible(False)
        self.progress_bar.setValue(0)
        self.set_title('Find Peaks')
        self.reduce = None
コード例 #4
0
    def __init__(self, parent=None):

        super(ImportDialog, self).__init__(parent)

        self.layout = QtWidgets.QVBoxLayout()

        self.layout.addLayout(self.directorybox())

        self.filter_box = self.make_filterbox()
        self.layout.addWidget(self.filter_box)

        self.rangebox = self.make_rangebox()
        self.layout.addWidget(self.rangebox)

        status_layout = QtWidgets.QHBoxLayout()
        self.progress_bar = QtWidgets.QProgressBar()
        status_layout.addWidget(self.progress_bar)
        self.progress_bar.setVisible(False)
        status_layout.addStretch()
        status_layout.addWidget(self.buttonbox())
        self.layout.addLayout(status_layout)

        self.setLayout(self.layout)

        self.setWindowTitle("Import " + str(filetype))
コード例 #5
0
    def __init__(self, parent=None):

        super().__init__(parent=parent)

        try:
            from globusonline.catalog.client.examples.catalog_wrapper import \
                CatalogWrapper
        except ImportError:
            raise NeXusError("Cannot import globusonline package")
        token_file = os.path.join(os.path.expanduser('~'), '.nexpy',
                                  'globusonline', 'gotoken.txt')
        self.wrap = CatalogWrapper(token='file', token_file=token_file)
        _, self.catalogs = self.wrap.catalogClient.get_catalogs()
        catalog_layout = QtWidgets.QHBoxLayout()
        self.catalog_box = QtWidgets.QComboBox()
        for catalog in self.catalogs:
            try:
                self.catalog_box.addItem(catalog['config']['name'])
            except Exception:
                pass
        self.catalog_box.setSizeAdjustPolicy(
            QtWidgets.QComboBox.AdjustToContents)
        catalog_button = QtWidgets.QPushButton("Choose Catalog")
        catalog_button.clicked.connect(self.get_catalog)
        catalog_layout.addWidget(self.catalog_box)
        catalog_layout.addWidget(catalog_button)
        self.layout = QtWidgets.QVBoxLayout()
        self.layout.addLayout(catalog_layout)
        self.layout.addWidget(self.close_buttons())
        self.setLayout(self.layout)

        self.setWindowTitle("Import " + str(filetype))
コード例 #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))
コード例 #7
0
 def new_checkbox(self, slot=None):
     checkbox = QtWidgets.QCheckBox()
     checkbox.setCheckState(QtCore.Qt.Unchecked)
     checkbox.setEnabled(True)
     if slot:
         checkbox.stateChanged.connect(slot)
     return checkbox
コード例 #8
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.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.peaks_box.set_layout(self.table_view,
                               self.close_buttons(close=True))
     self.peaks_box.set_title(f'{self.refine.name} Peak Table')
     self.peaks_box.adjustSize()
     self.peaks_box.show()
     self.plotview = None
コード例 #9
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)
コード例 #10
0
    def make_output_box(self):
        """
        Creates a text box and button for selecting the output file.
        """
        output_box = QtWidgets.QWidget()
        layout = QtWidgets.QHBoxLayout()
       
        file_button =  QtWidgets.QPushButton("Choose Output File")
        file_button.clicked.connect(self.choose_output_file)
        self.output_file = QtWidgets.QLineEdit(self)
        self.output_file.setMinimumWidth(300)
        layout.addWidget(file_button)
        layout.addWidget(self.output_file)

        output_box.setLayout(layout)
        output_box.setVisible(False)
        return output_box
コード例 #11
0
ファイル: readspec.py プロジェクト: aaron-parsons/nexpy
    def scanbox(self):
        '''create widgets for specifying scan range to import'''
        scanminlabel = QtWidgets.QLabel("Min. Scan")
        self.scanmin = QtWidgets.QLineEdit()
        self.scanmin.setFixedWidth(100)
        self.scanmin.setAlignment(QtCore.Qt.AlignRight)
        scanmaxlabel = QtWidgets.QLabel("Max. Scan")
        self.scanmax = QtWidgets.QLineEdit()
        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
コード例 #12
0
 def get_dataset(self):
     self.dataset_id = self.get_dataset_id(self.dataset_box.currentText())
     _, self.members = self.wrap.catalogClient.get_members(
         self.catalog_id, self.dataset_id)
     member_layout = QtWidgets.QHBoxLayout()
     self.member_box = QtWidgets.QComboBox()
     for member in self.members:
         try:
             self.member_box.addItem(member['data_uri'])
         except Exception:
             pass
     self.member_box.setSizeAdjustPolicy(
         QtWidgets.QComboBox.AdjustToContents)
     member_button = QtWidgets.QPushButton("Choose Member")
     member_button.clicked.connect(self.get_member)
     member_layout.addWidget(self.member_box)
     member_layout.addWidget(member_button)
     self.layout.insertLayout(2, member_layout)
コード例 #13
0
 def get_catalog(self):
     self.catalog_id = self.get_catalog_id(self.catalog_box.currentText())
     _, self.datasets = self.wrap.catalogClient.get_datasets(
         self.catalog_id)
     dataset_layout = QtWidgets.QHBoxLayout()
     self.dataset_box = QtWidgets.QComboBox()
     for dataset in self.datasets:
         try:
             self.dataset_box.addItem(dataset['name'])
         except Exception:
             pass
     self.dataset_box.setSizeAdjustPolicy(
         QtWidgets.QComboBox.AdjustToContents)
     dataset_button = QtWidgets.QPushButton("Choose Dataset")
     dataset_button.clicked.connect(self.get_dataset)
     dataset_layout.addWidget(self.dataset_box)
     dataset_layout.addWidget(dataset_button)
     self.layout.insertLayout(1, dataset_layout)
コード例 #14
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
コード例 #15
0
    def __init__(self, parent=None):

        super(ImportDialog, self).__init__(parent)
        
        skippedbox = QtWidgets.QHBoxLayout()
        skippedlabel = QtWidgets.QLabel("No. of skipped rows")
        self.skiprows = QtWidgets.QLineEdit()
        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))
コード例 #16
0
    def __init__(self, parent=None):

        super(StackDialog, self).__init__(parent)
        
        status_layout = QtWidgets.QHBoxLayout()
        self.progress_bar = QtWidgets.QProgressBar()
        status_layout.addWidget(self.progress_bar)
        self.progress_bar.setVisible(False)
        status_layout.addStretch()
        status_layout.addWidget(self.close_buttons(save=True))

        self.set_layout(self.directorybox(), 
                        self.make_filter_box(),
                        self.make_range_box(),
                        self.make_output_box(),
                        status_layout)

        self.setLayout(self.layout)
        self.set_title('Stack Images')
  
        self.suffix = ''
コード例 #17
0
    def __init__(self, parent=None):
        super(OrientationDialog, self).__init__(parent)

        self.select_entry(self.choose_entry)

        self.refine = NXRefine(self.entry)
        self.refine.read_parameters()

        self.parameters = GridParameters()
        self.parameters.add('phi_start', self.refine.phi, 'Phi Start (deg)')
        self.parameters.add('phi_step', self.refine.phi_step, 'Phi Step (deg)')
        self.parameters.add('chi', self.refine.chi, 'Chi (deg)')
        self.parameters.add('omega', self.refine.omega, 'Omega (deg)')
        self.parameters.add('polar', self.refine.polar_max,
                            'Max. Polar Angle (deg)')
        self.parameters.add('polar_tolerance', self.refine.polar_tolerance,
                            'Polar Angle Tolerance')
        self.parameters.add('peak_tolerance', self.refine.peak_tolerance,
                            'Peak Angle Tolerance')
        action_buttons = self.action_buttons(
            ('Generate Grains', self.generate_grains),
            ('List Peaks', self.list_peaks))
        self.grain_layout = QtWidgets.QHBoxLayout()
        self.grain_combo = QtWidgets.QComboBox()
        self.grain_combo.setSizeAdjustPolicy(
            QtWidgets.QComboBox.AdjustToContents)
        self.grain_combo.currentIndexChanged.connect(self.set_grain)
        self.grain_textbox = QtWidgets.QLabel()
        self.grain_layout.addWidget(self.grain_combo)
        self.grain_layout.addStretch()
        self.grain_layout.addWidget(self.grain_textbox)
        bottom_layout = QtWidgets.QHBoxLayout()
        self.result_textbox = QtWidgets.QLabel()
        bottom_layout.addWidget(self.result_textbox)
        bottom_layout.addStretch()
        bottom_layout.addWidget(self.close_buttons())
        self.set_layout(self.entry_layout, self.parameters.grid(),
                        action_buttons, bottom_layout)
        self.set_title('Defining Orientation')
コード例 #18
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
コード例 #19
0
ファイル: find_maximum.py プロジェクト: pat-gardner/nxrefine
    def __init__(self, parent=None):
        super(MaximumDialog, self).__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 = QtWidgets.QLabel('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
コード例 #20
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
コード例 #21
0
    def update(self):
        if not self.sample_directory:
            raise NeXusError("No sample directory declared")

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

        # 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.insert_layout(2, self.grid)
        self.grid.setSpacing(1)
        row = 0
        columns = [
            'Scan', 'data', 'link', 'max', 'find', 'copy', 'refine',
            'transform', 'masked_transform', 'combine', 'masked_combine',
            'pdf', 'overwrite', 'reduce', 'sync'
        ]
        header = {}
        for col, column in enumerate(columns):
            header[column] = QtWidgets.QLabel(column)
            header[column].setFont(self.bold_font)
            header[column].setFixedWidth(75)
            if column == 'transform' or column == 'combine':
                self.grid.addWidget(header[column], row, col, 1, 2,
                                    QtCore.Qt.AlignHCenter)
            elif 'masked' not in column:
                self.grid.addWidget(header[column], row, col)
                header[column].setAlignment(QtCore.Qt.AlignHCenter)
        row = 1
        columns = ['regular', 'masked', 'regular', 'masked']
        for col, column in enumerate(columns):
            header[column] = QtWidgets.QLabel(column)
            header[column].setFixedWidth(75)
            header[column].setAlignment(QtCore.Qt.AlignHCenter)
            self.grid.addWidget(header[column], row, col + 7)

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

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

        # Populate the checkboxes based on the entries in nxdb.File
        for i, (wrapper, scan) in enumerate(wrapper_files.items()):
            status = self.scans[scan]
            status['data'].setEnabled(False)
            f = nxdb.get_file(wrapper)
            for task_name in nxdb.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 == nxdb.DONE:
                    checkbox.setCheckState(QtCore.Qt.Checked)
                    checkbox.setEnabled(False)
                elif file_status == nxdb.IN_PROGRESS:
                    checkbox.setCheckState(QtCore.Qt.PartiallyChecked)
                    checkbox.setEnabled(True)
                elif file_status == nxdb.QUEUED:
                    checkbox.setCheckState(QtCore.Qt.PartiallyChecked)
                    checkbox.setEnabled(False)
                elif file_status == nxdb.FAILED:
                    checkbox.setCheckState(QtCore.Qt.Unchecked)
                    checkbox.setEnabled(True)
                # TODO: do i need to account for last?
            if status['data'].checkState() == QtCore.Qt.Unchecked:
                self.disable_status(status)
            self.update_progress(i)

        self.stop_progress()
        self.backup_scans()
        return self.grid
コード例 #22
0
    def __init__(self, parent=None):
        super(TransformDialog, self).__init__(parent)

        self.select_entry(self.initialize_grid)
        self.refine = NXRefine()

        grid = QtWidgets.QGridLayout()
        grid.setSpacing(10)
        header_font = QtGui.QFont()
        header_font.setBold(True)
        start_label = QtWidgets.QLabel('Start')
        start_label.setFont(header_font)
        grid.addWidget(start_label, 0, 1)
        step_label = QtWidgets.QLabel('Step')
        step_label.setFont(header_font)
        grid.addWidget(step_label, 0, 2)
        stop_label = QtWidgets.QLabel('Stop')
        stop_label.setFont(header_font)
        grid.addWidget(stop_label, 0, 3)
        grid.addWidget(QtWidgets.QLabel('H:'), 1, 0)
        grid.addWidget(QtWidgets.QLabel('K:'), 2, 0)
        grid.addWidget(QtWidgets.QLabel('L:'), 3, 0)
        self.start_h_box = QtWidgets.QLineEdit()
        self.step_h_box = QtWidgets.QLineEdit()
        self.stop_h_box = QtWidgets.QLineEdit()
        grid.addWidget(self.start_h_box, 1, 1)
        grid.addWidget(self.step_h_box, 1, 2)
        grid.addWidget(self.stop_h_box, 1, 3)
        self.start_k_box = QtWidgets.QLineEdit()
        self.step_k_box = QtWidgets.QLineEdit()
        self.stop_k_box = QtWidgets.QLineEdit()
        grid.addWidget(self.start_k_box, 2, 1)
        grid.addWidget(self.step_k_box, 2, 2)
        grid.addWidget(self.stop_k_box, 2, 3)
        self.start_l_box = QtWidgets.QLineEdit()
        self.step_l_box = QtWidgets.QLineEdit()
        self.stop_l_box = QtWidgets.QLineEdit()
        grid.addWidget(self.start_l_box, 3, 1)
        grid.addWidget(self.step_l_box, 3, 2)
        grid.addWidget(self.stop_l_box, 3, 3)
        self.set_layout(
            self.entry_layout, grid,
            self.checkboxes(
                ('copy', 'Copy to all entries', True),
                ('mask', 'Create masked transform group', True),
                ('overwrite', 'Overwrite existing transforms', False)),
            self.close_buttons(save=True))
        self.setWindowTitle('Transforming Data')
        try:
            self.initialize_grid()
        except Exception:
            pass
コード例 #23
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
コード例 #24
0
ファイル: refine_lattice.py プロジェクト: rayosborn/nxrefine
    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
コード例 #25
0
    def list_orientations(self):
        message_box = BaseDialog(self)
        message_box.setMinimumWidth(600)
        message_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.get_ring_hkls()
        orient_layout = QtWidgets.QHBoxLayout()
        if self.refine.primary is None:
            self.refine.primary = 0
        if self.refine.secondary is None:
            self.refine.secondary = 1
        self.primary_box = QtWidgets.QLineEdit(str(self.refine.primary))
        self.primary_box.setAlignment(QtCore.Qt.AlignRight)
        self.primary_box.setFixedWidth(80)
        self.secondary_box = QtWidgets.QLineEdit(str(self.refine.secondary))
        self.secondary_box.setAlignment(QtCore.Qt.AlignRight)
        self.secondary_box.setFixedWidth(80)
        orient_button = QtWidgets.QPushButton('Orient')
        orient_button.clicked.connect(self.orient)
        refine_button = QtWidgets.QPushButton('Refine')
        refine_button.clicked.connect(self.refine_orientation)
        restore_button = QtWidgets.QPushButton('Restore')
        restore_button.clicked.connect(self.restore_orientation)
        orient_layout.addStretch()
        orient_layout.addWidget(QtWidgets.QLabel('Primary'))
        orient_layout.addWidget(self.primary_box)
        orient_layout.addWidget(QtWidgets.QLabel('Secondary'))
        orient_layout.addWidget(self.secondary_box)
        orient_layout.addStretch()
        orient_layout.addWidget(orient_button)
        orient_layout.addWidget(refine_button)
        orient_layout.addWidget(restore_button)

        grid = QtWidgets.QGridLayout()
        grid.setSpacing(10)
        self.lattice = GridParameters()
        self.lattice.add('a', self.refine.a, 'a', False)
        self.lattice.add('b', self.refine.b, 'b', False)
        self.lattice.add('c', self.refine.c, 'c', False)
        self.lattice.add('alpha', self.refine.alpha, 'alpha', False)
        self.lattice.add('beta', self.refine.beta, 'beta', False)
        self.lattice.add('gamma', self.refine.gamma, 'gamma', False)
        p = self.lattice['a']
        p.box.setFixedWidth(80)
        label, value, checkbox = p.label, p.value, p.vary
        grid.addWidget(p.label, 0, 0, QtCore.Qt.AlignRight)
        grid.addWidget(p.box, 0, 1, QtCore.Qt.AlignHCenter)
        grid.addWidget(p.checkbox, 0, 2, QtCore.Qt.AlignHCenter)
        p = self.lattice['b']
        p.box.setFixedWidth(80)
        label, value, checkbox = p.label, p.value, p.vary
        grid.addWidget(p.label, 0, 3, QtCore.Qt.AlignRight)
        grid.addWidget(p.box, 0, 4, QtCore.Qt.AlignHCenter)
        grid.addWidget(p.checkbox, 0, 5, QtCore.Qt.AlignHCenter)
        p = self.lattice['c']
        p.box.setFixedWidth(80)
        label, value, checkbox = p.label, p.value, p.vary
        grid.addWidget(p.label, 0, 6, QtCore.Qt.AlignRight)
        grid.addWidget(p.box, 0, 7, QtCore.Qt.AlignHCenter)
        grid.addWidget(p.checkbox, 0, 8, QtCore.Qt.AlignHCenter)
        p = self.lattice['alpha']
        p.box.setFixedWidth(80)
        label, value, checkbox = p.label, p.value, p.vary
        grid.addWidget(p.label, 1, 0, QtCore.Qt.AlignRight)
        grid.addWidget(p.box, 1, 1, QtCore.Qt.AlignHCenter)
        grid.addWidget(p.checkbox, 1, 2, QtCore.Qt.AlignHCenter)
        p = self.lattice['beta']
        p.box.setFixedWidth(80)
        label, value, checkbox = p.label, p.value, p.vary
        grid.addWidget(p.label, 1, 3, QtCore.Qt.AlignRight)
        grid.addWidget(p.box, 1, 4, QtCore.Qt.AlignHCenter)
        grid.addWidget(p.checkbox, 1, 5, QtCore.Qt.AlignHCenter)
        p = self.lattice['gamma']
        p.box.setFixedWidth(80)
        label, value, checkbox = p.label, p.value, p.vary
        grid.addWidget(p.label, 1, 6, QtCore.Qt.AlignRight)
        grid.addWidget(p.box, 1, 7, QtCore.Qt.AlignHCenter)
        grid.addWidget(p.checkbox, 1, 8, QtCore.Qt.AlignHCenter)
        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)
        layout = QtWidgets.QVBoxLayout()
        layout.addLayout(orient_layout)
        layout.addLayout(grid)
        layout.addWidget(self.table_view)
        close_layout = QtWidgets.QHBoxLayout()
        self.status_text = QtWidgets.QLabel('Score: %.4f' %
                                            self.refine.score())
        self.tolerance_box = QtWidgets.QLineEdit(str(
            self.refine.hkl_tolerance))
        self.tolerance_box.setAlignment(QtCore.Qt.AlignRight)
        self.tolerance_box.setMaxLength(5)
        self.tolerance_box.editingFinished.connect(self.update_table)
        self.tolerance_box.setFixedWidth(80)
        save_button = QtWidgets.QPushButton('Save Orientation')
        save_button.clicked.connect(self.save_orientation)
        close_button = QtWidgets.QPushButton('Close Window')
        close_button.clicked.connect(message_box.close)
        close_layout.addWidget(self.status_text)
        close_layout.addStretch()
        close_layout.addWidget(QtWidgets.QLabel('Threshold'))
        close_layout.addWidget(self.tolerance_box)
        close_layout.addStretch()
        close_layout.addWidget(save_button)
        close_layout.addStretch()
        close_layout.addWidget(close_button)
        layout.addLayout(close_layout)
        message_box.setLayout(layout)
        message_box.setWindowTitle('%s Peak Table' % self.entry.nxtitle)
        message_box.adjustSize()
        message_box.show()
        self.plotview = None
コード例 #26
0
    def list_peaks(self):
        if self.peaks_box is not None and self.table_model is not None:
            self.update_table()
            return
        self.peaks_box = BaseDialog(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.get_ring_hkls()
        orient_layout = QtWidgets.QHBoxLayout()
        if self.refine.primary is None:
            self.refine.primary = 0
        if self.refine.secondary is None:
            self.refine.secondary = 1
        self.primary_box = QtWidgets.QLineEdit(str(self.refine.primary))
        self.primary_box.setAlignment(QtCore.Qt.AlignRight)
        self.primary_box.setFixedWidth(80)
        self.secondary_box = QtWidgets.QLineEdit(str(self.refine.secondary))
        self.secondary_box.setAlignment(QtCore.Qt.AlignRight)
        self.secondary_box.setFixedWidth(80)
        orient_button = QtWidgets.QPushButton('Orient')
        orient_button.clicked.connect(self.orient)

        orient_layout.addStretch()
        orient_layout.addWidget(QtWidgets.QLabel('Primary'))
        orient_layout.addWidget(self.primary_box)
        orient_layout.addWidget(QtWidgets.QLabel('Secondary'))
        orient_layout.addWidget(self.secondary_box)
        orient_layout.addStretch()
        orient_layout.addWidget(orient_button)

        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)
        layout = QtWidgets.QVBoxLayout()
        layout.addLayout(orient_layout)
        layout.addWidget(self.table_view)
        close_layout = QtWidgets.QHBoxLayout()
        self.status_text = QtWidgets.QLabel('Score: %.4f' %
                                            self.refine.score())
        self.tolerance_box = QtWidgets.QLineEdit(str(
            self.refine.hkl_tolerance))
        self.tolerance_box.setAlignment(QtCore.Qt.AlignRight)
        self.tolerance_box.setMaxLength(5)
        self.tolerance_box.editingFinished.connect(self.update_table)
        self.tolerance_box.setFixedWidth(80)
        save_button = QtWidgets.QPushButton('Save Orientation')
        save_button.clicked.connect(self.save_orientation)
        close_button = QtWidgets.QPushButton('Close Window')
        close_button.clicked.connect(self.close_peaks_box)
        close_layout.addWidget(self.status_text)
        close_layout.addStretch()
        close_layout.addWidget(QtWidgets.QLabel('Threshold'))
        close_layout.addWidget(self.tolerance_box)
        close_layout.addStretch()
        close_layout.addWidget(save_button)
        close_layout.addStretch()
        close_layout.addWidget(close_button)
        layout.addLayout(close_layout)
        self.peaks_box.setLayout(layout)
        self.peaks_box.setWindowTitle('%s Peak Table' % self.entry.nxtitle)
        self.peaks_box.adjustSize()
        self.peaks_box.show()
        self.plotview = None