Beispiel #1
0
    def run_calculation_intensity_power(self,
                                        srw_source,
                                        tickets,
                                        progress_bar_value=30):
        wf_parameters = WavefrontParameters(
            photon_energy_min=self.int_photon_energy_min,
            photon_energy_max=self.int_photon_energy_max,
            photon_energy_points=self.int_photon_energy_points,
            h_slit_gap=self.int_h_slit_gap,
            v_slit_gap=self.int_v_slit_gap,
            h_slit_points=self.int_h_slit_points,
            v_slit_points=self.int_v_slit_points,
            distance=self.int_distance,
            wavefront_precision_parameters=WavefrontPrecisionParameters(
                sr_method=0
                if self.int_sr_method == 0 else self.get_automatic_sr_method(),
                relative_precision=self.int_relative_precision,
                start_integration_longitudinal_position=self.
                int_start_integration_longitudinal_position,
                end_integration_longitudinal_position=self.
                int_end_integration_longitudinal_position,
                number_of_points_for_trajectory_calculation=self.
                int_number_of_points_for_trajectory_calculation,
                use_terminating_terms=self.int_use_terminating_terms,
                sampling_factor_for_adjusting_nx_ny=self.
                int_sampling_factor_for_adjusting_nx_ny))

        srw_wavefront = srw_source.get_SRW_Wavefront(
            source_wavefront_parameters=wf_parameters)

        e, h, v, i_se = srw_wavefront.get_intensity(multi_electron=False)

        tickets.append((i_se, e, h * 1e3, v * 1e3))

        e, h, v, i_me = srw_wavefront.get_intensity(multi_electron=True)

        tickets.append((i_me, e, h * 1e3, v * 1e3))

        if len(e) > 1: energy_step = e[1] - e[0]
        else: energy_step = 1.0

        import scipy.constants as codata
        pd = i_se.sum(axis=0) * energy_step * codata.e * 1e3

        self.calculated_total_power = SRWLightSource.get_total_power_from_power_density(
            h, v, pd)

        print("TOTAL POWER: ", self.calculated_total_power, " W")

        tickets.append(SRWPlot.get_ticket_2D(h, v, pd))

        self.progressBarSet(progress_bar_value + 10)
    def plot_2D(self, ticket, progressBarValue, var_x, var_y, plot_canvas_index, title, xtitle, ytitle, xum="", yum="", ignore_range=False):
        if self.plot_canvas[plot_canvas_index] is None:
            self.plot_canvas[plot_canvas_index] =  SRWPlot.Detailed2DWidget()
            self.tab[plot_canvas_index].layout().addWidget(self.plot_canvas[plot_canvas_index])

        if self.use_range == 1 and not ignore_range:
            plotting_range = [self.range_x_min/1000, self.range_x_max/1000, self.range_y_min/1000, self.range_y_max/1000]
        else:
            plotting_range = None

        self.plot_canvas[plot_canvas_index].plot_2D(ticket, var_x, var_y, title, xtitle, ytitle, xum=xum, yum=yum, plotting_range=plotting_range)

        self.progressBarSet(progressBarValue)
Beispiel #3
0
    def reset_accumulation(self):
        try:
            self.progressBarInit()

            self.accumulated_intensity = None

            self.plot_results([
                SRWPlot.get_ticket_2D(numpy.array(
                    [0, 0.001]), numpy.array([0, 0.001]), numpy.zeros((2, 2)))
            ],
                              ignore_range=True)
            self.progressBarFinished()
        except:
            pass
    def run_calculation_for_plots(self, output_wavefront, tickets,
                                  progress_bar_value):
        if self.view_type == 2:
            e, h, v, i = output_wavefront.get_intensity(
                multi_electron=False,
                polarization_component_to_be_extracted=PolarizationComponent.
                LINEAR_HORIZONTAL)

            tickets.append(
                SRWPlot.get_ticket_2D(h * 1000, v * 1000, i[int(e.size / 2)]))

            self.progressBarSet(progress_bar_value)

            e, h, v, i = output_wavefront.get_intensity(
                multi_electron=False,
                polarization_component_to_be_extracted=PolarizationComponent.
                LINEAR_VERTICAL)

            tickets.append(
                SRWPlot.get_ticket_2D(h * 1000, v * 1000, i[int(e.size / 2)]))

            e, h, v, p = output_wavefront.get_phase(
                polarization_component_to_be_extracted=PolarizationComponent.
                LINEAR_HORIZONTAL)

            tickets.append(
                SRWPlot.get_ticket_2D(h * 1000, v * 1000, p[int(e.size / 2)]))

            self.progressBarSet(progress_bar_value + 10)

            e, h, v, p = output_wavefront.get_phase(
                polarization_component_to_be_extracted=PolarizationComponent.
                LINEAR_VERTICAL)

            tickets.append(
                SRWPlot.get_ticket_2D(h * 1000, v * 1000, p[int(e.size / 2)]))

        elif self.view_type == 1:
            e, h, v, i = output_wavefront.get_intensity(multi_electron=False)

            tickets.append(
                SRWPlot.get_ticket_2D(h * 1000, v * 1000, i[int(e.size / 2)]))

            self.progressBarSet(progress_bar_value)

            e, h, v, p = output_wavefront.get_phase()

            tickets.append(
                SRWPlot.get_ticket_2D(h * 1000, v * 1000, p[int(e.size / 2)]))

        self.progressBarSet(progress_bar_value + 10)
Beispiel #5
0
    def plot_intensity(self):
        try:
            self.progressBarInit()

            tickets = []

            x, y, intensity = native_util.load_intensity_file(
                self.intensity_file_name)

            tickets.append(SRWPlot.get_ticket_2D(x * 1000, y * 1000,
                                                 intensity))

            self.progressBarSet(50)

            self.plot_results(tickets, progressBarValue=50)

            self.last_tickets = tickets

            self.progressBarFinished()
        except Exception as e:
            QMessageBox.critical(self, "Error", str(e), QMessageBox.Ok)
Beispiel #6
0
    def run_calculation_flux(self, srw_source, tickets, progress_bar_value=50):
        wf_parameters = WavefrontParameters(
            photon_energy_min=self.spe_photon_energy_min,
            photon_energy_max=self.spe_photon_energy_max,
            photon_energy_points=self.spe_photon_energy_points,
            h_slit_gap=self.spe_h_slit_gap,
            v_slit_gap=self.spe_v_slit_gap,
            h_slit_points=self.spe_h_slit_points,
            v_slit_points=self.spe_v_slit_points,
            distance=self.spe_distance,
            wavefront_precision_parameters=WavefrontPrecisionParameters(
                sr_method=0
                if self.spe_sr_method == 0 else self.get_automatic_sr_method(),
                relative_precision=self.spe_relative_precision,
                start_integration_longitudinal_position=self.
                spe_start_integration_longitudinal_position,
                end_integration_longitudinal_position=self.
                spe_end_integration_longitudinal_position,
                number_of_points_for_trajectory_calculation=self.
                spe_number_of_points_for_trajectory_calculation,
                use_terminating_terms=self.spe_use_terminating_terms,
                sampling_factor_for_adjusting_nx_ny=self.
                spe_sampling_factor_for_adjusting_nx_ny))

        srw_wavefront = srw_source.get_SRW_Wavefront(
            source_wavefront_parameters=wf_parameters)

        if isinstance(self.received_light_source, SRWBendingMagnetLightSource):
            e, i = srw_wavefront.get_flux(
                multi_electron=True,
                polarization_component_to_be_extracted=self.
                spe_polarization_component_to_be_extracted)
        elif isinstance(self.received_light_source, SRWUndulatorLightSource):
            e, i = srw_source.get_undulator_flux(
                source_wavefront_parameters=wf_parameters,
                flux_precision_parameters=FluxPrecisionParameters(
                    initial_UR_harmonic=self.spe_initial_UR_harmonic,
                    final_UR_harmonic=self.spe_final_UR_harmonic,
                    longitudinal_integration_precision_parameter=self.
                    spe_longitudinal_integration_precision_parameter,
                    azimuthal_integration_precision_parameter=self.
                    spe_azimuthal_integration_precision_parameter,
                    calculation_type=1))

        tickets.append(SRWPlot.get_ticket_1D(e, i))

        wf_parameters = WavefrontParameters(
            photon_energy_min=self.spe_photon_energy_min,
            photon_energy_max=self.spe_photon_energy_max,
            photon_energy_points=self.spe_photon_energy_points,
            h_slit_gap=0.0,
            v_slit_gap=0.0,
            h_slit_points=1,
            v_slit_points=1,
            h_position=self.spe_on_axis_x,
            v_position=self.spe_on_axis_y,
            distance=self.spe_distance,
            wavefront_precision_parameters=WavefrontPrecisionParameters(
                sr_method=0
                if self.spe_sr_method == 0 else self.get_automatic_sr_method(),
                relative_precision=self.spe_relative_precision,
                start_integration_longitudinal_position=self.
                spe_start_integration_longitudinal_position,
                end_integration_longitudinal_position=self.
                spe_end_integration_longitudinal_position,
                number_of_points_for_trajectory_calculation=self.
                spe_number_of_points_for_trajectory_calculation,
                use_terminating_terms=self.spe_use_terminating_terms,
                sampling_factor_for_adjusting_nx_ny=self.
                spe_sampling_factor_for_adjusting_nx_ny))

        power = i * 1e3 * (e[1] - e[0]) * codata.e
        cumulated_power = numpy.cumsum(power)
        self.calculated_total_power = cumulated_power[-1]

        srw_wavefront = srw_source.get_SRW_Wavefront(
            source_wavefront_parameters=wf_parameters)

        e, i = srw_wavefront.get_flux(
            multi_electron=False,
            polarization_component_to_be_extracted=self.
            spe_polarization_component_to_be_extracted)

        tickets.append(SRWPlot.get_ticket_1D(e, i))

        tickets.append(SRWPlot.get_ticket_1D(e, power))

        tickets.append(SRWPlot.get_ticket_1D(e, cumulated_power))

        self.progressBarSet(progress_bar_value)
    def plot_2D(self,
                ticket,
                progressBarValue,
                var_x,
                var_y,
                plot_canvas_index,
                title,
                xtitle,
                ytitle,
                xum="",
                yum="",
                ignore_range=False):
        if self.plot_canvas[plot_canvas_index] is None:
            self.plot_canvas[plot_canvas_index] = Plot2D()
            self.tab[plot_canvas_index].layout().addWidget(
                self.plot_canvas[plot_canvas_index])

            self.plot_canvas[plot_canvas_index].resetZoom()
            self.plot_canvas[plot_canvas_index].setXAxisAutoScale(True)
            self.plot_canvas[plot_canvas_index].setYAxisAutoScale(True)
            self.plot_canvas[plot_canvas_index].setGraphGrid(False)
            self.plot_canvas[plot_canvas_index].setKeepDataAspectRatio(False)
            self.plot_canvas[plot_canvas_index].yAxisInvertedAction.setVisible(
                False)

            self.plot_canvas[plot_canvas_index].setXAxisLogarithmic(False)
            self.plot_canvas[plot_canvas_index].setYAxisLogarithmic(False)
            self.plot_canvas[plot_canvas_index].getMaskAction().setVisible(
                False)
            self.plot_canvas[plot_canvas_index].getRoiAction().setVisible(
                False)
            self.plot_canvas[plot_canvas_index].getColormapAction().setVisible(
                True)

        if self.use_range == 1 and not ignore_range:
            plotting_range = [
                self.range_x_min / 1000, self.range_x_max / 1000,
                self.range_y_min / 1000, self.range_y_max / 1000
            ]
        else:
            plotting_range = None

        factor1 = SRWPlot.get_factor(var_x)
        factor2 = SRWPlot.get_factor(var_y)

        if plotting_range == None:
            xx = ticket['bin_h']
            yy = ticket['bin_v']

            nbins_h = ticket['nbins_h']
            nbins_v = ticket['nbins_v']

            histogram = ticket['histogram']
        else:
            range_x = numpy.where(
                numpy.logical_and(ticket['bin_h'] >= plotting_range[0],
                                  ticket['bin_h'] <= plotting_range[1]))
            range_y = numpy.where(
                numpy.logical_and(ticket['bin_v'] >= plotting_range[2],
                                  ticket['bin_v'] <= plotting_range[3]))

            xx = ticket['bin_h'][range_x]
            yy = ticket['bin_v'][range_y]

            histogram = []
            for row in ticket['histogram'][range_x]:
                histogram.append(row[range_y])

            nbins_h = len(xx)
            nbins_v = len(yy)

        if len(xx) == 0 or len(yy) == 0:
            raise Exception("Nothing to plot in the given range")

        xmin, xmax = xx.min(), xx.max()
        ymin, ymax = yy.min(), yy.max()

        origin = (xmin * factor1, ymin * factor2)
        scale = (abs(
            (xmax - xmin) / nbins_h) * factor1, abs(
                (ymax - ymin) / nbins_v) * factor2)

        # PyMCA inverts axis!!!! histogram must be calculated reversed
        data_to_plot = []
        for y_index in range(0, nbins_v):
            x_values = []
            for x_index in range(0, nbins_h):
                x_values.append(histogram[x_index][y_index])

            data_to_plot.append(x_values)

        colormap = {
            "name": "temperature",
            "normalization": "linear",
            "autoscale": True,
            "vmin": 0,
            "vmax": 0,
            "colors": 256
        }

        self.plot_canvas[plot_canvas_index].addImage(numpy.array(data_to_plot),
                                                     legend="Power Density",
                                                     scale=scale,
                                                     origin=origin,
                                                     colormap=colormap,
                                                     replace=True)

        self.plot_canvas[plot_canvas_index].setActiveImage("Power Density")

        self.plot_canvas[plot_canvas_index].setGraphXLabel(xtitle)
        self.plot_canvas[plot_canvas_index].setGraphYLabel(ytitle)
        self.plot_canvas[plot_canvas_index].setGraphTitle(title)
    def replace_fig(self, wavefront, var, xrange, title, xtitle, ytitle, xum):
        if self.plot_canvas_intensity is None:
            if self.iterative_mode < 2:
                self.plot_canvas_intensity = SRWPlot.Detailed1DWidget(
                    y_scale_factor=1.14)
            else:
                if self.plot_type == 0:
                    self.plot_canvas_intensity = ScanHistoWidget()
                    self.plot_canvas_phase = ScanHistoWidget()
                elif self.plot_type == 1:
                    self.plot_canvas_intensity = Scan3DHistoWidget(
                        type=Scan3DHistoWidget.PlotType.LINES if self.
                        plot_type_3D ==
                        0 else Scan3DHistoWidget.PlotType.SURFACE)
                    self.plot_canvas_phase = Scan3DHistoWidget(
                        type=Scan3DHistoWidget.PlotType.LINES if self.
                        plot_type_3D ==
                        0 else Scan3DHistoWidget.PlotType.SURFACE)

                self.plot_canvas_stats = DoublePlotWidget(parent=None)
                self.image_box_stats.layout().addWidget(self.plot_canvas_stats)

            self.image_box.layout().addWidget(self.plot_canvas_intensity)
            self.image_box_2.layout().addWidget(self.plot_canvas_phase)

        if self.polarization_component_to_be_extracted == 0:
            polarization_component_to_be_extracted = PolarizationComponent.TOTAL
        elif self.polarization_component_to_be_extracted == 1:
            polarization_component_to_be_extracted = PolarizationComponent.LINEAR_HORIZONTAL
        elif self.polarization_component_to_be_extracted == 2:
            polarization_component_to_be_extracted = PolarizationComponent.LINEAR_VERTICAL

        if self.multi_electron == 0 and self.iterative_mode == 2:
            e, h, v, p = wavefront.get_phase(
                polarization_component_to_be_extracted=
                polarization_component_to_be_extracted)

            ticket2D_Phase = SRWPlot.get_ticket_2D(h, v, p[int(e.size / 2)])

            ticket_phase = {}
            if var == Column.X:
                ticket_phase["histogram"] = ticket2D_Phase[
                    "histogram"][:, int(e.size / 2)]
                ticket_phase["bins"] = ticket2D_Phase["bin_h"] * TO_UM
                ticket_phase["xrange"] = ticket2D_Phase["xrange"]
                ticket_phase["fwhm"] = ticket2D_Phase["fwhm_h"] * TO_UM
                ticket_phase["fwhm_coordinates"] = ticket2D_Phase[
                    "fwhm_coordinates_h"]
            elif var == Column.Y:
                ticket_phase["histogram"] = ticket2D_Phase["histogram"][
                    int(e.size / 2), :]
                ticket_phase["bins"] = ticket2D_Phase["bin_v"] * TO_UM
                ticket_phase["xrange"] = ticket2D_Phase["yrange"]
                ticket_phase["fwhm"] = ticket2D_Phase["fwhm_v"] * TO_UM
                ticket_phase["fwhm_coordinates"] = ticket2D_Phase[
                    "fwhm_coordinates_v"]

            ticket_phase["xrange"] = (ticket_phase["xrange"][0] * TO_UM,
                                      ticket_phase["xrange"][1] * TO_UM)

            if not ticket_phase["fwhm"] is None and not ticket_phase[
                    "fwhm"] == 0.0:
                ticket_phase["fwhm_coordinates"] = (
                    ticket_phase["fwhm_coordinates"][0] * TO_UM,
                    ticket_phase["fwhm_coordinates"][1] * TO_UM)

        e, h, v, i = wavefront.get_intensity(
            multi_electron=self.multi_electron == 1,
            polarization_component_to_be_extracted=
            polarization_component_to_be_extracted,
            type_of_dependence=TypeOfDependence.VS_XY)

        ticket2D_Intensity = SRWPlot.get_ticket_2D(h, v, i[int(e.size / 2)])

        ticket_intensity = {}
        if var == Column.X:
            ticket_intensity["histogram"] = ticket2D_Intensity["histogram_h"]
            ticket_intensity["bins"] = ticket2D_Intensity["bin_h"] * TO_UM
            ticket_intensity["xrange"] = ticket2D_Intensity["xrange"]
            ticket_intensity["fwhm"] = ticket2D_Intensity["fwhm_h"] * TO_UM
            ticket_intensity["fwhm_coordinates"] = ticket2D_Intensity[
                "fwhm_coordinates_h"]
        elif var == Column.Y:
            ticket_intensity["histogram"] = ticket2D_Intensity["histogram_v"]
            ticket_intensity["bins"] = ticket2D_Intensity["bin_v"] * TO_UM
            ticket_intensity["xrange"] = ticket2D_Intensity["yrange"]
            ticket_intensity["fwhm"] = ticket2D_Intensity["fwhm_v"] * TO_UM
            ticket_intensity["fwhm_coordinates"] = ticket2D_Intensity[
                "fwhm_coordinates_v"]

        ticket_intensity["xrange"] = (ticket_intensity["xrange"][0] * TO_UM,
                                      ticket_intensity["xrange"][1] * TO_UM)

        if not ticket_intensity["fwhm"] is None and not ticket_intensity[
                "fwhm"] == 0.0:
            ticket_intensity["fwhm_coordinates"] = (
                ticket_intensity["fwhm_coordinates"][0] * TO_UM,
                ticket_intensity["fwhm_coordinates"][1] * TO_UM)

        if self.iterative_mode == 0:
            self.last_ticket = None
            self.current_histo_data = None
            self.current_stats = None
            self.last_histo_data = None
            self.current_histo_data_phase = None
            self.last_histo_data_phase = None
            self.histo_index = -1

            self.plot_canvas_intensity.plot_1D(ticket_intensity,
                                               var,
                                               title,
                                               xtitle,
                                               ytitle,
                                               xum,
                                               xrange,
                                               use_default_factor=False)
        elif self.iterative_mode == 1:
            self.current_histo_data = None
            self.current_stats = None
            self.last_histo_data = None
            self.current_histo_data_phase = None
            self.last_histo_data_phase = None
            self.histo_index = -1

            ticket_intensity['histogram'] += self.last_ticket['histogram']

            self.plot_canvas_intensity.plot_1D(ticket_intensity,
                                               var,
                                               title,
                                               xtitle,
                                               ytitle,
                                               xum,
                                               xrange,
                                               use_default_factor=False)

            self.last_ticket = ticket_intensity
        else:
            if not wavefront.scanned_variable_data is None:
                self.last_ticket = None
                self.histo_index += 1

                um = wavefront.scanned_variable_data.get_scanned_variable_um()
                um = " " + um if um.strip() == "" else " [" + um + "]"

                if self.multi_electron == 0:
                    histo_data_phase = self.plot_canvas_phase.plot_histo(
                        ticket_phase,
                        col=var,
                        title="Phase [rad]",
                        xtitle=xtitle,
                        ytitle=ytitle,
                        histo_index=self.histo_index,
                        scan_variable_name=wavefront.scanned_variable_data.
                        get_scanned_variable_display_name() + um,
                        scan_variable_value=wavefront.scanned_variable_data.
                        get_scanned_variable_value(),
                        offset=0.0 if self.last_histo_data_phase is None else
                        self.last_histo_data_phase.offset,
                        xrange=xrange,
                        show_reference=False,
                        add_labels=self.add_labels == 1,
                        has_colormap=self.has_colormap == 1,
                        use_default_factor=False)

                histo_data = self.plot_canvas_intensity.plot_histo(
                    ticket_intensity,
                    col=var,
                    title=title,
                    xtitle=xtitle,
                    ytitle=ytitle,
                    histo_index=self.histo_index,
                    scan_variable_name=wavefront.scanned_variable_data.
                    get_scanned_variable_display_name() + um,
                    scan_variable_value=wavefront.scanned_variable_data.
                    get_scanned_variable_value(),
                    offset=0.0 if self.last_histo_data is None else
                    self.last_histo_data.offset,
                    xrange=xrange,
                    show_reference=False,
                    add_labels=self.add_labels == 1,
                    has_colormap=self.has_colormap == 1,
                    use_default_factor=False)

                scanned_variable_value = wavefront.scanned_variable_data.get_scanned_variable_value(
                )

                if isinstance(scanned_variable_value, str):
                    histo_data.scan_value = self.histo_index + 1
                else:
                    histo_data.scan_value = wavefront.scanned_variable_data.get_scanned_variable_value(
                    )

                if not histo_data.bins is None:
                    if self.current_histo_data is None:
                        self.current_histo_data = HistogramDataCollection(
                            histo_data)
                    else:
                        self.current_histo_data.add_histogram_data(histo_data)

                if self.multi_electron == 0:
                    if isinstance(scanned_variable_value, str):
                        histo_data_phase.scan_value = self.histo_index + 1
                    else:
                        histo_data_phase.scan_value = wavefront.scanned_variable_data.get_scanned_variable_value(
                        )

                    if not histo_data_phase.bins is None:
                        if self.current_histo_data_phase is None:
                            self.current_histo_data_phase = HistogramDataCollection(
                                histo_data_phase)
                        else:
                            self.current_histo_data_phase.add_histogram_data(
                                histo_data_phase)

                if self.current_stats is None:
                    self.current_stats = StatisticalDataCollection(histo_data)
                else:
                    self.current_stats.add_statistical_data(histo_data)

                self.last_histo_data = histo_data
                if self.multi_electron == 0:
                    self.last_histo_data_phase = histo_data_phase

                self.plot_canvas_stats.plotCurves(
                    self.current_stats.get_scan_values(),
                    self.current_stats.get_sigmas() if self.stats_to_plot == 0
                    else self.current_stats.get_fwhms(),
                    self.current_stats.get_relative_peak_intensities()
                    if self.stats_to_plot_2 == 0 else
                    self.current_stats.get_relative_integral_intensities(),
                    "Statistics",
                    wavefront.scanned_variable_data.
                    get_scanned_variable_display_name() + um, "Sigma " +
                    xum if self.stats_to_plot == 0 else "FWHM " + xum,
                    "Relative Peak Intensity" if self.stats_to_plot_2 == 0 else
                    "Relative Integral Intensity")
Beispiel #9
0
    def plot_histo(self,
                   ticket,
                   col=Column.X,
                   title="",
                   xtitle="",
                   ytitle="",
                   histo_index=0,
                   scan_variable_name="Variable",
                   scan_variable_value=0,
                   offset=0.0,
                   xrange=None,
                   show_reference=True,
                   add_labels=True,
                   has_colormap=True,
                   colormap=cm.rainbow,
                   use_default_factor=True):
        if use_default_factor:
            factor=SRWPlot.get_factor(col)
        else:
            factor=1.0

        if histo_index==0 and xrange is None:
            fwhm = ticket['fwhm']
            xrange = ticket['xrange']

            centroid = xrange[0] + (xrange[1] - xrange[0])*0.5

            if not fwhm is None:
                xrange = [centroid - 2*fwhm , centroid + 2*fwhm]

        if isinstance(ticket['histogram'].shape, list):
            histogram = ticket['histogram'][0]
        else:
            histogram = ticket['histogram']

        bins = ticket['bins']

        if not xrange is None:
            good = numpy.where((bins >= xrange[0]) & (bins <= xrange[1]))

            bins = bins[good]
            histogram = histogram[good]

        bins *= factor

        histogram_stats = histogram
        bins_stats = bins

        fwhm = ticket['fwhm']

        sigma = get_sigma(histogram_stats, bins_stats)
        fwhm = sigma*2.35 if fwhm is None else fwhm*factor

        peak_intensity = numpy.average(histogram_stats[numpy.where(histogram_stats>=numpy.max(histogram_stats)*0.85)])

        if histo_index==0 and show_reference:
            h_title = "Reference"
        else:
            h_title = scan_variable_name + ": " + str(scan_variable_value)

        color="#000000"

        import matplotlib
        matplotlib.rcParams['axes.formatter.useoffset']='False'

        if histo_index== 0:
            offset = int(peak_intensity*0.3)

        self.plot_canvas.addCurve(bins, histogram + offset*histo_index, h_title, symbol='', color=color, xlabel=xtitle, ylabel=ytitle, replace=False) #'+', '^', ','

        if add_labels: self.plot_canvas._backend.ax.text(xrange[0]*factor*1.05, offset*histo_index*1.05, h_title)

        if not xtitle is None: self.plot_canvas.setGraphXLabel(xtitle)
        if not ytitle is None: self.plot_canvas.setGraphYLabel(ytitle)
        if not title is None:  self.plot_canvas.setGraphTitle(title)

        for label in self.plot_canvas._backend.ax.yaxis.get_ticklabels():
            label.set_color('white')
            label.set_fontsize(1)

        self.plot_canvas.setActiveCurveColor(color="#00008B")

        self.plot_canvas.resetZoom()
        self.plot_canvas.replot()

        self.plot_canvas.setGraphXLimits(xrange[0]*factor, xrange[1]*factor)

        self.plot_canvas.setActiveCurve(h_title)

        self.plot_canvas.setDefaultPlotLines(True)
        self.plot_canvas.setDefaultPlotPoints(False)

        self.plot_canvas.getLegendsDockWidget().setFixedHeight(510)
        self.plot_canvas.getLegendsDockWidget().setVisible(True)

        self.plot_canvas.addDockWidget(Qt.RightDockWidgetArea, self.plot_canvas.getLegendsDockWidget())

        return HistogramData(histogram_stats, bins_stats, offset, xrange, fwhm, sigma, peak_intensity)
Beispiel #10
0
    def plot_histo(self,
                   ticket,
                   col=Column.X,
                   title="",
                   xtitle="",
                   ytitle="",
                   histo_index=0,
                   scan_variable_name="Variable",
                   scan_variable_value=0,
                   offset=0.0,
                   xrange=None,
                   show_reference=True,
                   add_labels=True,
                   has_colormap=True,
                   colormap=cm.rainbow,
                   use_default_factor=True):

        if use_default_factor:
            factor=SRWPlot.get_factor(col)
        else:
            factor=1.0

        if histo_index==0 and xrange is None:
            fwhm = ticket['fwhm']
            xrange = ticket['xrange']

            centroid = xrange[0] + (xrange[1] - xrange[0])*0.5

            if not fwhm is None:
                xrange = [centroid - 2*fwhm , centroid + 2*fwhm]

        if isinstance(ticket['histogram'].shape, list):
            histogram = ticket['histogram'][0]
        else:
            histogram = ticket['histogram']

        bins = ticket['bins']

        if not xrange is None:
            good = numpy.where((bins >= xrange[0]) & (bins <= xrange[1]))

            bins = bins[good]
            histogram = histogram[good]

        bins *= factor

        if histo_index==0:
            self.set_xrange(bins)
        elif self.xx.shape != bins.shape:
            histogram = numpy.interp(self.xx, bins, histogram)
            bins = self.xx.copy()

        histogram_stats = histogram
        bins_stats = bins

        fwhm = ticket['fwhm']

        sigma = get_sigma(histogram_stats, bins_stats)
        fwhm = sigma*2.35 if fwhm is None else fwhm*factor

        peak_intensity = numpy.average(histogram_stats[numpy.where(histogram_stats>=numpy.max(histogram_stats)*0.85)])

        rcParams['axes.formatter.useoffset']='False'

        self.set_labels(title=title, xlabel=xtitle, ylabel=scan_variable_name, zlabel=ytitle)

        self.add_histo(scan_variable_value, histogram, has_colormap, colormap, histo_index)

        return HistogramData(histogram_stats, bins_stats, 0.0, xrange, fwhm, sigma, peak_intensity)