def check_fields(self):
        if self.kind_of_profile_y < 2:
            self.dimension_y = congruence.checkStrictlyPositiveNumber(self.dimension_y, "Dimension Y")
            self.step_y = congruence.checkStrictlyPositiveNumber(self.step_y, "Step Y")
            if self.kind_of_profile_y == 0: self.power_law_exponent_beta_y = congruence.checkPositiveNumber(self.power_law_exponent_beta_y, "Beta Value Y")
            if self.kind_of_profile_y == 1: self.correlation_length_y = congruence.checkStrictlyPositiveNumber(self.correlation_length_y, "Correlation Length Y")
            self.rms_y = congruence.checkPositiveNumber(self.rms_y, "Rms Y")
            self.montecarlo_seed_y = congruence.checkPositiveNumber(self.montecarlo_seed_y, "Monte Carlo initial seed y")
        else:
            congruence.checkFile(self.heigth_profile_1D_file_name_y)
            self.conversion_factor_y_x = congruence.checkStrictlyPositiveNumber(self.conversion_factor_y_x, "Conversion from file to workspace units(Abscissa)")
            self.conversion_factor_y_y = congruence.checkStrictlyPositiveNumber(self.conversion_factor_y_y, "Conversion from file to workspace units (Height Profile Values)")
            if self.renormalize_y == 1:
                self.rms_y = congruence.checkPositiveNumber(self.rms_y, "Rms Y")

        if self.kind_of_profile_x < 2:
            self.dimension_x = congruence.checkStrictlyPositiveNumber(self.dimension_x, "Dimension X")
            self.step_x = congruence.checkStrictlyPositiveNumber(self.step_x, "Step X")
            if self.kind_of_profile_x == 0: self.power_law_exponent_beta_x = congruence.checkPositiveNumber(self.power_law_exponent_beta_x, "Beta Value X")
            if self.kind_of_profile_x == 1: self.correlation_length_x = congruence.checkStrictlyPositiveNumber(self.correlation_length_x, "Correlation Length X")
            self.rms_x = congruence.checkPositiveNumber(self.rms_x, "Rms X")
            self.montecarlo_seed_x = congruence.checkPositiveNumber(self.montecarlo_seed_x, "Monte Carlo initial seed X")
        else:
            congruence.checkFile(self.heigth_profile_1D_file_name_x)
            self.conversion_factor_x_x = congruence.checkStrictlyPositiveNumber(self.conversion_factor_x_x, "Conversion from file to workspace units(Abscissa)")
            self.conversion_factor_x_y = congruence.checkStrictlyPositiveNumber(self.conversion_factor_x_y, "Conversion from file to workspace units (Height Profile Values)")
            if self.renormalize_x == 1:
                self.rms_x = congruence.checkPositiveNumber(self.rms_x, "Rms X")

        congruence.checkDir(self.heigth_profile_file_name)
Beispiel #2
0
    def write_file(self):
        self.setStatusMessage("")

        try:
            if not self.input_data is None:
                congruence.checkDir(self.file_name)

                # note that this is valid for both 1D and 2D wavefronts because both implement
                # the save_h5_file method.

                srw_wavefront = self.input_data.get_srw_wavefront()
                save_wfr_2_hdf5(self.input_data.get_srw_wavefront(),
                                self.file_name,
                                subgroupname=self.data_path,
                                intensity=True,
                                phase=False,
                                overwrite=True)

                path, file_name = os.path.split(self.file_name)

                self.setStatusMessage("File Out: " + file_name)

            else:
                QMessageBox.critical(self, "Error",
                                     "Wavefront Data not present",
                                     QMessageBox.Ok)
        except Exception as exception:
            QMessageBox.critical(self, "Error", str(exception), QMessageBox.Ok)
Beispiel #3
0
    def generate_waviness_file(self, not_interactive_mode=False):
        if not self.zz is None and not self.yy is None and not self.xx is None:
            try:
                congruence.checkDir(self.waviness_file_name)

                sys.stdout = EmittingStream(textWritten=self.writeStdOut)

                ST.write_shadow_surface(self.zz.T,
                                        self.xx,
                                        self.yy,
                                        outFile=congruence.checkFileName(
                                            self.waviness_file_name))
                if not not_interactive_mode:
                    QMessageBox.information(
                        self, "QMessageBox.information()", "Waviness file " +
                        self.waviness_file_name + " written on disk",
                        QMessageBox.Ok)

                self.send(
                    "PreProcessor_Data",
                    ShadowPreProcessorData(
                        error_profile_data_file=self.waviness_file_name,
                        error_profile_x_dim=self.dimension_x,
                        error_profile_y_dim=self.dimension_y))
            except Exception as exception:
                QMessageBox.critical(self, "Error", exception.args[0],
                                     QMessageBox.Ok)
    def generate_heigth_profile_file(self, not_interactive_mode=False):
        if not self.zz is None and not self.yy is None and not self.xx is None:
            try:
                congruence.checkDir(self.heigth_profile_file_name)

                sys.stdout = EmittingStream(textWritten=self.writeStdOut)

                ST.write_shadow_surface(self.zz, self.xx, self.yy, outFile=congruence.checkFileName(self.heigth_profile_file_name))
                if not not_interactive_mode:
                    QMessageBox.information(self, "QMessageBox.information()",
                                            "Height Profile file " + self.heigth_profile_file_name + " written on disk",
                                            QMessageBox.Ok)
                if self.modify_y == 0:
                    dimension_y = self.si_to_user_units * (self.server.y[-1] - self.server.y[0])
                if self.modify_y == 1:
                    dimension_y = self.si_to_user_units * (self.server.y[-1] - self.server.y[0]) * self.scale_factor_y
                elif self.modify_y == 2:
                    dimension_y = self.new_length

                self.send("PreProcessor_Data", ShadowPreProcessorData(error_profile_data_file=self.heigth_profile_file_name,
                                                                      error_profile_x_dim=self.dimension_x,
                                                                      error_profile_y_dim=dimension_y))
            except Exception as exception:
                QMessageBox.critical(self, "Error",
                                     exception.args[0],
                                     QMessageBox.Ok)
Beispiel #5
0
 def checkFields(self):
     self.SYMBOL = ShadowPhysics.checkCompoundName(self.SYMBOL)
     self.DENSITY = congruence.checkStrictlyPositiveNumber(self.DENSITY, "Density")
     self.E_MIN  = congruence.checkPositiveNumber(self.E_MIN , "Minimum Energy")
     self.E_MAX  = congruence.checkStrictlyPositiveNumber(self.E_MAX , "Maximum Energy")
     self.E_STEP = congruence.checkStrictlyPositiveNumber(self.E_STEP, "Energy step")
     if self.E_MIN > self.E_MAX: raise Exception("Minimum Energy cannot be bigger than Maximum Energy")
     congruence.checkDir(self.SHADOW_FILE)
Beispiel #6
0
 def checkFields(self):
     self.SYMBOL = ShadowPhysics.checkCompoundName(self.SYMBOL)
     self.DENSITY = congruence.checkStrictlyPositiveNumber(self.DENSITY, "Density")
     self.E_MIN  = congruence.checkPositiveNumber(self.E_MIN , "Minimum Energy")
     self.E_MAX  = congruence.checkStrictlyPositiveNumber(self.E_MAX , "Maximum Energy")
     self.E_STEP = congruence.checkStrictlyPositiveNumber(self.E_STEP, "Energy step")
     congruence.checkLessOrEqualThan(self.E_MIN, self.E_MAX, "Minimum Energy", "Maximum Energy")
     congruence.checkDir(self.SHADOW_FILE)
    def check_fields(self):
        if self.modify_y == 1 or self.modify_y == 2:
            self.new_length = congruence.checkStrictlyPositiveNumber(
                self.new_length, "New Length")

        if self.renormalize_y == 1:
            self.rms_y = congruence.checkPositiveNumber(self.rms_y, "Rms Y")

        congruence.checkDir(self.heigth_profile_file_name)
    def check_fields(self):
        self.dimension_x = congruence.checkStrictlyPositiveNumber(self.dimension_x, "Dimension X")
        self.step_x = congruence.checkStrictlyPositiveNumber(self.step_x, "Step X")
        if self.step_x > self.dimension_x/2:
            raise Exception("Step Width should be smaller than or equal to Width/2")
        if self.modify_y == 1:
            self.scale_factor_y = congruence.checkStrictlyPositiveNumber(self.scale_factor_y, "Scale Factor")
        elif self.modify_y == 2:
            self.new_length = congruence.checkStrictlyPositiveNumber(self.new_length, "New Length")

        if self.renormalize_y == 1:
            self.rms_y = congruence.checkPositiveNumber(self.rms_y, "Rms Y")

        congruence.checkDir(self.heigth_profile_file_name)
Beispiel #9
0
    def check_fields(self):
        self.number_of_points_x = congruence.checkStrictlyPositiveNumber(self.number_of_points_x, "Number of Points X")
        self.number_of_points_y = congruence.checkStrictlyPositiveNumber(self.number_of_points_y, "Number of Points Y")

        self.dimension_x = congruence.checkStrictlyPositiveNumber(self.dimension_x, "Dimension X")
        self.dimension_y = congruence.checkStrictlyPositiveNumber(self.dimension_y, "Dimension Y")

        self.estimated_slope_error = congruence.checkPositiveNumber(self.estimated_slope_error, "Estimated slope error")
        self.montecarlo_seed = congruence.checkPositiveNumber(self.montecarlo_seed, "Monte Carlo initial seed")

        self.harmonic_maximum_index = congruence.checkPositiveNumber(self.harmonic_maximum_index,
                                                                    "Harmonic Maximum Index")

        congruence.checkDir(self.waviness_file_name)
Beispiel #10
0
    def replace_fig(self, beam, var_x, var_y,  title, xtitle, ytitle, xrange, yrange, nbins, nolost, xum, yum):
        if self.plot_canvas is None:
            self.plot_canvas = ShadowPlot.DetailedPlotWidget(y_scale_factor=1.14)
            self.image_box.layout().addWidget(self.plot_canvas)

        try:
            if self.autosave == 1:
                if self.autosave_file is None:
                    self.autosave_file = ShadowPlot.PlotXYHdf5File(congruence.checkDir(self.autosave_file_name))
                elif self.autosave_file.filename != congruence.checkFileName(self.autosave_file_name):
                    self.autosave_file.close()
                    self.autosave_file = ShadowPlot.PlotXYHdf5File(congruence.checkDir(self.autosave_file_name))

            if self.keep_result == 1:
                self.cumulated_ticket, last_ticket = self.plot_canvas.plot_xy(beam, var_x, var_y, title, xtitle, ytitle, xrange=xrange, yrange=yrange, nbins=nbins, nolost=nolost, xum=xum, yum=yum, conv=self.workspace_units_to_cm, ref=self.weight_column_index, ticket_to_add=self.cumulated_ticket)

                self.plotted_ticket = self.cumulated_ticket

                if self.autosave == 1:
                    self.autosave_prog_id += 1
                    self.autosave_file.write_coordinates(self.cumulated_ticket)
                    dataset_name = self.weight_column.itemText(self.weight_column_index)

                    self.autosave_file.add_plot_xy(self.cumulated_ticket, dataset_name=dataset_name)

                    if self.autosave_partial_results == 1:
                        if last_ticket is None:
                            self.autosave_file.add_plot_xy(self.cumulated_ticket, plot_name="Plot XY #" + str(self.autosave_prog_id), dataset_name=dataset_name)
                        else:
                            self.autosave_file.add_plot_xy(last_ticket, plot_name="Plot X #" + str(self.autosave_prog_id), dataset_name=dataset_name)

                    self.autosave_file.flush()
            else:
                ticket, _ = self.plot_canvas.plot_xy(beam, var_x, var_y, title, xtitle, ytitle, xrange=xrange, yrange=yrange, nbins=nbins, nolost=nolost, xum=xum, yum=yum, conv=self.workspace_units_to_cm, ref=self.weight_column_index)

                self.cumulated_ticket = None
                self.plotted_ticket = ticket

                if self.autosave == 1:
                    self.autosave_prog_id += 1
                    self.autosave_file.write_coordinates(ticket)
                    self.autosave_file.add_plot_xy(ticket, dataset_name=self.weight_column.itemText(self.weight_column_index))
                    self.autosave_file.flush()

        except Exception as e:
            if not self.IS_DEVELOP:
                raise Exception("Data not plottable: No good rays or bad content")
            else:
                raise e
Beispiel #11
0
    def checkFields(self):
        if type(self.DESCRIPTOR) == str: # back compatibility with old version
            try:
                self.DESCRIPTOR = self.crystals.index(self.DESCRIPTOR)
            except:
                self.DESCRIPTOR = 0

        self.H_MILLER_INDEX = congruence.checkNumber(self.H_MILLER_INDEX, "H miller index")
        self.K_MILLER_INDEX = congruence.checkNumber(self.K_MILLER_INDEX, "K miller index")
        self.L_MILLER_INDEX = congruence.checkNumber(self.L_MILLER_INDEX, "L miller index")
        self.TEMPERATURE_FACTOR = congruence.checkNumber(self.TEMPERATURE_FACTOR, "Temperature factor")
        self.E_MIN  = congruence.checkPositiveNumber(self.E_MIN , "Minimum energy")
        self.E_MAX  = congruence.checkStrictlyPositiveNumber(self.E_MAX , "Maximum Energy")
        self.E_STEP = congruence.checkStrictlyPositiveNumber(self.E_STEP, "Energy step")
        if self.E_MIN > self.E_MAX: raise Exception("From Energy cannot be bigger than To Energy")
        congruence.checkDir(self.SHADOW_FILE)
Beispiel #12
0
    def check_fields(self):
        self.dimension_y = congruence.checkStrictlyPositiveNumber(
            self.dimension_y, "Dimension")
        self.step_y = congruence.checkStrictlyPositiveNumber(
            self.step_y, "Step")
        if self.kind_of_profile_y == 0:
            self.power_law_exponent_beta_y = congruence.checkPositiveNumber(
                self.power_law_exponent_beta_y, "Beta Value")
        if self.kind_of_profile_y == 1:
            self.correlation_length_y = congruence.checkStrictlyPositiveNumber(
                self.correlation_length_y, "Correlation Length")
        self.rms_y = congruence.checkPositiveNumber(self.rms_y, "Rms")
        self.montecarlo_seed_y = congruence.checkPositiveNumber(
            self.montecarlo_seed_y, "Monte Carlo initial seed")

        congruence.checkDir(self.heigth_profile_file_name)
Beispiel #13
0
    def save_results(self):
        if not self.plotted_ticket is None:
            try:
                file_name, _ = QtWidgets.QFileDialog.getSaveFileName(
                    self,
                    "Save Current Plot",
                    filter="HDF5 Files (*.hdf5 *.h5 *.hdf)")

                if not file_name is None and not file_name.strip() == "":
                    if not (file_name.endswith("hd5")
                            or file_name.endswith("hdf5")
                            or file_name.endswith("hdf")):
                        file_name += ".hdf5"

                    save_file = ShadowPlot.HistogramHdf5File(
                        congruence.checkDir(file_name))

                    save_file.write_coordinates(self.plotted_ticket)
                    dataset_name = self.weight_column.itemText(
                        self.weight_column_index)

                    save_file.add_histogram(self.plotted_ticket,
                                            dataset_name=dataset_name)

                    save_file.close()
            except Exception as exception:
                QtWidgets.QMessageBox.critical(self, "Error", str(exception),
                                               QtWidgets.QMessageBox.Ok)

                if self.IS_DEVELOP: raise exception
Beispiel #14
0
    def selectPlotFile(self):
        file_name = oasysgui.selectFileFromDialog(self, None, "Select File", file_extension_filter="HDF5 Files (*.hdf5 *.h5 *.hdf)")

        if not file_name is None:
            self.le_loaded_plot_file_name.setText(os.path.basename(os.path.normpath(file_name)))

            plot_file = ShadowPlot.PlotXYHdf5File(congruence.checkDir(file_name), mode="r")

            ticket = {}

            ticket["histogram"], ticket["histogram_h"], ticket["histogram_v"], attributes = plot_file.get_last_plot(dataset_name="power_density")
            ticket["bin_h_center"], ticket["bin_v_center"], ticket["h_label"], ticket["v_label"] = plot_file.get_coordinates()
            ticket["intensity"] = attributes["intensity"]
            ticket["nrays"]     = attributes["total_rays"]
            ticket["good_rays"] = attributes["good_rays"]

            if self.plot_canvas is None:
                self.plot_canvas = PowerPlotXYWidget()
                self.image_box.layout().addWidget(self.plot_canvas)
            else:
                if not self.plotted_ticket is None:
                    if QMessageBox.question(self, "Load Plot", "Merge with current Plot?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No) == QMessageBox.Yes:
                        if ticket["histogram"].shape == self.plotted_ticket["histogram"].shape and \
                           ticket["bin_h_center"].shape == self.plotted_ticket["bin_h_center"].shape and \
                           ticket["bin_v_center"].shape == self.plotted_ticket["bin_v_center"].shape and \
                           ticket["bin_h_center"][0] == self.plotted_ticket["bin_h_center"][0] and \
                           ticket["bin_h_center"][-1] == self.plotted_ticket["bin_h_center"][-1] and \
                           ticket["bin_v_center"][0] == self.plotted_ticket["bin_v_center"][0] and \
                           ticket["bin_v_center"][-1] == self.plotted_ticket["bin_v_center"][-1]:
                            ticket["histogram"] += self.plotted_ticket["histogram"]

                            if  QMessageBox.question(self, "Load Plot", "Average with current Plot?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No) == QMessageBox.Yes:
                                ticket["histogram"] *= 0.5
                        else:
                            raise ValueError("The plots cannot be merged: the should have same dimensions and ranges")

            cumulated_power_plot = numpy.sum(ticket["histogram"])*(ticket["bin_h_center"][1]-ticket["bin_h_center"][0])*(ticket["bin_v_center"][1]-ticket["bin_v_center"][0])

            try:
                energy_min=0.0
                energy_max=0.0
                energy_step=0.0

                self.plot_canvas.cumulated_power_plot = cumulated_power_plot
                self.plot_canvas.plot_power_density_ticket(ticket,
                                                           ticket["h_label"],
                                                           ticket["v_label"],
                                                           cumulated_total_power=0.0,
                                                           energy_min=energy_min,
                                                           energy_max=energy_max,
                                                           energy_step=energy_step)

                self.cumulated_ticket = None
                self.plotted_ticket = ticket
                self.plotted_ticket_original = ticket.copy()
            except Exception as e:
                QMessageBox.critical(self, "Error", str(e), QMessageBox.Ok)

                if self.IS_DEVELOP: raise e
Beispiel #15
0
    def checkFields(self):
        congruence.checkDir(self.FILE)
        self.E_MIN = congruence.checkPositiveNumber(self.E_MIN, "Min Energy")
        self.E_MAX = congruence.checkStrictlyPositiveNumber(
            self.E_MAX, "Max Energy")
        congruence.checkLessOrEqualThan(self.E_MIN, self.E_MAX,
                                        "Minimum Energy", "Maximum Energy")
        self.S_MATERIAL = ShadowPhysics.checkCompoundName(self.S_MATERIAL)
        self.S_DENSITY = congruence.checkStrictlyPositiveNumber(
            float(self.S_DENSITY), "Density (substrate)")
        self.E_MATERIAL = ShadowPhysics.checkCompoundName(self.E_MATERIAL)
        self.E_DENSITY = congruence.checkStrictlyPositiveNumber(
            float(self.E_DENSITY), "Density (even sublayer)")
        self.O_MATERIAL = ShadowPhysics.checkCompoundName(self.O_MATERIAL)
        self.O_DENSITY = congruence.checkStrictlyPositiveNumber(
            float(self.O_DENSITY), "Density (odd sublayer)")

        if self.GRADE_DEPTH == 0:
            self.N_PAIRS = congruence.checkStrictlyPositiveNumber(
                int(self.N_PAIRS), "Number of bilayers")
            self.THICKNESS = congruence.checkStrictlyPositiveNumber(
                float(self.THICKNESS), "bilayer thickness t")
            self.GAMMA = congruence.checkStrictlyPositiveNumber(
                float(self.GAMMA), "gamma ratio")
            self.ROUGHNESS_EVEN = congruence.checkPositiveNumber(
                float(self.ROUGHNESS_EVEN), "Roughness even layer")
            self.ROUGHNESS_ODD = congruence.checkPositiveNumber(
                float(self.ROUGHNESS_ODD), "Roughness odd layer")
        else:
            congruence.checkDir(self.FILE_DEPTH)

        if self.GRADE_SURFACE == 1:
            congruence.checkDir(self.FILE_SHADOW)
            congruence.checkDir(self.FILE_THICKNESS)
            congruence.checkDir(self.FILE_GAMMA)
        elif self.GRADE_SURFACE == 2:
            self.AA0 = congruence.checkNumber(float(self.AA0),
                                              "zero-order coefficient")
            self.AA1 = congruence.checkNumber(float(self.AA1),
                                              "linear coefficient")
            self.AA2 = congruence.checkNumber(float(self.AA2),
                                              "2nd degree coefficient")
            self.AA3 = congruence.checkNumber(float(self.AA3),
                                              "3rd degree coefficient")
Beispiel #16
0
    def generate_waviness_file(self, not_interactive_mode=False):
        if not self.zz is None and not self.yy is None and not self.xx is None:
            try:
                congruence.checkDir(self.waviness_file_name)

                sys.stdout = EmittingStream(textWritten=self.writeStdOut)

                ST.write_shadow_surface(self.zz.T, self.xx, self.yy, outFile=congruence.checkFileName(self.waviness_file_name))
                if not not_interactive_mode:
                    QMessageBox.information(self, "QMessageBox.information()",
                                            "Waviness file " + self.waviness_file_name + " written on disk",
                                            QMessageBox.Ok)

                self.send("PreProcessor_Data", ShadowPreProcessorData(error_profile_data_file=self.waviness_file_name,
                                                                      error_profile_x_dim=self.dimension_x,
                                                                      error_profile_y_dim=self.dimension_y))
            except Exception as exception:
                QMessageBox.critical(self, "Error",
                                     exception.args[0],
                                     QMessageBox.Ok)
Beispiel #17
0
    def check_fields(self):
        self.number_of_points_x = congruence.checkStrictlyPositiveNumber(
            self.number_of_points_x, "Number of Points X")
        self.number_of_points_y = congruence.checkStrictlyPositiveNumber(
            self.number_of_points_y, "Number of Points Y")

        self.dimension_x = congruence.checkStrictlyPositiveNumber(
            self.dimension_x, "Dimension X")
        self.dimension_y = congruence.checkStrictlyPositiveNumber(
            self.dimension_y, "Dimension Y")

        self.estimated_slope_error = congruence.checkPositiveNumber(
            self.estimated_slope_error, "Estimated slope error")
        self.montecarlo_seed = congruence.checkPositiveNumber(
            self.montecarlo_seed, "Monte Carlo initial seed")

        self.harmonic_maximum_index = congruence.checkPositiveNumber(
            self.harmonic_maximum_index, "Harmonic Maximum Index")

        congruence.checkDir(self.waviness_file_name)
Beispiel #18
0
    def load_file(self):
        try:
            hdf5_file_name = congruence.checkDir(self.hdf5_file_name)

            self.tree_view.load_file(hdf5_file_name)
            self.tree_view.set_text("Loaded File: " + hdf5_file_name)

        except Exception as exception:
            QMessageBox.critical(self, "Error", exception.args[0],
                                 QMessageBox.Ok)

            if self.IS_DEVELOP: raise exception
    def interp_save(self, not_interactive_mode=False):
        try:
            congruence.checkDir(self.save_height_profile_file_name)

            sys.stdout = EmittingStream(textWritten=self.writeStdOut)

            congruence.checkFileName(self.save_height_profile_file_name)

            self.write_error_profile_file()

            if not not_interactive_mode:
                QMessageBox.information(
                    self, "QMessageBox.information()", "Height Profile file " +
                    self.save_height_profile_file_name + " written on disk",
                    QMessageBox.Ok)

        except Exception as exception:
            QMessageBox.critical(self, "Error", exception.args[0],
                                 QMessageBox.Ok)

            if self.IS_DEVELOP: raise exception
    def generate_heigth_profile_file(self, not_interactive_mode=False):
        if not self.yy is None and not self.xx is None:
            try:
                congruence.checkDir(self.heigth_profile_file_name)

                sys.stdout = EmittingStream(textWritten=self.writeStdOut)
                numpy.savetxt(self.heigth_profile_file_name, self.yy)

                QMessageBox.information(
                    self, "QMessageBox.information()", "Height Profile file " +
                    self.heigth_profile_file_name + " written on disk",
                    QMessageBox.Ok)

                self.send(
                    "PreInput",
                    WiserPreInputData(
                        figure_error_file=self.heigth_profile_file_name,
                        figure_error_step=numpy.abs(self.xx[1] - self.xx[0]),
                        figure_user_units_to_m=self.workspace_units_to_m))
            except Exception as exception:
                QMessageBox.critical(self, "Error", exception.args[0],
                                     QMessageBox.Ok)
    def save_cumulated_data_hdf5(self, file_name):
        if not self.plotted_ticket is None:
            try:
                save_file = ShadowPlot.PlotXYHdf5File(congruence.checkDir(os.path.splitext(file_name)[0] + ".hdf5"))

                save_file.write_coordinates(self.plotted_ticket)
                save_file.add_plot_xy(self.plotted_ticket, dataset_name="power_density")

                save_file.close()
            except Exception as exception:
                QMessageBox.critical(self, "Error", str(exception), QMessageBox.Ok)

                if self.IS_DEVELOP: raise exception
Beispiel #22
0
    def checkFields(self):
        if type(self.DESCRIPTOR) == str:  # back compatibility with old version
            try:
                self.DESCRIPTOR = self.crystals.index(self.DESCRIPTOR)
            except:
                self.DESCRIPTOR = 0

        self.H_MILLER_INDEX = congruence.checkNumber(self.H_MILLER_INDEX,
                                                     "H miller index")
        self.K_MILLER_INDEX = congruence.checkNumber(self.K_MILLER_INDEX,
                                                     "K miller index")
        self.L_MILLER_INDEX = congruence.checkNumber(self.L_MILLER_INDEX,
                                                     "L miller index")
        self.TEMPERATURE_FACTOR = congruence.checkNumber(
            self.TEMPERATURE_FACTOR, "Temperature factor")
        self.E_MIN = congruence.checkPositiveNumber(self.E_MIN,
                                                    "Minimum energy")
        self.E_MAX = congruence.checkStrictlyPositiveNumber(
            self.E_MAX, "Maximum Energy")
        self.E_STEP = congruence.checkStrictlyPositiveNumber(
            self.E_STEP, "Energy step")
        congruence.checkLessOrEqualThan(self.E_MIN, self.E_MAX, "From Energy",
                                        "To Energy")
        congruence.checkDir(self.SHADOW_FILE)
Beispiel #23
0
    def read_data_files(self):
        self.data = []

        for surface_file_name in self.surface_file_names:
            surface_file_name = congruence.checkDir(surface_file_name)

            data = numpy.loadtxt(surface_file_name, delimiter="," if self.separator==0 else " ", skiprows=self.skip_rows)

            xx = numpy.unique(data[:, 0]) * self.conversion_to_m_xy
            yy = numpy.unique(data[:, 1]) * self.conversion_to_m_xy
            zz = numpy.reshape(data[:, 2], (len(xx), len(yy))).T

            zz = zz * self.conversion_to_m_z if self.negate == 0 else -1.0 * zz * self.conversion_to_m_z

            self.data.append([xx, yy, zz])

        self.initialize_figures()
Beispiel #24
0
    def render_surface(self):
        try:
            self.surface_file_name = congruence.checkDir(
                self.surface_file_name)

            #### LENGTH

            xx, yy, zz = OU.read_surface_file(self.surface_file_name)

            self.xx = xx
            self.yy = yy
            self.zz = zz

            self.axis.clear()

            x_to_plot, y_to_plot = numpy.meshgrid(self.xx, self.yy)

            self.axis.plot_surface(x_to_plot,
                                   y_to_plot,
                                   zz,
                                   rstride=1,
                                   cstride=1,
                                   cmap=cm.autumn,
                                   linewidth=0.5,
                                   antialiased=True)

            self.axis.set_xlabel("X [m]")
            self.axis.set_ylabel("Y [m]")
            self.axis.set_zlabel("Z [m]")
            self.axis.mouse_init()

            self.figure_canvas.draw()

            self.send(
                "Surface Data",
                OasysSurfaceData(xx=self.xx,
                                 yy=self.yy,
                                 zz=self.zz,
                                 surface_data_file=self.surface_file_name))

        except Exception as exception:
            QMessageBox.critical(self, "Error", exception.args[0],
                                 QMessageBox.Ok)

            if self.IS_DEVELOP: raise exception
    def read_surface(self):
        try:
            self.surface_file_name = congruence.checkDir(
                self.surface_file_name)

            xx, yy, zz = OU.read_surface_file(self.surface_file_name)
            zz = zz if self.negate == 0 else -1.0 * zz

            self.xx = xx
            self.yy = yy
            self.zz = zz

            self.send(
                "Surface Data",
                OasysSurfaceData(xx=self.xx,
                                 yy=self.yy,
                                 zz=self.zz,
                                 surface_data_file=self.surface_file_name))
        except Exception as exception:
            QMessageBox.critical(self, "Error", exception.args[0],
                                 QMessageBox.Ok)

            if self.IS_DEVELOP: raise exception
    def replace_fig(self, shadow_beam, var_x, var_y, xrange, yrange, nbins, nolost):
        if self.plot_canvas is None:
            self.plot_canvas = PowerPlotXYWidget()
            self.image_box.layout().addWidget(self.plot_canvas)

        try:

            if self.autosave == 1:
                if self.autosave_file is None:
                    self.autosave_file = ShadowPlot.PlotXYHdf5File(congruence.checkDir(self.autosave_file_name))
                elif self.autosave_file.filename != congruence.checkFileName(self.autosave_file_name):
                    self.autosave_file.close()
                    self.autosave_file = ShadowPlot.PlotXYHdf5File(congruence.checkDir(self.autosave_file_name))

            if self.keep_result == 1:
                self.cumulated_ticket, last_ticket = self.plot_canvas.plot_power_density(shadow_beam, var_x, var_y,
                                                                                         self.total_power, self.cumulated_total_power,
                                                                                         self.energy_min, self.energy_max, self.energy_step,
                                                                                         nbins=nbins, xrange=xrange, yrange=yrange, nolost=nolost,
                                                                                         ticket_to_add=self.cumulated_ticket,
                                                                                         to_mm=self.workspace_units_to_mm,
                                                                                         show_image=self.view_type==1,
                                                                                         kind_of_calculation=self.kind_of_calculation,
                                                                                         replace_poor_statistic=self.replace_poor_statistic,
                                                                                         good_rays_limit=self.good_rays_limit,
                                                                                         center_x=self.center_x,
                                                                                         center_y=self.center_y,
                                                                                         sigma_x=self.sigma_x,
                                                                                         sigma_y=self.sigma_y,
                                                                                         gamma=self.gamma)
                self.plotted_ticket = self.cumulated_ticket
                self.plotted_ticket_original = self.plotted_ticket.copy()

                if self.autosave == 1:
                    self.autosave_file.write_coordinates(self.cumulated_ticket)
                    dataset_name = "power_density"

                    self.autosave_file.add_plot_xy(self.cumulated_ticket, dataset_name=dataset_name)

                    if self.autosave_partial_results == 1:
                        if last_ticket is None:
                            self.autosave_file.add_plot_xy(self.cumulated_ticket,
                                                           plot_name="Energy Range: " + str(round(self.energy_max-self.energy_step, 2)) + "-" + str(round(self.energy_max, 2)),
                                                           dataset_name=dataset_name)
                        else:
                            self.autosave_file.add_plot_xy(last_ticket,
                                                           plot_name="Energy Range: " + str(round(self.energy_max-self.energy_step, 2)) + "-" + str(round(self.energy_max, 2)),
                                                           dataset_name=dataset_name)

                    self.autosave_file.flush()
            else:
                ticket, _ = self.plot_canvas.plot_power_density(shadow_beam, var_x, var_y,
                                                                self.total_power, self.cumulated_total_power,
                                                                self.energy_min, self.energy_max, self.energy_step,
                                                                nbins=nbins, xrange=xrange, yrange=yrange, nolost=nolost,
                                                                to_mm=self.workspace_units_to_mm,
                                                                show_image=self.view_type==1,
                                                                kind_of_calculation=self.kind_of_calculation,
                                                                replace_poor_statistic=self.replace_poor_statistic,
                                                                good_rays_limit=self.good_rays_limit,
                                                                center_x=self.center_x,
                                                                center_y=self.center_y,
                                                                sigma_x=self.sigma_x,
                                                                sigma_y=self.sigma_y,
                                                                gamma=self.gamma)

                self.cumulated_ticket = None
                self.plotted_ticket = ticket
                self.plotted_ticket_original = self.plotted_ticket.copy()

                if self.autosave == 1:
                    self.autosave_file.write_coordinates(ticket)
                    self.autosave_file.add_plot_xy(ticket, dataset_name="power_density")
                    self.autosave_file.flush()

        except Exception as e:
            if not self.IS_DEVELOP:
                raise Exception("Data not plottable: No good rays or bad content")
            else:
                raise e
Beispiel #27
0
    def write_file(self):
        self.setStatusMessage("")

        try:
            if not self.af is None:
                congruence.checkDir(self.file_name)

                if self.TYPE_OF_OUTPUT == 0:  # ['COMSYL hdf5 with multi-mode','WOFRY hdf5 with multi-mode','WOFRY multiple files'
                    if self.ALL_MODES:
                        self.af.write_h5(self.file_name,
                                         maximum_number_of_modes=None)
                    else:
                        self.af.write_h5(self.file_name,
                                         maximum_number_of_modes=self.MODE_TO)
                        path, file_name = os.path.split(self.file_name)
                        self.setStatusMessage("File Out: " + file_name)
                else:  # WOFRY
                    if self.ALL_MODES == 0 and (self.MODE_TO <
                                                self.af.number_of_modes()):
                        nmax = self.MODE_TO
                    else:
                        nmax = self.af.number_of_modes()

                    for i in range(nmax + 1):
                        eigenvalue = numpy.real(self.af.eigenvalue(i), )
                        eigenfunction = self.af.mode(i)
                        w = GenericWavefront2D.initialize_wavefront_from_arrays(
                            self.af.x_coordinates(), self.af.y_coordinates(),
                            eigenfunction * numpy.sqrt(eigenvalue))
                        w.set_photon_energy(self.af.photon_energy())

                        if self.TYPE_OF_OUTPUT == 1:  #
                            file_name = self.file_name
                            subgroupname = "mode" + self.index_format % (i)
                            overwrite = False
                        elif self.TYPE_OF_OUTPUT == 2:
                            subgroupname = "mode" + self.index_format % (i)
                            file_name = self.file_name.split(".")[0] + "_" + (
                                self.index_format % i) + ".h5"
                            overwrite = True

                        if i == 0:
                            w.save_h5_file(file_name,
                                           subgroupname=subgroupname,
                                           intensity=True,
                                           phase=True,
                                           overwrite=True)
                        else:
                            w.save_h5_file(file_name,
                                           subgroupname=subgroupname,
                                           intensity=True,
                                           phase=True,
                                           overwrite=overwrite)
                        path, file_name = os.path.split(file_name)
                        self.setStatusMessage("File Out: " + file_name)

                # path, file_name = os.path.split(self.file_name)

                # self.setStatusMessage("File Out: " + file_name)

            else:
                QMessageBox.critical(self, "Error", "COMSYL modes not present",
                                     QMessageBox.Ok)
        except Exception as exception:
            QMessageBox.critical(self, "Error", str(exception), QMessageBox.Ok)