Example #1
0
    def update_dict_profile_to_fit(self):
        [left_range, right_range] = self.bragg_edge_range

        o_selection = BraggEdgeSelectionTab(parent=self)
        [x0, y0, x1, y1] = o_selection.get_shrinking_roi_dimension()
        o_get = Get(parent=self)
        profile = o_get.profile_of_roi(x0=x0, y0=y0,
                                       x1=x1, y1=y1)

        yaxis = profile[left_range: right_range]

        all_x_axis = o_get.all_x_axis()
        index_array = all_x_axis['index'][0]
        tof_array = all_x_axis['tof'][0]
        lambda_array = all_x_axis['lambda'][0]

        index_selected = index_array[left_range: right_range]
        tof_selected = tof_array[left_range: right_range]
        lambda_selected = lambda_array[left_range: right_range]

        profile_to_fit = {'yaxis': yaxis,
                          'xaxis': {'index': index_selected,
                                    'tof': tof_selected,
                                    'lambda': lambda_selected},
                          }
        self.dict_profile_to_fit = profile_to_fit
Example #2
0
 def selection_roi_slider_changed(self, new_value):
     if self.ui.square_roi_radiobutton.isChecked():
         mode = 'square'
     else:
         mode = 'free'
     o_selection = BraggEdgeSelectionTab(parent=self)
     o_selection.update_selection(new_value=new_value,
                                  mode=mode)
Example #3
0
    def profile_of_bin_size_slider_changed_after_import(self, new_value):
        dict_rois_imported = self.dict_rois_imported
        new_width = dict_rois_imported[new_value]['width']
        new_height = dict_rois_imported[new_value]['height']
        self.ui.profile_of_bin_size_height.setText(new_height)
        self.ui.profile_of_bin_size_width.setText(new_width)

        o_selection = BraggEdgeSelectionTab(parent=self)
        o_selection.update_selection_plot()

        self.update_vertical_line_in_profile_plot()
        self.update_kropff_fit_table_graph(fit_region='high')
        self.update_kropff_fit_table_graph(fit_region='low')
        self.update_kropff_fit_table_graph(fit_region='bragg_peak')
Example #4
0
    def roi_radiobuttons_changed(self):
        if self.ui.square_roi_radiobutton.isChecked():
            slider_visible = True
            new_width = np.min([np.int(str(self.ui.roi_width.text())),
                                np.int(str(self.ui.roi_height.text()))])
            mode = 'square'
        else:
            slider_visible = False
            new_width = np.int(str(self.ui.roi_width.text()))
            self.selection_roi_slider_changed(new_width)
            mode = 'free'

        o_selection = BraggEdgeSelectionTab(parent=self)
        o_selection.update_selection(new_value=new_width,
                                     mode=mode)

        self.ui.roi_size_slider.setVisible(slider_visible)
Example #5
0
    def __init__(self, parent=None, working_dir="", o_bragg=None, spectra_file=None):

        if o_bragg:
            # self.working_dir = o_bragg.working_dir
            self.o_norm = o_bragg.o_norm
            self.working_dir = self.retrieve_working_dir()
            self.o_bragg = o_bragg
            show_selection_tab = True
            enabled_export_button = False
            self.index_array = np.arange(len(self.o_norm.data['sample']['file_name']))
        else:
            self.working_dir = working_dir
            show_selection_tab = False
            enabled_export_button = False

        if spectra_file:
            self.spectra_file = spectra_file

        display(HTML('<span style="font-size: 20px; color:blue">Check UI that poped up \
            (maybe hidden behind this browser!)</span>'))

        super(Interface, self).__init__(parent)
        ui_full_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
                                    os.path.join('ui',
                                                 'ui_bragg_edge_peak_fitting.ui'))

        self.ui = load_ui(ui_full_path, baseinstance=self)
        self.setWindowTitle("Peak Fitting Tool")

        if show_selection_tab:
            # initialization
            o_init = Initialization(parent=self)
            o_init.display(image=self.get_live_image())
            self.load_time_spectra()
            self.roi_moved()
        else:
            o_init = Initialization(parent=self, tab='2')
            self.disable_left_part_of_selection_tab()
            self.ui.tabWidget.setEnabled(False)

        self.ui.tabWidget.setTabEnabled(1, False)
        # self.ui.tabWidget.setCurrentIndex(default_tab)
        self.ui.actionExport.setEnabled(enabled_export_button)

        o_selection = BraggEdgeSelectionTab(parent=self)
        o_selection.update_selection_roi_slider_changed()
Example #6
0
 def update_roi_defined_by_profile_of_bin_size_slider(self):
     o_selection = BraggEdgeSelectionTab(parent=self)
     o_selection.update_roi_defined_by_profile_of_bin_size_slider()
Example #7
0
 def profile_of_bin_size_slider_changed(self, new_value):
     o_selection = BraggEdgeSelectionTab(parent=self)
     o_selection.profile_of_bin_size_slider_changed(new_value=new_value)
Example #8
0
 def selection_axis_changed(self):
     o_selection = BraggEdgeSelectionTab(parent=self)
     o_selection.update_selection_profile_plot()
Example #9
0
 def detector_offset_changed(self):
     self.update_time_spectra()
     o_selection = BraggEdgeSelectionTab(parent=self)
     o_selection.update_selection_profile_plot()
Example #10
0
 def distance_detector_sample_changed(self):
     self.update_time_spectra()
     o_selection = BraggEdgeSelectionTab(parent=self)
     o_selection.update_selection_profile_plot()
Example #11
0
 def roi_moved(self):
     o_selection = BraggEdgeSelectionTab(parent=self)
     o_selection.update_selection_profile_plot()
     o_selection.update_all_size_widgets_infos()
     o_selection.update_roi_defined_by_profile_of_bin_size_slider()
Example #12
0
    def run(self):
        working_dir = str(Path(self.parent.working_dir).parent)
        ascii_file = QFileDialog.getOpenFileName(self.parent,
                                                 caption="Select ASCII file",
                                                 directory=working_dir,
                                                 filter="ASCII (*.txt)")

        if ascii_file[0]:

            self.parent.full_reset_of_ui()
            self.parent.block_table_ui(True)
            self.parent.is_file_imported = True
            result_of_import = read_bragg_edge_fitting_ascii_format(
                full_file_name=str(ascii_file[0]))
            self.save_initial_roi_dimension_from_config_file(
                result_of_import['metadata']['columns']['3'])
            self.save_march_dollase_parameters(result_of_import['metadata'])
            self.parent.bragg_edge_range = result_of_import['metadata'][
                'bragg_edge_range']
            self.parent.bragg_peak_selection_range = result_of_import[
                'metadata']['bragg_peak_selection_range']

            self.update_selection_tab(result_of_import=result_of_import)
            self.update_interface(result_of_import=result_of_import)

            self.parent.ui.statusbar.showMessage(
                "{} has been imported!".format(ascii_file[0]), 10000)  # 10s
            self.parent.ui.statusbar.setStyleSheet("color: green")

            o_selection = BraggEdgeSelectionTab(parent=self.parent)
            o_selection.update_profile_of_bin_slider_widget()
            o_selection.update_selection_plot()

            self.parent.ui.tabWidget.setTabEnabled(
                1, self.parent.is_fit_infos_loaded())
            self.parent.ui.tabWidget.setEnabled(True)
            self.parent.ui.actionExport.setEnabled(True)

            self.parent.fitting_procedure_started[
                'kropff'] = result_of_import.get('metadata').get(
                    'kropff fitting '
                    'procedure '
                    'started', False)
            self.parent.fitting_procedure_started[
                'march-dollase'] = result_of_import.get('metadata').get(
                    'march-dollase fitting procedure started', False)

            o_kropff = Kropff(parent=self.parent)
            o_kropff.reset_all_table()

            o_march = MarchDollase(parent=self.parent)
            o_march.reset_table()

            if result_of_import.get('metadata').get(
                    'kropff fitting procedure started', False):
                # fill tables with minimum contains
                o_kropff.fill_table_with_fitting_information()

            if result_of_import.get('metadata').get(
                    'march-dollase fitting procedure started', False):
                # fill tables with minimum contains
                o_march.fill_tables_with_fitting_information()
            o_march.fill_history_table_with_fitting_information()

            self.parent.select_first_row_of_all_fitting_table()

            # self.parent.initialize_default_peak_regions()

            self.parent.block_table_ui(False)
            self.parent.update_vertical_line_in_profile_plot()
            self.parent.update_fitting_plot()
            self.parent.kropff_fitting_range_changed()

            o_gui = GuiUtility(parent=self.parent)
            o_gui.check_status_of_kropff_fitting_buttons()