예제 #1
0
    def kropff_fitting_range_changed(self):
        [global_left_range, global_right_range] = self.bragg_edge_range

        if not self.fitting_peak_ui:
            return

        [left_range, right_range] = list(self.fitting_peak_ui.getRegion())
        xaxis_dict = self.fitting_input_dictionary['xaxis']
        o_get = Get(parent=self)
        x_axis_selected = o_get.x_axis_checked()
        xaxis_index, _ = xaxis_dict[x_axis_selected]

        [left_xaxis_index, right_xaxis_index] = self.bragg_edge_range
        xaxis = xaxis_index[left_xaxis_index: right_xaxis_index]

        left_index = find_nearest_index(array=xaxis, value=left_range)
        right_index = find_nearest_index(array=xaxis, value=right_range)

        global_left_index = find_nearest_index(array=xaxis, value=global_left_range)
        global_right_index = find_nearest_index(array=xaxis, value=global_right_range)

        self.kropff_fitting_range['high'] = [right_index, global_right_index]
        self.kropff_fitting_range['low'] = [global_left_index, left_index]
        self.kropff_fitting_range['bragg_peak'] = [left_index, right_index]
        self.bragg_peak_selection_range = [left_index, right_index]

        o_kropff = Kropff(parent=self)
        o_kropff.update_roi_labels()
예제 #2
0
	def update_roi_labels(self):
		[global_left_range, global_right_range] = self.parent.bragg_edge_range
		[left_range, right_range] = list(self.parent.fitting_peak_ui.getRegion())

		o_get = Get(parent=self.parent)
		x_axis_selected = o_get.x_axis_checked()
		xaxis_dict = self.parent.fitting_input_dictionary['xaxis']
		xaxis_index, _ = xaxis_dict[x_axis_selected]
		[left_xaxis_index, right_xaxis_index] = [global_left_range, global_right_range]

		xaxis = xaxis_index[left_xaxis_index: right_xaxis_index]

		left_index = find_nearest_index(array=xaxis, value=left_range)
		right_index = find_nearest_index(array=xaxis, value=right_range)

		xaxis_in_selected_axis = self.parent.fitting_input_dictionary['xaxis'][x_axis_selected][0][
		                         global_left_range: global_right_range]
		real_left_value = xaxis_in_selected_axis[left_index]
		real_right_value = xaxis_in_selected_axis[right_index]
		if x_axis_selected == 'lambda':
			str_format = "{:02f}"
		elif x_axis_selected == 'tof':
			str_format = "{:04.2f}"
		else:
			str_format = "{}"
		real_left_value = str_format.format(real_left_value)
		real_right_value = str_format.format(real_right_value)

		units = Get.units(name=x_axis_selected)
		self.parent.ui.bragg_peak_range_from_value.setText(str(real_left_value))
		self.parent.ui.bragg_peak_range_to_value.setText(str(real_right_value))
		self.parent.ui.from_bragg_peak_range_units.setText(units)
		self.parent.ui.to_bragg_peak_range_units.setText(units)
예제 #3
0
    def update_fitting_plot(self):
        self.parent.ui.fitting.clear()
        if self.parent.fitting_peak_ui:
            self.parent.ui.fitting.removeItem(self.parent.fitting_peak_ui)

        o_get = Get(parent=self.parent)
        xaxis_checked = o_get.x_axis_checked()
        xaxis = o_get.x_axis_data(x_axis_selected=xaxis_checked)
        xaxis_label = o_get.x_axis_label(x_axis_selected=xaxis_checked)

        o_table = TableHandler(
            table_ui=self.parent.ui.march_dollase_result_table)
        list_row_selected = o_table.get_rows_of_table_selected()

        if list_row_selected is None:
            return

        for row_selected in list_row_selected:
            yaxis = o_get.y_axis_data_of_selected_row(
                row_selected=row_selected)
            self.parent.ui.fitting.plot(xaxis,
                                        yaxis,
                                        pen=(self.parent.selection_roi_rgb[0],
                                             self.parent.selection_roi_rgb[1],
                                             self.parent.selection_roi_rgb[2]),
                                        symbol='o')
            self.parent.ui.fitting.setLabel("bottom", xaxis_label)
            self.parent.ui.fitting.setLabel("left", "Average transmission")

        if self.parent.ui.march_dollase_toolBox.currentIndex() == 0:
            move_bragg_peak_range = True
        else:
            move_bragg_peak_range = False

        peak_range = self.parent.march_dollase_fitting_range_selected
        local_peak_range = [xaxis[peak_range[0]], xaxis[peak_range[1]]]

        if self.parent.march_dollase_fitting_peak_ui:
            self.parent.ui.fitting.removeItem(
                self.parent.march_dollase_fitting_peak_ui)
        self.parent.march_dollase_fitting_peak_ui = pg.LinearRegionItem(
            values=local_peak_range,
            orientation=None,
            brush=None,
            movable=move_bragg_peak_range,
            bounds=None)
        self.parent.march_dollase_fitting_peak_ui.sigRegionChanged.connect(
            self.parent.march_dollase_fitting_range_changed)
        self.parent.march_dollase_fitting_peak_ui.setZValue(-10)
        self.parent.ui.fitting.addItem(
            self.parent.march_dollase_fitting_peak_ui)
예제 #4
0
	def update_fitting_plot(self):
		self.parent.ui.fitting.clear()
		o_get = Get(parent=self.parent)
		part_of_fitting_dict = o_get.part_of_fitting_selected()
		name_of_page = part_of_fitting_dict['name_of_page']
		table_ui = part_of_fitting_dict['table_ui']

		o_table = TableHandler(table_ui=table_ui)
		list_row_selected = o_table.get_rows_of_table_selected()
		x_axis_selected = o_get.x_axis_checked()

		if list_row_selected is None:
			# first fitting tab where we only display the full data with bragg peak selection
			if self.parent.fitting_peak_ui:
				self.parent.ui.fitting.removeItem(self.parent.fitting_peak_ui)
			xaxis_dict = self.parent.fitting_input_dictionary['xaxis']
			xaxis_index, xaxis_label = xaxis_dict[x_axis_selected]
			[left_xaxis_index, right_xaxis_index] = self.parent.bragg_edge_range
			xaxis = xaxis_index[left_xaxis_index: right_xaxis_index]
			selected_roi = self.parent.fitting_input_dictionary['rois'][0]
			yaxis = selected_roi['profile']
			yaxis = yaxis[left_xaxis_index: right_xaxis_index]
			yaxis = -np.log(yaxis)
			self.parent.ui.fitting.plot(xaxis, yaxis,
			                            pen=(self.parent.selection_roi_rgb[0],
			                                 self.parent.selection_roi_rgb[1],
			                                 self.parent.selection_roi_rgb[2]),
			                            symbol='o')
			self.parent.ui.fitting.setLabel("bottom", xaxis_label)
			peak_range_index = self.parent.kropff_fitting_range['bragg_peak']
			if peak_range_index[0] is None:
				peak_range = self.parent.bragg_edge_range
			else:
				peak_range = [xaxis[peak_range_index[0]], xaxis[peak_range_index[1]]]

			if self.parent.fitting_peak_ui:
				self.parent.ui.fitting.removeItem(self.parent.fitting_peak_ui)
			self.parent.fitting_peak_ui = pg.LinearRegionItem(values=peak_range,
					                                          orientation=None,
					                                          brush=None,
					                                          movable=True,
					                                          bounds=None)
			self.parent.fitting_peak_ui.sigRegionChanged.connect(self.parent.fitting_range_changed)
			self.parent.fitting_peak_ui.setZValue(-10)
			self.parent.ui.fitting.addItem(self.parent.fitting_peak_ui)

		else:

			for row_selected in list_row_selected:

				selected_roi = self.parent.fitting_input_dictionary['rois'][row_selected]

				xaxis_dict = self.parent.fitting_input_dictionary['xaxis']
				[left_xaxis_index, right_xaxis_index] = self.parent.bragg_edge_range

				yaxis = selected_roi['profile']
				xaxis_index, xaxis_label = xaxis_dict[x_axis_selected]

				xaxis = xaxis_index[left_xaxis_index: right_xaxis_index]
				yaxis = yaxis[left_xaxis_index: right_xaxis_index]

				self.parent.ui.fitting.setLabel("bottom", xaxis_label)
				self.parent.ui.fitting.setLabel("left", 'Cross Section (arbitrary units)')
				yaxis = -np.log(yaxis)
				self.parent.ui.fitting.plot(xaxis, yaxis,
				                            pen=(self.parent.selection_roi_rgb[0],
				                                 self.parent.selection_roi_rgb[1],
				                                 self.parent.selection_roi_rgb[2]),
				                            symbol='o')

				peak_range_index = self.parent.kropff_fitting_range[name_of_page]
				if peak_range_index[0] is None:
					peak_range = self.parent.bragg_edge_range
				else:
					peak_range = [xaxis[peak_range_index[0]], xaxis[peak_range_index[1]]]

				if self.parent.fitting_peak_ui:
					self.parent.ui.fitting.removeItem(self.parent.fitting_peak_ui)
				self.parent.fitting_peak_ui = pg.LinearRegionItem(values=peak_range,
					                                              orientation=None,
					                                              brush=None,
					                                              movable=False,
					                                              bounds=None)
				self.parent.fitting_peak_ui.sigRegionChanged.connect(self.parent.fitting_range_changed)
				self.parent.fitting_peak_ui.setZValue(-10)
				self.parent.ui.fitting.addItem(self.parent.fitting_peak_ui)

				o_gui = GuiUtility(parent=self.parent)
				algo_name = o_gui.get_tab_selected(self.parent.ui.tab_algorithm).lower()

				if key_path_exists_in_dictionary(dictionary=self.parent.fitting_input_dictionary,
				                                 tree_key=['rois', row_selected, 'fitting', algo_name,
				                                           name_of_page, 'xaxis_to_fit']):

					# show fit only if tof scale selected
					if x_axis_selected == 'lambda':
						_entry = self.parent.fitting_input_dictionary['rois'][row_selected]['fitting'][algo_name][name_of_page]
						xaxis = _entry['xaxis_to_fit']
						yaxis = _entry['yaxis_fitted']
						yaxis = -np.log(yaxis)
						self.parent.ui.fitting.plot(xaxis, yaxis,
						                            pen=(self.parent.fit_rgb[0],
						                                 self.parent.fit_rgb[1],
						                                 self.parent.fit_rgb[2]))

				if peak_range_index[0] is None:
					self.parent.fitting_range_changed()

		self.parent.ui.fitting.setLabel("left", "Cross Section (arbitrary Units)")