Beispiel #1
0
    def indexer_finished(self):
        # Compute number of orientations run_cluster() will use
        # to make sure there aren't too many
        config = create_indexing_config()
        min_compl = config.find_orientations.clustering.completeness
        num_orientations = (np.array(self.completeness) > min_compl).sum()

        num_orientations_warning_threshold = 1e6
        if num_orientations > num_orientations_warning_threshold:
            formatted = format_big_int(num_orientations)
            msg = (f'Over {formatted} orientations are staged for '
                   'clustering. This may use up too much memory.\n\n'
                   'Proceed anyways?')

            response = QMessageBox.question(self.parent, 'WARNING', msg)
            if response == QMessageBox.No:
                # Go back to the eta omega maps viewer
                self.accept_progress()
                self.view_ome_maps()
                return

        worker = AsyncWorker(self.run_cluster_functions)
        self.thread_pool.start(worker)

        worker.signals.result.connect(self.start_fit_grains_runner,
                                      Qt.QueuedConnection)
        worker.signals.finished.connect(self.accept_progress)
        worker.signals.error.connect(self.on_async_error)
Beispiel #2
0
    def run_indexer(self):
        config = create_indexing_config()

        # Find orientations
        self.update_progress_text('Running indexer (paintGrid)')
        ncpus = config.multiprocessing
        self.completeness = indexer.paintGrid(
            self.qfib,
            self.ome_maps,
            etaRange=np.radians(config.find_orientations.eta.range),
            omeTol=np.radians(config.find_orientations.omega.tolerance),
            etaTol=np.radians(config.find_orientations.eta.tolerance),
            omePeriod=np.radians(config.find_orientations.omega.period),
            threshold=config.find_orientations.threshold,
            doMultiProc=ncpus > 1,
            nCPUs=ncpus)
        print('paintGrid complete')

        orientations_cfg = HexrdConfig().indexing_config['find_orientations']
        if orientations_cfg.get('_write_scored_orientations'):
            # Write out the scored orientations
            results = {}
            results['scored_orientations'] = {
                'test_quaternions': self.qfib,
                'score': self.completeness
            }
            print(f'Writing scored orientations in {config.working_dir} ...')
            write_scored_orientations(results, config)
Beispiel #3
0
    def ome_maps_viewed(self):
        # The dialog should have automatically updated our internal config
        # Let's go ahead and run the indexing!

        # Create a full indexing config
        config = create_indexing_config()

        # Hexrd normally applies filtering immediately after eta omega
        # maps are loaded. We will perform the user-selected filtering now.
        filter_maps_if_requested(self.ome_maps, config)

        # Setup to run indexing in background
        self.progress_dialog.setWindowTitle('Find Orientations')
        self.progress_dialog.setRange(0, 0)  # no numerical updates

        find_orientations = HexrdConfig().indexing_config['find_orientations']
        if find_orientations['use_quaternion_grid']:
            # Load qfib from a numpy file
            self.qfib = np.load(find_orientations['use_quaternion_grid'])
            self.orientation_fibers_generated()
        else:
            worker = AsyncWorker(self.generate_orientation_fibers, config)
            self.thread_pool.start(worker)

            worker.signals.result.connect(self.orientation_fibers_generated)
            worker.signals.error.connect(self.on_async_error)

        self.progress_dialog.exec_()
Beispiel #4
0
    def fit_grains_options_accepted(self):
        # Create a full indexing config
        config = create_indexing_config()

        # Setup to run in background
        self.progress_dialog.setWindowTitle('Fit Grains')
        self.progress_dialog.setRange(0, 0)  # no numerical updates

        worker = AsyncWorker(self.run_fit_grains, config)
        self.thread_pool.start(worker)

        worker.signals.result.connect(self.view_fit_grains_results)
        worker.signals.finished.connect(self.progress_dialog.accept)
        self.progress_dialog.exec_()
Beispiel #5
0
    def run_fit_grains(self):
        cfg = create_indexing_config()
        write_spots = HexrdConfig().indexing_config.get('_write_spots', False)

        num_grains = self.grains_table.shape[0]
        self.update_progress_text(f'Running fit grains on {num_grains} grains')
        kwargs = {
            'cfg': cfg,
            'grains_table': self.grains_table,
            'write_spots_files': write_spots,
        }
        self.fit_grains_results = fit_grains(**kwargs)
        print('Fit Grains Complete')

        # If we wrote out the spots, let's write out the grains.out file too
        if write_spots:
            write_fit_grains_results(self.fit_grains_results, cfg)
Beispiel #6
0
    def run_cluster(self):
        print('Running cluster...')
        self.update_progress_text('Running cluster')
        config = create_indexing_config()
        kwargs = {
            'compl': self.completeness,
            'qfib': self.qfib,
            'qsym': config.material.plane_data.getQSym(),
            'cfg': config,
            'min_samples': self.min_samples,
            'compl_thresh': config.find_orientations.clustering.completeness,
            'radius': config.find_orientations.clustering.radius
        }
        self.qbar, cl = run_cluster(**kwargs)

        print('Clustering complete...')
        self.generate_grains_table()
Beispiel #7
0
    def ome_maps_viewed(self):
        # The dialog should have automatically updated our internal config
        # Let's go ahead and run the indexing!

        # For now, always use all hkls from eta omega maps
        hkls = list(range(len(self.ome_maps.iHKLList)))
        indexing_config = HexrdConfig().indexing_config
        indexing_config['find_orientations']['seed_search']['hkl_seeds'] = hkls

        # Create a full indexing config
        config = create_indexing_config()

        # Setup to run indexing in background
        self.progress_dialog.setWindowTitle('Find Orientations')
        self.progress_dialog.setRange(0, 0)  # no numerical updates

        worker = AsyncWorker(self.run_indexer, config)
        self.thread_pool.start(worker)

        worker.signals.result.connect(self.view_fit_grains_options)
        worker.signals.finished.connect(self.progress_dialog.accept)
        self.progress_dialog.exec_()
Beispiel #8
0
    def ome_maps_selected(self):
        dialog = self.ome_maps_select_dialog
        if dialog is None:
            return

        if dialog.method_name == 'load':
            self.ome_maps = EtaOmeMaps(dialog.file_name)
            self.ome_maps_select_dialog = None
            self.view_ome_maps()
        else:
            # Create a full indexing config
            config = create_indexing_config()

            # Setup to generate maps in background
            self.progress_dialog.setWindowTitle('Generating Eta Omega Maps')
            self.progress_dialog.setRange(0, 0)  # no numerical updates

            worker = AsyncWorker(self.run_eta_ome_maps, config)
            self.thread_pool.start(worker)

            worker.signals.result.connect(self.view_ome_maps)
            worker.signals.finished.connect(self.progress_dialog.accept)
            self.progress_dialog.exec_()
Beispiel #9
0
 def create_clustering_parameters(self):
     print('Creating cluster parameters...')
     self.update_progress_text('Creating cluster parameters')
     config = create_indexing_config()
     self.min_samples, mean_rpg = create_clustering_parameters(
         config, self.ome_maps)