コード例 #1
0
    def plot_histo(self, var_x, title, xtitle, ytitle, xum):
        beam_to_plot = self.input_beam._beam

        if self.image_plane == 1:
            new_shadow_beam = self.input_beam.duplicate(history=False)

            historyItem = self.input_beam.getOEHistory(oe_number=self.input_beam._oe_number)
            if historyItem is None: raise Exception("Calculation impossible: Beam has no history")

            dist = 0.0

            if self.image_plane_rel_abs_position == 1:  # relative
                image_plane = 0.0

                if type(historyItem.shadow_oe_end) == ShadowOpticalElement:
                    image_plane = historyItem.shadow_oe_end._oe.T_IMAGE
                elif type(historyItem.shadow_oe_end) == ShadowCompoundOpticalElement:
                    image_plane = historyItem.shadow_oe_end._oe.list[historyItem.shadow_oe_end._oe.number_oe() - 1].T_IMAGE

                if self.image_plane_new_position < 0 and abs(self.image_plane_new_position) > image_plane:
                    raise Exception("Image plane new position cannot be before the O.E.")

                dist = self.image_plane_new_position
            else:  # absolute
                ShadowGui.checkPositiveNumber(self.image_plane_new_position, "Image Plane new Position")

                dist = self.image_plane_new_position - historyItem.shadow_oe_end._oe.T_IMAGE

            new_shadow_beam._beam.retrace(dist)

            beam_to_plot = new_shadow_beam._beam

        self.replace_fig(beam_to_plot, var_x, title, xtitle, ytitle, xum)
コード例 #2
0
ファイル: ow_kb.py プロジェクト: ales-erjavec/ShadowOui
    def checkFields(self):
        ShadowGui.checkPositiveNumber(self.grazing_angles_mrad, "Grazing Angle")

        if self.has_finite_dimensions == 0:
            ShadowGui.checkStrictlyPositiveNumber(self.mirror_width, "Mirror Width")
            ShadowGui.checkStrictlyPositiveNumber(self.mirror_length, "Mirror Length")

        if self.reflectivity_kind != 0:
            ShadowGui.checkFile(self.reflectivity_files)

        if self.has_surface_error == 1:
            ShadowGui.checkFile(self.surface_error_files)
コード例 #3
0
ファイル: ow_kb.py プロジェクト: ales-erjavec/ShadowOui
    def checkFields(self):
        ShadowGui.checkPositiveNumber(self.p, "Distance Source - KB center")
        ShadowGui.checkPositiveNumber(self.q, "Distance KB center - Image plane")

        ShadowGui.checkPositiveNumber(self.separation, "Separation between the Mirrors")
        ShadowGui.checkPositiveAngle(self.mirror_orientation_angle, "Mirror orientation angle")

        if self.use_different_focal_positions == 1:
            ShadowGui.checkPositiveNumber(self.focal_positions_p, "Focal Position P")
            ShadowGui.checkPositiveNumber(self.focal_positions_q, "Focal Position Q")

        self.v_box.checkFields()
        self.h_box.checkFields()
コード例 #4
0
    def check_fields(self):
        self.number_of_points_x = ShadowGui.checkStrictlyPositiveNumber(self.number_of_points_x, "Number of Points X")
        self.number_of_points_y = ShadowGui.checkStrictlyPositiveNumber(self.number_of_points_y, "Number of Points Y")

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

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

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

        if not self.waviness_file_name is None:
            self.waviness_file_name = self.waviness_file_name.strip()

            if self.waviness_file_name == "": raise Exception("Output File Name missing")
        else:
            raise Exception("Output File Name missing")
コード例 #5
0
ファイル: ow_dcm.py プロジェクト: ales-erjavec/ShadowOui
    def checkFields(self):
        ShadowGui.checkPositiveNumber(self.p, "Distance Source - KB center")
        ShadowGui.checkPositiveNumber(self.q, "Distance KB center - Image plane")

        ShadowGui.checkPositiveNumber(self.separation, "Separation between the Mirrors")
        ShadowGui.checkStrictlyPositiveNumber(self.photon_energy_ev, "Photon Energy")

        ShadowGui.checkFile(self.reflectivity_file)

        self.crystal_1_box.checkFields()
        self.crystal_2_box.checkFields()
コード例 #6
0
    def checkFields(self):
        ShadowGui.checkPositiveNumber(self.nlenses, "Number of lenses")
        ShadowGui.checkPositiveNumber(self.slots_empty, "Number of empty slots")
        ShadowGui.checkPositiveNumber(self.thickness, "Piling thickness")

        ShadowGui.checkPositiveNumber(self.p, "P")
        ShadowGui.checkPositiveNumber(self.q, "Q")

        if self.has_finite_diameter:
            ShadowGui.checkStrictlyPositiveNumber(self.diameter, "Diameter")

        if self.ri_calculation_mode == 1:
            ShadowGui.checkFile(self.prerefl_file)
        else:
            ShadowGui.checkStrictlyPositiveNumber(self.refraction_index, "Refraction Index")
            ShadowGui.checkStrictlyPositiveNumber(self.attenuation_coefficient, "Attenuation Coefficient")

        ShadowGui.checkStrictlyPositiveNumber(self.radius, "Radius")
        ShadowGui.checkPositiveNumber(self.interthickness, "Lens Thickness")
コード例 #7
0
 def checkFields(self):
     ShadowGui.checkPositiveNumber(self.source_plane_distance, "Distance from Source")
     ShadowGui.checkPositiveNumber(self.image_plane_distance, "Image Plane Distance")
     ShadowGui.checkPositiveNumber(self.focal_x, "Focal length (horizontal)")
     ShadowGui.checkPositiveNumber(self.focal_y, "Focal length (vertical)")
コード例 #8
0
    def plot_results(self):
        self.error(self.error_id)

        try:
            sys.stdout = EmittingStream(textWritten=self.writeStdOut)
            if self.trace_shadow:
                grabber = TTYGrabber()
                grabber.start()

            if ShadowGui.checkEmptyBeam(self.input_beam):
                self.number_of_bins = ShadowGui.checkPositiveNumber(self.number_of_bins, "Number of Bins")

                auto_x_title = self.x_column.currentText().split(":", 2)[1]
                auto_y_title = self.y_column.currentText().split(":", 2)[1]

                xum = auto_x_title + " "
                yum = auto_y_title + " "

                self.title = auto_x_title + "," + auto_y_title

                x = self.x_column_index + 1

                if x == 1 or x == 2 or x == 3:
                    xum = xum + "[" + u"\u03BC" + "m]"
                    auto_x_title = auto_x_title + " [$\mu$m]"
                elif x == 4 or x == 5 or x == 6:
                    xum = xum + "[" + u"\u03BC" + "rad]"
                    auto_x_title = auto_x_title + " [$\mu$rad]"
                elif x == 11:
                    xum = xum + "[eV]"
                    auto_x_title = auto_x_title + " [eV]"
                elif x == 13:
                    xum = xum + "[cm]"
                    auto_x_title = auto_x_title + " [cm]"
                elif x == 14:
                    xum = xum + "[rad]"
                    auto_x_title = auto_x_title + " [rad]"
                elif x == 15:
                    xum = xum + "[rad]"
                    auto_x_title = auto_x_title + " [rad]"
                elif x == 19:
                    xum = xum + "[Å]"
                    auto_x_title = auto_x_title + " [Å]"
                elif x == 20:
                    xum = xum + "[cm]"
                    auto_x_title = auto_x_title + " [cm]"
                elif x == 21:
                    xum = xum + "[rad]"
                    auto_x_title = auto_x_title + " [rad]"
                elif x >= 25 and x <= 28:
                    xum = xum + "[Å-1]"
                    auto_x_title = auto_x_title + " [Å-1]"

                y = self.y_column_index + 1

                if y == 1 or y == 2 or y == 3:
                    yum = yum + "[" + u"\u03BC" + "m]"
                    auto_y_title = auto_y_title + " [$\mu$m]"
                elif y == 4 or y == 5 or y == 6:
                    yum = yum + "[" + u"\u03BC" + "rad]"
                    auto_y_title = auto_y_title + " [$\mu$rad]"
                elif y == 11:
                    yum = yum + "[eV]"
                    auto_y_title = auto_y_title + " [eV]"
                elif y == 13:
                    yum = yum + "[cm]"
                    auto_y_title = auto_y_title + " [cm]"
                elif y == 14:
                    yum = yum + "[rad]"
                    auto_y_title = auto_y_title + " [rad]"
                elif y == 15:
                    yum = yum + "[rad]"
                    auto_y_title = auto_y_title + " [rad]"
                elif y == 19:
                    yum = yum + "[Å]"
                    auto_y_title = auto_y_title + " [Å]"
                elif y == 20:
                    yum = yum + "[cm]"
                    auto_y_title = auto_y_title + " [cm]"
                elif y == 21:
                    yum = yum + "[rad]"
                    auto_y_title = auto_y_title + " [rad]"
                elif y >= 25 and y <= 28:
                    yum = yum + "[Å-1]"
                    auto_y_title = auto_y_title + " [Å-1]"

                self.plot_xy(x, y, title=self.title, xtitle=auto_x_title, ytitle=auto_y_title, xum=xum, yum=yum)

            if self.trace_shadow:
                grabber.stop()

                for row in grabber.ttyData:
                    self.writeStdOut(row)

            time.sleep(0.5)  # prevents a misterious dead lock in the Orange cycle when refreshing the histogram
        except Exception as exception:
            QtGui.QMessageBox.critical(self, "QMessageBox.critical()",
                                       str(exception),
                                       QtGui.QMessageBox.Ok)

            self.error_id = self.error_id + 1
            self.error(self.error_id, "Exception occurred: " + str(exception))
コード例 #9
0
    def plot_xy(self, var_x, var_y, title, xtitle, ytitle, xum, yum):
        beam_to_plot = self.input_beam._beam

        if self.image_plane == 1:
            new_shadow_beam = self.input_beam.duplicate(history=False)

            historyItem = self.input_beam.getOEHistory(oe_number=self.input_beam._oe_number)
            if historyItem is None: raise Exception("Calculation impossible: Beam has no history")

            dist = 0.0

            if self.image_plane_rel_abs_position == 1:  # relative
                image_plane = 0.0

                if type(historyItem._shadow_oe_end) == ShadowOpticalElement:
                    image_plane = historyItem._shadow_oe_end._oe.T_IMAGE
                elif type(historyItem._shadow_oe_end) == ShadowCompoundOpticalElement:
                    image_plane = historyItem._shadow_oe_end._oe.list[historyItem._shadow_oe_end._oe.number_oe() - 1].T_IMAGE

                if self.image_plane_new_position < 0 and abs(self.image_plane_new_position) > image_plane:
                    raise Exception("Image plane new position cannot be before the O.E.")

                dist = self.image_plane_new_position
            else:  # absolute
                ShadowGui.checkPositiveNumber(self.image_plane_new_position, "Image Plane new Position")

                dist = self.image_plane_new_position - historyItem._shadow_oe_end._oe.T_IMAGE

            new_shadow_beam._beam.retrace(dist)

            beam_to_plot = new_shadow_beam._beam

        xrange = None
        yrange = None

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

        if self.x_range == 0 and self.y_range == 0:
            if self.cartesian_axis == 1:
                x_max = 0
                y_max = 0
                x_min = 0
                y_min = 0

                x, y, good_only = beam_to_plot.getshcol((var_x, var_y, 10))

                x_to_plot = copy.deepcopy(x)
                y_to_plot = copy.deepcopy(y)

                go = numpy.where(good_only == 1)
                lo = numpy.where(good_only != 1)

                if self.rays == 0:
                    x_max = numpy.array(x_to_plot[0:], float).max()
                    y_max = numpy.array(y_to_plot[0:], float).max()
                    x_min = numpy.array(x_to_plot[0:], float).min()
                    y_min = numpy.array(y_to_plot[0:], float).min()
                elif self.rays == 1:
                    x_max = numpy.array(x_to_plot[go], float).max()
                    y_max = numpy.array(y_to_plot[go], float).max()
                    x_min = numpy.array(x_to_plot[go], float).min()
                    y_min = numpy.array(y_to_plot[go], float).min()
                elif self.rays == 2:
                    x_max = numpy.array(x_to_plot[lo], float).max()
                    y_max = numpy.array(y_to_plot[lo], float).max()
                    x_min = numpy.array(x_to_plot[lo], float).min()
                    y_min = numpy.array(y_to_plot[lo], float).min()

                temp = numpy.array([x_max, y_max, x_min, y_min], float)

                xrange = [temp.min(), temp.max()]
                yrange = [temp.min(), temp.max()]
        else:
            if self.x_range == 1:
                if self.x_range_min >= self.x_range_max:
                    raise Exception("X range min cannot be greater or equal than X range max")

                xrange = [self.x_range_min / factor1, self.x_range_max / factor1]

            if self.y_range == 1:
                if self.y_range_min >= self.y_range_max:
                    raise Exception("Y range min cannot be greater or than Y range max")

                yrange = [self.y_range_min / factor2, self.y_range_max / factor1]

        self.replace_fig(beam_to_plot, var_x, var_y, title, xtitle, ytitle, xrange=xrange, yrange=yrange, nbins=int(self.number_of_bins), nolost=self.rays, xum=xum, yum=yum)
コード例 #10
0
 def checkFields(self):
     ShadowGui.checkPositiveNumber(self.source_plane_distance, "Distance from Source")
     ShadowGui.checkPositiveNumber(self.image_plane_distance, "Image Plane Distance")
コード例 #11
0
 def checkFields(self):
     self.number_of_rays = ShadowGui.checkPositiveNumber(self.number_of_rays, "Number of rays")
     self.seed = ShadowGui.checkPositiveNumber(self.seed, "Seed")
     self.e_min = ShadowGui.checkPositiveNumber(self.e_min, "Minimum energy")
     self.e_max = ShadowGui.checkPositiveNumber(self.e_max, "Maximum energy")
     if self.e_min > self.e_max: raise Exception("Energy min should be <= Energy max")
     self.sigma_x = ShadowGui.checkPositiveNumber(self.sigma_x, "Sigma x")
     self.sigma_z = ShadowGui.checkPositiveNumber(self.sigma_z, "Sigma z")
     self.emittance_x = ShadowGui.checkPositiveNumber(self.emittance_x, "Emittance x")
     self.emittance_z = ShadowGui.checkPositiveNumber(self.emittance_z, "Emittance z")
     self.distance_from_waist_x = ShadowGui.checkPositiveNumber(self.distance_from_waist_x, "Distance from waist x")
     self.distance_from_waist_z = ShadowGui.checkPositiveNumber(self.distance_from_waist_z, "Distance from waist z")
     self.energy = ShadowGui.checkPositiveNumber(self.energy, "Energy")
     self.magnetic_radius = ShadowGui.checkPositiveNumber(self.magnetic_radius, "Magnetic radius")
     self.horizontal_half_divergence_from = ShadowGui.checkPositiveNumber(self.horizontal_half_divergence_from,
                                                                          "Horizontal half-divergence from [+]")
     self.horizontal_half_divergence_to = ShadowGui.checkPositiveNumber(self.horizontal_half_divergence_to,
                                                                        "Horizontal half-divergence to [-]")
     self.max_vertical_half_divergence_from = ShadowGui.checkPositiveNumber(self.max_vertical_half_divergence_from,
                                                                            "Max vertical half-divergence from [+]")
     self.max_vertical_half_divergence_to = ShadowGui.checkPositiveNumber(self.max_vertical_half_divergence_to,
                                                                          "Max vertical half-divergence to [-]")
     if self.optimize_source > 0:
         self.max_number_of_rejected_rays = ShadowGui.checkPositiveNumber(self.max_number_of_rejected_rays,
                                                                          "Max number of rejected rays")
         self.optimize_file_name = ShadowGui.checkFile(self.optimize_file_name)
コード例 #12
0
    def check_fields(self):
        self.energy_in_GeV = ShadowGui.checkPositiveNumber(self.energy_in_GeV, "Energy")
        self.energy_spread = ShadowGui.checkPositiveNumber(self.energy_spread, "Energy Spread")
        self.current = ShadowGui.checkPositiveNumber(self.current, "Current")
        self.electrons_per_bunch = ShadowGui.checkPositiveNumber(self.electrons_per_bunch, "Number of electrons per bunch")

        if self.kind_of_beam == 0:
            self.moment_xx   = ShadowGui.checkPositiveNumber(self.moment_xx  , "Moment (spatial^2, horizontal)")
            self.moment_xxp  = ShadowGui.checkPositiveNumber(self.moment_xxp , "Moment (spatial-angular, horizontal)")
            self.moment_xpxp = ShadowGui.checkPositiveNumber(self.moment_xpxp, "Moment (angular^2, horizontal)")
            self.moment_yy   = ShadowGui.checkPositiveNumber(self.moment_yy  , "Moment (spatial^2, vertical)")
            self.moment_yyp  = ShadowGui.checkPositiveNumber(self.moment_yyp , "Moment (spatial-angular, vertical)")
            self.moment_ypyp = ShadowGui.checkPositiveNumber(self.moment_ypyp, "Moment (angular^2, vertical)")

        self.e_min = ShadowGui.checkPositiveNumber(self.e_min, "Minimum energy")
        self.e_max = ShadowGui.checkPositiveNumber(self.e_max, "Maximum energy")

        if self.e_min > self.e_max: raise Exception("Energy min should be <= Energy max")
コード例 #13
0
 def check_fields(self):
     self.lens_name = ShadowGui.checkEmptyString(self.lens_name, "Lens Name")
     self.lens_position = ShadowGui.checkPositiveNumber(self.lens_position, "Lens Position")
     self.focal_x = ShadowGui.checkPositiveNumber(self.focal_x, "Focal length (horizontal)")
     self.focal_y = ShadowGui.checkPositiveNumber(self.focal_y, "Focal length (vertical)")
コード例 #14
0
 def check_fields(self):
     self.image_plane_name = ShadowGui.checkEmptyString(self.image_plane_name, "Image Plane Name")
     self.image_plane_position = ShadowGui.checkPositiveNumber(self.image_plane_position, "Image Plane Position")