Exemplo n.º 1
0
    def checkFields(self):
        self.number_of_rays = congruence.checkPositiveNumber(self.number_of_rays, "Number of rays")
        self.seed = congruence.checkPositiveNumber(self.seed, "Seed")
        self.e_min = congruence.checkPositiveNumber(self.e_min, "Minimum energy")
        self.e_max = congruence.checkPositiveNumber(self.e_max, "Maximum energy")
        congruence.checkLessThan(self.e_min, self.e_max,  "Minimum energy",  "Maximum energy")

        self.sigma_x = congruence.checkPositiveNumber(self.sigma_x, "Sigma x")
        self.sigma_z = congruence.checkPositiveNumber(self.sigma_z, "Sigma z")
        self.emittance_x = congruence.checkPositiveNumber(self.emittance_x, "Emittance x")
        self.emittance_z = congruence.checkPositiveNumber(self.emittance_z, "Emittance z")
        self.distance_from_waist_x = congruence.checkPositiveNumber(self.distance_from_waist_x, "Distance from waist x")
        self.distance_from_waist_z = congruence.checkPositiveNumber(self.distance_from_waist_z, "Distance from waist z")
        self.energy = congruence.checkPositiveNumber(self.energy, "Energy")
        self.magnetic_radius = congruence.checkPositiveNumber(self.magnetic_radius, "Magnetic radius")
        self.horizontal_half_divergence_from = congruence.checkPositiveNumber(self.horizontal_half_divergence_from,
                                                                             "Horizontal half-divergence from [+]")
        self.horizontal_half_divergence_to = congruence.checkPositiveNumber(self.horizontal_half_divergence_to,
                                                                           "Horizontal half-divergence to [-]")
        self.max_vertical_half_divergence_from = congruence.checkPositiveNumber(self.max_vertical_half_divergence_from,
                                                                               "Max vertical half-divergence from [+]")
        self.max_vertical_half_divergence_to = congruence.checkPositiveNumber(self.max_vertical_half_divergence_to,
                                                                             "Max vertical half-divergence to [-]")
        if self.optimize_source > 0:
            self.max_number_of_rejected_rays = congruence.checkPositiveNumber(self.max_number_of_rejected_rays,
                                                                             "Max number of rejected rays")
            congruence.checkFile(self.optimize_file_name)
Exemplo n.º 2
0
    def generate_energy_spectrum(self):
        if self.input_beam is None: return

        try:
            if self.input_beam.getOEHistory(oe_number=0)._shadow_source_end.src.FSOURCE_DEPTH == 1:
                raise Exception("Source has no depth, calcution could be inconsistent")

            if self.kind_of_calculation == 1:
                congruence.checkFile(self.user_file)
            else:
                congruence.checkStrictlyPositiveNumber(self.factor, "Proportionality factor (k) [to eV/Å]")
                congruence.checkStrictlyPositiveNumber(self.central_value, "Central Energy/Wavelength Value [eV/Å]")

            beam_out = self.input_beam.duplicate()

            if self.kind_of_calculation == 0:
                for index in range(0, len(beam_out._beam.rays)):
                    if self.units == 0:
                        beam_out._beam.rays[index, 10] =  ShadowPhysics.getShadowKFromEnergy(self.central_value + self.factor*beam_out._beam.rays[index, 1])
                    else:
                        beam_out._beam.rays[index, 10] =  ShadowPhysics.getShadowKFromWavelength(self.central_value + self.factor*beam_out._beam.rays[index, 1])
            else:
                self.load_energy_distribution()

                for index in range(0, len(beam_out._beam.rays)):
                    if self.units == 0:
                        beam_out._beam.rays[index, 10] = ShadowPhysics.getShadowKFromEnergy(self.get_value_from_y(beam_out._beam.rays[index, 1]))
                    else:
                        beam_out._beam.rays[index, 10] =  ShadowPhysics.getShadowKFromWavelength(self.get_value_from_y(beam_out._beam.rays[index, 1]))

            self.send("Beam", beam_out)
        except Exception as exception:
                QtGui.QMessageBox.critical(self, "Error", str(exception), QtGui.QMessageBox.Ok)
Exemplo n.º 3
0
    def checkFields(self):
        self.number_of_rays = congruence.checkPositiveNumber(self.number_of_rays, "Number of rays")
        self.seed = congruence.checkPositiveNumber(self.seed, "Seed")
        self.e_min = congruence.checkPositiveNumber(self.e_min, "Minimum energy")
        self.e_max = congruence.checkPositiveNumber(self.e_max, "Maximum energy")
        congruence.checkLessThan(self.e_min, self.e_max,  "Minimum energy",  "Maximum energy")

        self.max_number_of_rejected_rays = congruence.checkPositiveNumber(self.max_number_of_rejected_rays,
                                                                         "Max Number of Rejected Rays")
        self.slit_distance = congruence.checkPositiveNumber(self.slit_distance, "Horizontal half-divergence from [+]")
        self.min_x = congruence.checkNumber(self.min_x, "Min X/Min Xp")
        self.max_x = congruence.checkNumber(self.max_x, "Max X/Max Xp")
        self.min_z = congruence.checkNumber(self.min_z, "Min X/Min Xp")
        self.max_z = congruence.checkNumber(self.max_z, "Max X/Max Xp")
        self.energy = congruence.checkPositiveNumber(self.energy, "Energy")
        self.electron_current = congruence.checkPositiveNumber(self.electron_current, "Electron Current")
        self.sigma_x = congruence.checkPositiveNumber(self.sigma_x, "Sigma x")
        self.sigma_z = congruence.checkPositiveNumber(self.sigma_z, "Sigma z")
        self.emittance_x = congruence.checkPositiveNumber(self.emittance_x, "Emittance x")
        self.emittance_z = congruence.checkPositiveNumber(self.emittance_z, "Emittance z")
        self.distance_from_waist_x = congruence.checkNumber(self.distance_from_waist_x, "Distance from waist x")
        self.distance_from_waist_z = congruence.checkNumber(self.distance_from_waist_z, "Distance from waist z")
        self.number_of_periods = congruence.checkStrictlyPositiveNumber(self.number_of_periods, "Number of periods")
        self.k_value = congruence.checkStrictlyPositiveNumber(self.k_value, "K value")
        self.id_period = congruence.checkStrictlyPositiveNumber(self.id_period, "ID period")

        if self.optimize_source_combo == 1:
            congruence.checkFile(self.file_with_phase_space_volume)

        if self.type_combo == 1:
            congruence.checkUrl(self.file_with_b_vs_y)
        elif self.type_combo == 2:
            congruence.checkUrl(self.file_with_harmonics)
Exemplo n.º 4
0
    def check_fields(self):
        if self.F12_FLAG == 1:
            congruence.checkEmptyString(self.SUBSTRATE, "Substrate")
            congruence.checkEmptyString(self.ODD_MATERIAL,
                                        "Odd layer material")
            congruence.checkEmptyString(self.EVEN_MATERIAL,
                                        "Even layer material")

        if self.SCAN == 0:  # ga
            self.ENERGY = congruence.checkStrictlyPositiveNumber(
                self.ENERGY, "Photon energy")
        else:
            self.THETA = congruence.checkStrictlyPositiveNumber(
                self.THETA, "Grazing angle")

        self.SCAN_STEP = congruence.checkStrictlyPositiveNumber(
            self.SCAN_STEP, "Scanning variable step")
        self.NPOINTS = congruence.checkStrictlyPositiveNumber(
            self.NPOINTS, "Number of scanning points")

        if self.MODE == 0:  # periodic layers
            self.ODD_THICKNESS = congruence.checkStrictlyPositiveNumber(
                self.ODD_THICKNESS, "Thickness for odd material")
            self.EVEN_THICKNESS = congruence.checkStrictlyPositiveNumber(
                self.EVEN_THICKNESS, "Thickness for even material")
            self.NLAYERS = congruence.checkStrictlyPositiveNumber(
                self.NLAYERS, "Number of layer pairs")
        else:
            congruence.checkFile(self.FILE)
Exemplo n.º 5
0
def read_error_profile_file(file_name, separator='\t', dimension=2):
    if dimension == 2:
        rows = open(congruence.checkFile(file_name), "r").readlines()

        # first row: x positions

        x_pos = rows[0].split(separator)
        n_x = len(x_pos) - 1
        n_y = len(rows) - 1

        x_coords = numpy.zeros(n_x)
        y_coords = numpy.zeros(n_y)
        z_values = numpy.zeros((n_x, n_y))

        for i_x in range(n_x):
            x_coords[i_x] = float(x_pos[i_x + 1])

        for i_y in range(n_y):
            data = rows[i_y + 1].split(separator)
            y_coords[i_y] = float(data[0])

            for i_x in range(n_x):
                z_values[i_x, i_y] = float(data[i_x + 1])

        return x_coords, y_coords, z_values
    else:
        data = numpy.loadtxt(congruence.checkFile(file_name),
                             delimiter=separator)

        x_coords = data[:, 0]
        z_values = data[:, 1]

        return x_coords, z_values
Exemplo n.º 6
0
    def checkFields(self):
        self.number_of_rays = congruence.checkPositiveNumber(self.number_of_rays, "Number of rays")
        self.seed = congruence.checkPositiveNumber(self.seed, "Seed")
        self.e_min = congruence.checkPositiveNumber(self.e_min, "Minimum energy")
        self.e_max = congruence.checkPositiveNumber(self.e_max, "Maximum energy")
        congruence.checkLessThan(self.e_min, self.e_max,  "Minimum energy",  "Maximum energy")

        self.sigma_x = congruence.checkPositiveNumber(self.sigma_x, "Sigma x")
        self.sigma_z = congruence.checkPositiveNumber(self.sigma_z, "Sigma z")
        self.emittance_x = congruence.checkPositiveNumber(self.emittance_x, "Emittance x")
        self.emittance_z = congruence.checkPositiveNumber(self.emittance_z, "Emittance z")
        self.distance_from_waist_x = congruence.checkPositiveNumber(self.distance_from_waist_x, "Distance from waist x")
        self.distance_from_waist_z = congruence.checkPositiveNumber(self.distance_from_waist_z, "Distance from waist z")
        self.energy = congruence.checkPositiveNumber(self.energy, "Energy")
        self.magnetic_radius = congruence.checkPositiveNumber(self.magnetic_radius, "Magnetic radius")
        self.horizontal_half_divergence_from = congruence.checkPositiveNumber(self.horizontal_half_divergence_from,
                                                                             "Horizontal half-divergence from [+]")
        self.horizontal_half_divergence_to = congruence.checkPositiveNumber(self.horizontal_half_divergence_to,
                                                                           "Horizontal half-divergence to [-]")
        self.max_vertical_half_divergence_from = congruence.checkPositiveNumber(self.max_vertical_half_divergence_from,
                                                                               "Max vertical half-divergence from [+]")
        self.max_vertical_half_divergence_to = congruence.checkPositiveNumber(self.max_vertical_half_divergence_to,
                                                                             "Max vertical half-divergence to [-]")
        if self.optimize_source > 0:
            self.max_number_of_rejected_rays = congruence.checkPositiveNumber(self.max_number_of_rejected_rays,
                                                                             "Max number of rejected rays")
            congruence.checkFile(self.optimize_file_name)
Exemplo n.º 7
0
    def check_fields(self):
        self.NPERIODS = congruence.checkStrictlyPositiveNumber(
            self.NPERIODS, "Number of Periods")
        self.ENERGY = congruence.checkStrictlyPositiveNumber(
            self.ENERGY, "Beam Energy")
        self.PHOT_ENERGY_MIN = congruence.checkPositiveNumber(
            self.PHOT_ENERGY_MIN, "Min Photon Energy")
        self.PHOT_ENERGY_MAX = congruence.checkStrictlyPositiveNumber(
            self.PHOT_ENERGY_MAX, "Max Photon Energy")
        congruence.checkLessThan(self.PHOT_ENERGY_MIN, self.PHOT_ENERGY_MAX,
                                 "Min Photon Energy", "Max Photon Energy")
        self.NPOINTS = congruence.checkStrictlyPositiveNumber(
            self.NPOINTS, "Number of Energy Points")
        self.CURRENT = congruence.checkStrictlyPositiveNumber(
            self.CURRENT, "Electron Beam Current")

        if self.FIELD == 0:
            self.ULAMBDA = congruence.checkStrictlyPositiveNumber(
                self.ULAMBDA, "Wiggler period")
            self.K = congruence.checkStrictlyPositiveNumber(self.K, "K")
            self.NTRAJPOINTS = congruence.checkStrictlyPositiveNumber(
                self.NTRAJPOINTS, "Number of traj points per period")
        elif self.FIELD == 1:
            self.ULAMBDA = congruence.checkStrictlyPositiveNumber(
                self.ULAMBDA, "Wiggler period")
            self.NTRAJPOINTS = congruence.checkStrictlyPositiveNumber(
                self.NTRAJPOINTS, "Number of traj points per period")
            congruence.checkFile(self.FILE)
        elif self.FIELD == 2:
            congruence.checkFile(self.FILE)
    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)
Exemplo n.º 9
0
    def plot_wiggler_results(self):
        if self.plot_graph == 1:
            try:
                try:
                    congruence.checkFile("tmp.traj")
                except:
                    return

                data = numpy.loadtxt("tmp.traj",skiprows=15)

                energy, flux, temp = srfunc.wiggler_spectrum(data.T,
                                                             enerMin=self.e_min,
                                                             enerMax=self.e_max,
                                                             nPoints=500,
                                                             electronCurrent=self.electron_current/1000,
                                                             outFile="spectrum.dat",
                                                             elliptical=False)

                self.plot_wiggler_histo(20,  data[:, 1], data[:, 7], plot_canvas_index=0, title="Magnetic Field (in vertical) Bz(Y)", xtitle=r'Y [m]', ytitle=r'B [T]')
                self.plot_wiggler_histo(40,  data[:, 1], data[:, 6], plot_canvas_index=1, title="Electron Curvature", xtitle=r'Y [m]', ytitle=r'curvature [m^-1]')
                self.plot_wiggler_histo(60,  data[:, 1], data[:, 3], plot_canvas_index=2, title="Electron Velocity BetaX(Y)", xtitle=r'Y [m]', ytitle=r'BetaX')
                self.plot_wiggler_histo(80,  data[:, 1], data[:, 0], plot_canvas_index=3, title="Electron Trajectory X(Y)", xtitle=r'Y [m]', ytitle=r'X [m]')
                self.plot_wiggler_histo(100, energy    , flux      , plot_canvas_index=4, title="Wiggler Spectrum (current = " + str(self.electron_current) + " mA)",
                                        xtitle=r'E [eV]', ytitle=r'Flux [phot/s/0.1%bw]', is_log_log=True)

            except Exception as exception:
                QtGui.QMessageBox.critical(self, "Error",
                                           str(exception),
                    QtGui.QMessageBox.Ok)
Exemplo n.º 10
0
    def check_fields(self):
        self.MILLER_INDEX_H = congruence.checkNumber(self.MILLER_INDEX_H,
                                                     "Miller index H")
        self.MILLER_INDEX_K = congruence.checkNumber(self.MILLER_INDEX_K,
                                                     "Miller index K")
        self.MILLER_INDEX_L = congruence.checkNumber(self.MILLER_INDEX_L,
                                                     "Miller index L")
        self.TEMPER = congruence.checkNumber(self.TEMPER, "Temperature factor")

        if self.SCAN == 0 or self.SCAN == 3:
            self.SCANFROM = congruence.checkPositiveNumber(
                self.SCANFROM, "Min Scan value")
            self.SCANTO = congruence.checkStrictlyPositiveNumber(
                self.SCANTO, "Max Scan value")
        else:
            self.SCANFROM = congruence.checkNumber(self.SCANFROM,
                                                   "Min Scan value")
            self.SCANTO = congruence.checkNumber(self.SCANTO, "Max Scan value")

        congruence.checkLessThan(self.SCANFROM, self.SCANTO, "Min Scan value",
                                 "Max Scan value")
        self.SCANPOINTS = congruence.checkStrictlyPositiveNumber(
            self.SCANPOINTS, "Scan points")

        if self.SCAN < 4:
            self.ENERGY = congruence.checkStrictlyPositiveNumber(
                self.ENERGY, "Fix value")
        else:
            self.ENERGY = congruence.checkNumber(self.ENERGY, "Fix value")

        if self.MOSAIC == 0:  #perfect
            self.ASYMMETRY_ANGLE = congruence.checkNumber(
                self.ASYMMETRY_ANGLE, "Asymmetry angle")
            self.THICKNESS = congruence.checkStrictlyPositiveNumber(
                self.THICKNESS, "Crystal thickness")
        elif self.MOSAIC == 1:  #mosaic
            self.THICKNESS = congruence.checkStrictlyPositiveNumber(
                self.THICKNESS, "Crystal thickness")
            self.MOSAIC_FWHM = congruence.checkNumber(self.MOSAIC_FWHM,
                                                      "Mosaicity")
        elif self.MOSAIC == 2 or self.MOSAIC == 3:  #bent ML/PP
            self.ASYMMETRY_ANGLE = congruence.checkNumber(
                self.ASYMMETRY_ANGLE, "Asymmetry angle")
            self.THICKNESS = congruence.checkStrictlyPositiveNumber(
                self.THICKNESS, "Crystal thickness")
            self.RSAG = congruence.checkStrictlyPositiveNumber(
                self.RSAG, "R Sagittal")
            self.RMER = congruence.checkStrictlyPositiveNumber(
                self.RMER, "R meridional")

            if self.ANISOTROPY == 0:
                self.POISSON = congruence.checkStrictlyPositiveNumber(
                    self.POISSON, "Poisson Ratio")
            elif self.ANISOTROPY == 2:
                congruence.checkEmptyString(self.CUT, "Valong; Vnorm; Vperp")
            elif self.ANISOTROPY == 3:
                congruence.checkFile(self.FILECOMPLIANCE)
Exemplo n.º 11
0
    def check_fields(self):
        self.DESCRIPTION = congruence.checkEmptyString(self.DESCRIPTION, "Description")

        if self.SUBSTANCE == 3:
            self.FRACTION = congruence.checkEmptyString(self.FRACTION, "fraction")

        if self.GRID != 0:
            if self.GRIDINPUT == 0:
                self.GRIDDATA = congruence.checkEmptyString(self.GRIDDATA, "grid points")
            else:
                congruence.checkFile(self.GRIDDATA)
Exemplo n.º 12
0
    def checkFields(self):
        congruence.checkPositiveNumber(self.p, "Distance Source - KB center")
        congruence.checkPositiveNumber(self.q, "Distance KB center - Image plane")

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

        congruence.checkFile(self.reflectivity_file)

        self.crystal_1_box.checkFields()
        self.crystal_2_box.checkFields()
Exemplo n.º 13
0
    def check_fields(self):
        self.DESCRIPTION = congruence.checkEmptyString(self.DESCRIPTION, "Description")

        if self.SUBSTANCE == 3:
            self.FRACTION = congruence.checkEmptyString(self.FRACTION, "fraction")

        if self.GRID != 0:
            if self.GRIDINPUT == 0:
                self.GRIDDATA = congruence.checkEmptyString(self.GRIDDATA, "grid points")
            else:
                congruence.checkFile(self.GRIDDATA)
Exemplo n.º 14
0
 def check_fields(self):
     congruence.checkFile(self.FILE)
     self.LAMBDA = congruence.checkStrictlyPositiveNumber(self.LAMBDA, "Lambda")
     self.U = congruence.checkNumber(self.U, "U")
     self.V = congruence.checkNumber(self.V, "V")
     self.W = congruence.checkNumber(self.W, "W")
     self.X = congruence.checkNumber(self.X, "X")
     self.LS = congruence.checkNumber(self.LS, "LS")
     self.THMIN = congruence.checkPositiveAngle(self.THMIN, "TwoTheta from")
     self.THMAX = congruence.checkPositiveAngle(self.THMAX, "TwoTheta to")
     self.STEP = congruence.checkStrictlyPositiveAngle(self.STEP, "TwoTheta step")
     congruence.checkGreaterThan(self.THMAX, self.THMIN, "TwoTheta to", "TwoTheta from")
 def send_data(self):
     try:
         congruence.checkEmptyString(self.file_name, "File Name")
         congruence.checkFile(self.file_name)
         native_srw_wavefront = load_hdf5_2_wfr(self.file_name,
                                                self.data_path)
         self.send(
             "SRWData",
             SRWData(srw_wavefront=SRWWavefront.decorateSRWWF(
                 native_srw_wavefront)))
     except Exception as e:
         QMessageBox.critical(self, "Error", str(e.args[0]), QMessageBox.Ok)
Exemplo n.º 16
0
 def check_fields(self):
     congruence.checkFile(self.FILE)
     self.LAMBDA = congruence.checkStrictlyPositiveNumber(self.LAMBDA, "Lambda")
     self.U = congruence.checkNumber(self.U, "U")
     self.V = congruence.checkNumber(self.V, "V")
     self.W = congruence.checkNumber(self.W, "W")
     self.X = congruence.checkNumber(self.X, "X")
     self.LS = congruence.checkNumber(self.LS, "LS")
     self.THMIN = congruence.checkPositiveAngle(self.THMIN, "TwoTheta from")
     self.THMAX = congruence.checkPositiveAngle(self.THMAX, "TwoTheta to")
     self.STEP = congruence.checkStrictlyPositiveAngle(self.STEP, "TwoTheta step")
     congruence.checkGreaterThan(self.THMAX, self.THMIN, "TwoTheta to", "TwoTheta from")
Exemplo n.º 17
0
    def load_diffraction_pattern(self):
        congruence.checkFile(self.filename)

        if self.twotheta_has_min == 1 or self.twotheta_has_max == 1:
            limits = DiffractionPatternLimits(
                twotheta_min=self.twotheta_min
                if self.twotheta_has_min == 1 else -numpy.inf,
                twotheta_max=self.twotheta_max
                if self.twotheta_has_max == 1 else numpy.inf)
        else:
            limits = None

        self.diffraction_pattern = DiffractionPatternFactory.create_diffraction_pattern_from_file(
            self.filename, limits, self.diffraction_pattern_name)
Exemplo n.º 18
0
    def checkFields(self):
        congruence.checkPositiveNumber(self.grazing_angles_mrad, "Grazing Angle")

        if self.has_finite_dimensions == 0:
            congruence.checkStrictlyPositiveNumber(self.mirror_width, "Mirror Width")
            congruence.checkStrictlyPositiveNumber(self.mirror_length, "Mirror Length")
        elif self.has_surface_error != 0:
            raise Exception("With surface error file, dimensions cannot be infinite")

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

        if self.has_surface_error == 1:
            congruence.checkFile(self.surface_error_files)
Exemplo n.º 19
0
    def checkFields(self):
        congruence.checkPositiveNumber(self.p, "Distance Source - KB center")
        congruence.checkPositiveNumber(self.q,
                                       "Distance KB center - Image plane")

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

        congruence.checkFile(self.reflectivity_file)

        self.crystal_1_box.checkFields()
        self.crystal_2_box.checkFields()
Exemplo n.º 20
0
    def check_data(self):
        super().check_data()

        congruence.checkStrictlyPositiveNumber(self.tangential_size,
                                               "Tangential Size")
        congruence.checkStrictlyPositiveNumber(self.sagittal_size,
                                               "Sagittal Size")

        if self.has_height_profile:
            congruence.checkFile(self.height_profile_data_file)

        congruence.checkPositiveNumber(self.diffraction_order,
                                       "Diffraction Order")
        congruence.checkStrictlyPositiveNumber(self.grooving_density_0,
                                               "Groove density")
Exemplo n.º 21
0
    def checkFields(self):
        congruence.checkPositiveNumber(self.p, "P")
        congruence.checkPositiveNumber(self.q, "Q")

        if self.has_finite_diameter == 0:
            congruence.checkStrictlyPositiveNumber(self.diameter, "Diameter")

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

        congruence.checkStrictlyPositiveNumber(self.radius, "Radius")
        congruence.checkPositiveNumber(self.interthickness, "Lens Thickness")
Exemplo n.º 22
0
    def checkFields(self):
        congruence.checkPositiveNumber(self.p, "P")
        congruence.checkPositiveNumber(self.q, "Q")

        if self.has_finite_diameter == 0:
            congruence.checkStrictlyPositiveNumber(self.diameter, "Diameter")

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

        congruence.checkStrictlyPositiveNumber(self.radius, "Radius")
        congruence.checkPositiveNumber(self.interthickness, "Lens Thickness")
def generate_user_defined_distribution(beam_out,
                                       user_defined_file,
                                       axis=Axis.X,
                                       distribution_type=Distribution.POSITION,
                                       minimum_value=-2e-5,
                                       step=1e-6):

    distribution = extract_distribution_from_file(
        congruence.checkFile(user_defined_file))

    sampled_distribution = sample_from_distribution(distribution,
                                                    len(beam_out._beam.rays))

    if distribution_type == Distribution.POSITION:
        if axis == Axis.X:
            axis_index = 0
        elif axis == Axis.Z:
            axis_index = 2
    elif distribution_type == Distribution.DIVERGENCE:
        if axis == Axis.X:
            axis_index = 4
        elif axis == Axis.Z:
            axis_index = 6

    beam_out._beam.rays[:,
                        axis_index] = minimum_value + sampled_distribution * step
Exemplo n.º 24
0
def sh_readsurface(filename, dimension):
    if dimension == 1:
        values = np.loadtxt(congruence.checkFile(filename))

        return ScaledArray(values[:, 1], values[:, 0])
    elif dimension == 2:
        x_coords, y_coords, z_values = ShadowPreProcessor.read_surface_error_file(filename)

        return ScaledMatrix(x_coords, y_coords, z_values)
Exemplo n.º 25
0
    def checkFields(self):
        congruence.checkPositiveNumber(self.grazing_angles_mrad,
                                       "Grazing Angle")

        if self.has_finite_dimensions == 0:
            congruence.checkStrictlyPositiveNumber(self.mirror_width,
                                                   "Mirror Width")
            congruence.checkStrictlyPositiveNumber(self.mirror_length,
                                                   "Mirror Length")
        elif self.has_surface_error != 0:
            raise Exception(
                "With surface error file, dimensions cannot be infinite")

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

        if self.has_surface_error == 1:
            congruence.checkFile(self.surface_error_files)
Exemplo n.º 26
0
    def check_fields(self):
        if self.F12_FLAG == 1:
            congruence.checkEmptyString(self.SUBSTRATE, "Substrate")
            congruence.checkEmptyString(self.ODD_MATERIAL, "Odd layer material")
            congruence.checkEmptyString(self.EVEN_MATERIAL, "Even layer material")

        if self.SCAN == 0: # ga
            self.ENERGY = congruence.checkStrictlyPositiveNumber(self.ENERGY, "Photon energy")
        else:
            self.THETA = congruence.checkStrictlyPositiveNumber(self.THETA, "Grazing angle")

        self.SCAN_STEP = congruence.checkStrictlyPositiveNumber(self.SCAN_STEP, "Scanning variable step")
        self.NPOINTS = congruence.checkStrictlyPositiveNumber(self.NPOINTS, "Number of scanning points")

        if self.MODE == 0: # periodic layers
            self.ODD_THICKNESS = congruence.checkStrictlyPositiveNumber(self.ODD_THICKNESS, "Thickness for odd material")
            self.EVEN_THICKNESS = congruence.checkStrictlyPositiveNumber(self.EVEN_THICKNESS, "Thickness for even material")
            self.NLAYERS = congruence.checkStrictlyPositiveNumber(self.NLAYERS, "Number of layer pairs")
        else:
            congruence.checkFile(self.FILE)
Exemplo n.º 27
0
    def checkFields(self):
        self.number_of_rays = congruence.checkPositiveNumber(self.number_of_rays, "Number of rays")
        self.seed = congruence.checkPositiveNumber(self.seed, "Seed")
        self.e_min = congruence.checkPositiveNumber(self.e_min, "Minimum energy")
        self.e_max = congruence.checkPositiveNumber(self.e_max, "Maximum energy")
        congruence.checkLessThan(self.e_min, self.e_max,  "Minimum energy",  "Maximum energy")

        self.max_number_of_rejected_rays = congruence.checkPositiveNumber(self.max_number_of_rejected_rays,
                                                                         "Max Number of Rejected Rays")
        self.slit_distance = congruence.checkPositiveNumber(self.slit_distance, "Horizontal half-divergence from [+]")
        self.min_x = congruence.checkNumber(self.min_x, "Min X/Min Xp")
        self.max_x = congruence.checkNumber(self.max_x, "Max X/Max Xp")
        self.min_z = congruence.checkNumber(self.min_z, "Min X/Min Xp")
        self.max_z = congruence.checkNumber(self.max_z, "Max X/Max Xp")
        self.energy = congruence.checkPositiveNumber(self.energy, "Energy")
        self.electron_current = congruence.checkPositiveNumber(self.electron_current, "Electron Current")
        self.sigma_x = congruence.checkPositiveNumber(self.sigma_x, "Sigma x")
        self.sigma_z = congruence.checkPositiveNumber(self.sigma_z, "Sigma z")
        self.emittance_x = congruence.checkPositiveNumber(self.emittance_x, "Emittance x")
        self.emittance_z = congruence.checkPositiveNumber(self.emittance_z, "Emittance z")
        self.distance_from_waist_x = congruence.checkNumber(self.distance_from_waist_x, "Distance from waist x")
        self.distance_from_waist_z = congruence.checkNumber(self.distance_from_waist_z, "Distance from waist z")
        self.number_of_periods = congruence.checkStrictlyPositiveNumber(self.number_of_periods, "Number of periods")
        self.k_value = congruence.checkStrictlyPositiveNumber(self.k_value, "K value")
        self.id_period = congruence.checkStrictlyPositiveNumber(self.id_period, "ID period")

        if self.optimize_source_combo == 1:
            congruence.checkFile(self.file_with_phase_space_volume)

        if self.type_combo == 1:
            congruence.checkFile(self.file_with_b_vs_y)
        elif self.type_combo == 2:
            congruence.checkFile(self.file_with_harmonics)
Exemplo n.º 28
0
    def check_fields(self):
        self.MILLER_INDEX_H = congruence.checkNumber(self.MILLER_INDEX_H, "Miller index H")
        self.MILLER_INDEX_K = congruence.checkNumber(self.MILLER_INDEX_K, "Miller index K")
        self.MILLER_INDEX_L = congruence.checkNumber(self.MILLER_INDEX_L, "Miller index L")
        self.TEMPER = congruence.checkNumber(self.TEMPER, "Temperature factor")

        if self.SCAN == 0 or self.SCAN == 3:
            self.SCANFROM = congruence.checkPositiveNumber(self.SCANFROM, "Min Scan value")
            self.SCANTO = congruence.checkStrictlyPositiveNumber(self.SCANTO, "Max Scan value")
        else:
            self.SCANFROM = congruence.checkNumber(self.SCANFROM, "Min Scan value")
            self.SCANTO = congruence.checkNumber(self.SCANTO, "Max Scan value")

        congruence.checkLessThan(self.SCANFROM, self.SCANTO, "Min Scan value", "Max Scan value")
        self.SCANPOINTS = congruence.checkStrictlyPositiveNumber(self.SCANPOINTS, "Scan points")

        if self.SCAN < 4:
            self.ENERGY = congruence.checkStrictlyPositiveNumber(self.ENERGY , "Fix value")
        else:
            self.ENERGY = congruence.checkNumber(self.ENERGY , "Fix value")

        if self.MOSAIC == 0: #perfect
            self.ASYMMETRY_ANGLE = congruence.checkNumber(self.ASYMMETRY_ANGLE, "Asymmetry angle")
            self.THICKNESS = congruence.checkStrictlyPositiveNumber(self.THICKNESS, "Crystal thickness")
        elif self.MOSAIC == 1: #mosaic
            self.THICKNESS = congruence.checkStrictlyPositiveNumber(self.THICKNESS, "Crystal thickness")
            self.MOSAIC_FWHM = congruence.checkNumber(self.MOSAIC_FWHM, "Mosaicity")
        elif self.MOSAIC == 2 or self.MOSAIC == 3: #bent ML/PP
            self.ASYMMETRY_ANGLE = congruence.checkNumber(self.ASYMMETRY_ANGLE, "Asymmetry angle")
            self.THICKNESS = congruence.checkStrictlyPositiveNumber(self.THICKNESS, "Crystal thickness")
            self.RSAG = congruence.checkStrictlyPositiveNumber(self.RSAG, "R Sagittal")
            self.RMER = congruence.checkStrictlyPositiveNumber(self.RMER, "R meridional")

            if self.ANISOTROPY == 0:
                self.POISSON = congruence.checkStrictlyPositiveNumber(self.POISSON, "Poisson Ratio")
            elif self.ANISOTROPY == 2:
                congruence.checkEmptyString(self.CUT, "Valong; Vnorm; Vperp")
            elif self.ANISOTROPY == 3:
                congruence.checkFile(self.FILECOMPLIANCE)
Exemplo n.º 29
0
    def check_data(self):
        super().check_data()

        congruence.checkStrictlyPositiveNumber(self.tangential_size, "Tangential Size")
        congruence.checkStrictlyPositiveNumber(self.sagittal_size, "Sagittal Size")
        
        if self.has_height_profile:
            congruence.checkFile(self.height_profile_data_file)

        if self.has_reflectivity == 1:
            congruence.checkStrictlyPositiveNumber(self.reflectivity_value, "Reflectivity Value")
        elif self.has_reflectivity == 2:
            congruence.checkFile(self.reflectivity_data_file)

            congruence.checkStrictlyPositiveNumber(self.reflectivity_energies_number, "Number of Energy Values")
            congruence.checkStrictlyPositiveNumber(self.reflectivity_energy_start, "Initial Energy Value")
            congruence.checkStrictlyPositiveNumber(self.reflectivity_energy_end, "Final Energy Value")
            congruence.checkGreaterOrEqualThan(self.reflectivity_energy_end, self.reflectivity_energy_start, "Final Energy Value", "Initial Energy Value")

            congruence.checkStrictlyPositiveNumber(self.reflectivity_angles_number, "Number of Grazing Angle Values")
            congruence.checkStrictlyPositiveNumber(self.reflectivity_angle_start, "Initial Grazing Angle Value")
            congruence.checkStrictlyPositiveNumber(self.reflectivity_angle_end, "Final Grazing Angle Value")
            congruence.checkGreaterOrEqualThan(self.reflectivity_angle_end, self.reflectivity_angle_start, "Final Grazing Angle Value", "Initial Grazing Angle Value")
Exemplo n.º 30
0
    def plot_wiggler_results(self):
        if self.plot_graph == 1:
            try:
                try:
                    congruence.checkFile("tmp.traj")
                except:
                    return

                data = numpy.loadtxt("tmp.traj",skiprows=15)

                energy, flux, temp = srfunc.wiggler_spectrum(data.T,
                                                             enerMin=self.e_min,
                                                             enerMax=self.e_max,
                                                             nPoints=500,
                                                             electronCurrent=self.electron_current/1000,
                                                             outFile="spectrum.dat",
                                                             elliptical=False)

                self.plot_wiggler_histo(15,  data[:, 1], data[:, 7], plot_canvas_index=0, title="Magnetic Field (in vertical) Bz(Y)", xtitle=r'Y [m]', ytitle=r'B [T]')
                self.plot_wiggler_histo(30,  data[:, 1], data[:, 6], plot_canvas_index=1, title="Electron Curvature", xtitle=r'Y [m]', ytitle=r'curvature [m^-1]')
                self.plot_wiggler_histo(45,  data[:, 1], data[:, 3], plot_canvas_index=2, title="Electron Velocity BetaX(Y)", xtitle=r'Y [m]', ytitle=r'BetaX')
                self.plot_wiggler_histo(60,  data[:, 1], data[:, 0], plot_canvas_index=3, title="Electron Trajectory X(Y)", xtitle=r'Y [m]', ytitle=r'X [m]')
                self.plot_wiggler_histo(80, energy    , flux      , plot_canvas_index=4,
                                        title="Wiggler Spectrum (current = " + str(self.electron_current) + " mA)",
                                        xtitle=r'E [eV]', ytitle=r'Flux [phot/s/0.1%bw]', is_log_log=False)
                self.plot_wiggler_histo(100, energy, flux*1e3*codata.e, plot_canvas_index=5,
                                        title="Spectral Power (current = " + str(self.electron_current) + " mA)",
                                        xtitle=r'E [eV]', ytitle=r'Spectral Power [W/eV]', is_log_log=False)

                print("\nTotal power (from integral of spectrum): %f W"%(numpy.trapz(flux*1e3*codata.e,x=energy)))
                print("\nTotal number of photons (from integral of spectrum): %g"%(numpy.trapz(flux/(energy*1e-3),x=energy)))

            except Exception as exception:
                QtWidgets.QMessageBox.critical(self, "Error",
                                           str(exception),
                    QtWidgets.QMessageBox.Ok)
Exemplo n.º 31
0
def sh_readangle(filename, mirror_beam=None):
    values = np.loadtxt(congruence.checkFile(filename))
    dimension = len(mirror_beam._beam.rays)

    angle_inc = np.zeros(dimension)
    angle_ref = np.zeros(dimension)

    ray_index = 0
    for index in range(0, len(values)):
        if values[index, 3] == 1:
            angle_inc[ray_index] = values[index, 1]
            angle_ref[ray_index] = values[index, 2]

            ray_index += 1

    return angle_inc, angle_ref
Exemplo n.º 32
0
def sh_read_gfile(gfilename):
    return ShadowOpticalElement.create_oe_from_file(congruence.checkFile(gfilename))
    def run_hybrid(self):
        try:
            self.setStatusMessage("")
            self.progressBarInit()
            self.initializeTabs()

            if ShadowCongruence.checkEmptyBeam(self.input_beam):
                if ShadowCongruence.checkGoodBeam(self.input_beam):
                    sys.stdout = EmittingStream(textWritten=self.write_stdout)

                    self.check_fields()

                    input_parameters = hybrid_control.HybridInputParameters()
                    input_parameters.ghy_lengthunit = self.workspace_units
                    input_parameters.widget = self
                    input_parameters.ghy_diff_plane = self.ghy_diff_plane + 1

                    if self.distance_to_image_calc == 0:
                        input_parameters.ghy_distance = -1
                    else:
                        input_parameters.ghy_distance = self.ghy_distance

                    if self.focal_length_calc == 0:
                        input_parameters.ghy_focallength = -1
                    else:
                        input_parameters.ghy_focallength = self.ghy_focallength

                    input_parameters.ghy_nf = self.ghy_nf

                    input_parameters.ghy_nbins_x = int(self.ghy_nbins_x)
                    input_parameters.ghy_nbins_z = int(self.ghy_nbins_z)
                    input_parameters.ghy_npeak = int(self.ghy_npeak)
                    input_parameters.ghy_fftnpts = int(self.ghy_fftnpts)
                    input_parameters.file_to_write_out = self.file_to_write_out

                    input_parameters.ghy_automatic = self.ghy_automatic

                    # -----------------------------------------------
                    #cycling or figure errors

                    # add the reference (no error profile)

                    shadow_beam = self.input_beam.duplicate()

                    history_entry = shadow_beam.getOEHistory(
                        shadow_beam._oe_number)
                    shadow_oe = history_entry._shadow_oe_start  # changes to the original object!
                    shadow_oe._oe.F_RIPPLE = 0

                    input_parameters.ghy_calcType = 2

                    input_parameters.shadow_beam = shadow_beam

                    calculation_parameters = hybrid_control.hy_run(
                        input_parameters)

                    self.ghy_focallength = input_parameters.ghy_focallength
                    self.ghy_distance = input_parameters.ghy_distance
                    self.ghy_nbins_x = int(input_parameters.ghy_nbins_x)
                    self.ghy_nbins_z = int(input_parameters.ghy_nbins_z)
                    self.ghy_npeak = int(input_parameters.ghy_npeak)
                    self.ghy_fftnpts = int(input_parameters.ghy_fftnpts)

                    if input_parameters.ghy_calcType == 3 or input_parameters.ghy_calcType == 4:
                        do_plot_x = True
                        do_plot_z = True
                    else:
                        if self.ghy_automatic == 1:
                            do_plot_x = not calculation_parameters.beam_not_cut_in_x
                            do_plot_z = not calculation_parameters.beam_not_cut_in_z
                        else:
                            do_plot_x = True
                            do_plot_z = True

                    do_nf = input_parameters.ghy_nf == 1 and input_parameters.ghy_calcType > 1

                    if do_plot_x or do_plot_z:
                        self.setStatusMessage("Plotting Results")

                    profile = 0

                    self.current_histo_data_x_ff = None
                    self.current_histo_data_x_nf = None
                    self.current_histo_data_z_ff = None
                    self.current_histo_data_z_nf = None
                    self.current_stats_x_ff = None
                    self.current_stats_x_nf = None
                    self.current_stats_z_ff = None
                    self.current_stats_z_nf = None

                    histo_data_x_ff, \
                    histo_data_z_ff, \
                    histo_data_x_nf, \
                    histo_data_z_nf = self.plot_results(calculation_parameters=calculation_parameters,
                                                        do_nf=do_nf,
                                                        do_plot_x=do_plot_x,
                                                        do_plot_z=do_plot_z,
                                                        histo_data_x_ff=HistogramData(),
                                                        histo_data_z_ff=HistogramData(),
                                                        histo_data_x_nf=HistogramData(),
                                                        histo_data_z_nf=HistogramData(),
                                                        profile=profile)

                    if not histo_data_x_ff.bins is None:
                        self.current_histo_data_x_ff = HistogramDataCollection(
                            histo_data_x_ff)
                    if not histo_data_z_ff.bins is None:
                        self.current_histo_data_z_ff = HistogramDataCollection(
                            histo_data_z_ff)
                    if not histo_data_x_nf.bins is None:
                        self.current_histo_data_x_nf = HistogramDataCollection(
                            histo_data_x_nf)
                    if not histo_data_z_nf.bins is None:
                        self.current_histo_data_z_nf = HistogramDataCollection(
                            histo_data_z_nf)

                    stats_x_ff = StatisticalDataCollection(histo_data_x_ff)
                    stats_z_ff = StatisticalDataCollection(histo_data_z_ff)
                    stats_x_nf = StatisticalDataCollection(histo_data_x_nf)
                    stats_z_nf = StatisticalDataCollection(histo_data_z_nf)

                    input_parameters.ghy_calcType = self.ghy_calcType + 3

                    for file in self.ghy_files:
                        shadow_beam = self.input_beam.duplicate()

                        history_entry = shadow_beam.getOEHistory(
                            shadow_beam._oe_number)
                        shadow_oe = history_entry._shadow_oe_start  # changes to the original object!

                        shadow_oe._oe.F_RIPPLE = 1
                        shadow_oe._oe.F_G_S = 2

                        file = congruence.checkFile(file)
                        ShadowCongruence.checkErrorProfileFile(file)

                        shadow_oe._oe.FILE_RIP = bytes(file, 'utf-8')

                        input_parameters.shadow_beam = shadow_beam

                        calculation_parameters = hybrid_control.hy_run(
                            input_parameters)

                        if do_plot_x or do_plot_z:
                            self.setStatusMessage("Plotting Results")

                        profile += 1

                        histo_data_x_ff, \
                        histo_data_z_ff, \
                        histo_data_x_nf, \
                        histo_data_z_nf = self.plot_results(calculation_parameters,
                                                            do_nf,
                                                            do_plot_x,
                                                            do_plot_z,
                                                            histo_data_x_ff,
                                                            histo_data_z_ff,
                                                            histo_data_x_nf,
                                                            histo_data_z_nf,
                                                            profile)

                        if not histo_data_x_ff.bins is None:
                            self.current_histo_data_x_ff.add_histogram_data(
                                histo_data_x_ff)
                        if not histo_data_z_ff.bins is None:
                            self.current_histo_data_z_ff.add_histogram_data(
                                histo_data_z_ff)
                        if not histo_data_x_nf.bins is None:
                            self.current_histo_data_x_nf.add_histogram_data(
                                histo_data_x_nf)
                        if not histo_data_z_nf.bins is None:
                            self.current_histo_data_z_nf.add_histogram_data(
                                histo_data_z_nf)

                        stats_x_ff.add_statistical_data(histo_data_x_ff)
                        stats_z_ff.add_statistical_data(histo_data_z_ff)
                        stats_x_nf.add_statistical_data(histo_data_x_nf)
                        stats_z_nf.add_statistical_data(histo_data_z_nf)

                    self.current_stats_x_ff = stats_x_ff
                    self.current_stats_z_ff = stats_z_ff
                    self.current_stats_x_nf = stats_x_nf
                    self.current_stats_z_nf = stats_z_nf

                    self.add_empty_curves(do_nf, do_plot_x, do_plot_z,
                                          histo_data_x_ff, histo_data_x_nf,
                                          histo_data_z_ff, histo_data_z_nf)

                    self.plot_stats(
                        do_nf,
                        do_plot_x,
                        do_plot_z,
                        stats_x_ff,
                        stats_z_ff,
                        stats_x_nf,
                        stats_z_nf,
                    )

                else:
                    raise Exception("Input Beam with no good rays")
            else:
                raise Exception("Empty Input Beam")
        except Exception as exception:
            QMessageBox.critical(self, "Error", str(exception), QMessageBox.Ok)

            if self.IS_DEVELOP: raise exception

        self.setStatusMessage("")
        self.progressBarFinished()
Exemplo n.º 34
0
def sh_readsh(shfilename):
    image_beam = ShadowBeam()
    image_beam.loadFromFile(congruence.checkFile(shfilename))

    return read_shadow_beam(image_beam)
Exemplo n.º 35
0
    def check_fields(self):

        if self.SOURCE == 1:
            self.ENER_MIN = congruence.checkPositiveNumber(self.ENER_MIN, "Energy from")
            self.ENER_MAX = congruence.checkStrictlyPositiveNumber(self.ENER_MAX, "Energy to")
            congruence.checkLessThan(self.ENER_MIN, self.ENER_MAX, "Energy from", "Energy to")
            self.NPOINTS = congruence.checkStrictlyPositiveNumber(self.ENER_N, "Energy Points")
        elif self.SOURCE == 2:
            congruence.checkFile(self.SOURCE_FILE)

        if self.NELEMENTS >= 1:
            self.EL1_FOR = congruence.checkEmptyString(self.EL1_FOR, "1st oe formula")

            if self.EL1_FLAG == 0: # filter
                self.EL1_THI = congruence.checkStrictlyPositiveNumber(self.EL1_THI, "1st oe filter thickness")
            elif self.EL1_FLAG == 1: # mirror
                self.EL1_ANG = congruence.checkStrictlyPositiveNumber(self.EL1_ANG, "1st oe mirror angle")
                self.EL1_ROU = congruence.checkPositiveNumber(self.EL1_ROU, "1st oe mirror roughness")

            if not self.EL1_DEN.strip() == "?":
                self.EL1_DEN = str(congruence.checkStrictlyPositiveNumber(float(congruence.checkNumber(self.EL1_DEN, "1st oe density")), "1st oe density"))

        if self.NELEMENTS >= 2:
            self.EL2_FOR = congruence.checkEmptyString(self.EL2_FOR, "2nd oe formula")

            if self.EL2_FLAG == 0: # filter
                self.EL2_THI = congruence.checkStrictlyPositiveNumber(self.EL2_THI, "2nd oe filter thickness")
            elif self.EL2_FLAG == 1: # mirror
                self.EL2_ANG = congruence.checkStrictlyPositiveNumber(self.EL2_ANG, "2nd oe mirror angle")
                self.EL2_ROU = congruence.checkPositiveNumber(self.EL2_ROU, "2nd oe mirror roughness")

            if not self.EL2_DEN.strip() == "?":
                self.EL2_DEN = str(congruence.checkStrictlyPositiveNumber(float(congruence.checkNumber(self.EL2_DEN, "2nd oe density")), "2nd oe density"))

        if self.NELEMENTS >= 3:
            self.EL3_FOR = congruence.checkEmptyString(self.EL3_FOR, "3rd oe formula")

            if self.EL3_FLAG == 0: # filter
                self.EL3_THI = congruence.checkStrictlyPositiveNumber(self.EL3_THI, "3rd oe filter thickness")
            elif self.EL3_FLAG == 1: # mirror
                self.EL3_ANG = congruence.checkStrictlyPositiveNumber(self.EL3_ANG, "3rd oe mirror angle")
                self.EL3_ROU = congruence.checkPositiveNumber(self.EL3_ROU, "3rd oe mirror roughness")

            if not self.EL3_DEN.strip() == "?":
                self.EL3_DEN = str(congruence.checkStrictlyPositiveNumber(float(congruence.checkNumber(self.EL3_DEN, "3rd oe density")), "3rd oe density"))

        if self.NELEMENTS >= 4:
            self.EL4_FOR = congruence.checkEmptyString(self.EL4_FOR, "4th oe formula")

            if self.EL4_FLAG == 0: # filter
                self.EL4_THI = congruence.checkStrictlyPositiveNumber(self.EL4_THI, "4th oe filter thickness")
            elif self.EL4_FLAG == 1: # mirror
                self.EL4_ANG = congruence.checkStrictlyPositiveNumber(self.EL4_ANG, "4th oe mirror angle")
                self.EL4_ROU = congruence.checkPositiveNumber(self.EL4_ROU, "4th oe mirror roughness")

            if not self.EL4_DEN.strip() == "?":

                self.EL4_DEN = str(congruence.checkStrictlyPositiveNumber(float(congruence.checkNumber(self.EL4_DEN, "4th oe density")), "4th oe density"))

        if self.NELEMENTS >= 5:
            self.EL5_FOR = congruence.checkEmptyString(self.EL5_FOR, "5th oe formula")

            if self.EL5_FLAG == 0: # filter
                self.EL5_THI = congruence.checkStrictlyPositiveNumber(self.EL5_THI, "5th oe filter thickness")
            elif self.EL5_FLAG == 1: # mirror
                self.EL5_ANG = congruence.checkStrictlyPositiveNumber(self.EL5_ANG, "5th oe mirror angle")
                self.EL5_ROU = congruence.checkPositiveNumber(self.EL5_ROU, "5th oe mirror roughness")

            if not self.EL5_DEN.strip() == "?":
                self.EL5_DEN = str(congruence.checkStrictlyPositiveNumber(float(congruence.checkNumber(self.EL5_DEN, "5th oe density")), "5th oe density"))
Exemplo n.º 36
0
    def check_fields(self):

        if self.SOURCE == 1:
            self.ENER_MIN = congruence.checkPositiveNumber(self.ENER_MIN, "Energy from")
            self.ENER_MAX = congruence.checkStrictlyPositiveNumber(self.ENER_MAX, "Energy to")
            congruence.checkLessThan(self.ENER_MIN, self.ENER_MAX, "Energy from", "Energy to")
            self.NPOINTS = congruence.checkStrictlyPositiveNumber(self.ENER_N, "Energy Points")
        elif self.SOURCE == 2:
            congruence.checkFile(self.SOURCE_FILE)

        if self.NELEMENTS >= 1:
            self.EL1_FOR = congruence.checkEmptyString(self.EL1_FOR, "1st oe formula")

            if self.EL1_FLAG == 0: # filter
                self.EL1_THI = congruence.checkStrictlyPositiveNumber(self.EL1_THI, "1st oe filter thickness")
            elif self.EL1_FLAG == 1: # mirror
                self.EL1_ANG = congruence.checkStrictlyPositiveNumber(self.EL1_ANG, "1st oe mirror angle")
                self.EL1_ROU = congruence.checkPositiveNumber(self.EL1_ROU, "1st oe mirror roughness")

            if not self.EL1_DEN.strip() == "?":
                self.EL1_DEN = str(congruence.checkStrictlyPositiveNumber(float(congruence.checkNumber(self.EL1_DEN, "1st oe density")), "1st oe density"))

        if self.NELEMENTS >= 2:
            self.EL2_FOR = congruence.checkEmptyString(self.EL2_FOR, "2nd oe formula")

            if self.EL2_FLAG == 0: # filter
                self.EL2_THI = congruence.checkStrictlyPositiveNumber(self.EL2_THI, "2nd oe filter thickness")
            elif self.EL2_FLAG == 1: # mirror
                self.EL2_ANG = congruence.checkStrictlyPositiveNumber(self.EL2_ANG, "2nd oe mirror angle")
                self.EL2_ROU = congruence.checkPositiveNumber(self.EL2_ROU, "2nd oe mirror roughness")

            if not self.EL2_DEN.strip() == "?":
                self.EL2_DEN = str(congruence.checkStrictlyPositiveNumber(float(congruence.checkNumber(self.EL2_DEN, "2nd oe density")), "2nd oe density"))

        if self.NELEMENTS >= 3:
            self.EL3_FOR = congruence.checkEmptyString(self.EL3_FOR, "3rd oe formula")

            if self.EL3_FLAG == 0: # filter
                self.EL3_THI = congruence.checkStrictlyPositiveNumber(self.EL3_THI, "3rd oe filter thickness")
            elif self.EL3_FLAG == 1: # mirror
                self.EL3_ANG = congruence.checkStrictlyPositiveNumber(self.EL3_ANG, "3rd oe mirror angle")
                self.EL3_ROU = congruence.checkPositiveNumber(self.EL3_ROU, "3rd oe mirror roughness")

            if not self.EL3_DEN.strip() == "?":
                self.EL3_DEN = str(congruence.checkStrictlyPositiveNumber(float(congruence.checkNumber(self.EL3_DEN, "3rd oe density")), "3rd oe density"))

        if self.NELEMENTS >= 4:
            self.EL4_FOR = congruence.checkEmptyString(self.EL4_FOR, "4th oe formula")

            if self.EL4_FLAG == 0: # filter
                self.EL4_THI = congruence.checkStrictlyPositiveNumber(self.EL4_THI, "4th oe filter thickness")
            elif self.EL4_FLAG == 1: # mirror
                self.EL4_ANG = congruence.checkStrictlyPositiveNumber(self.EL4_ANG, "4th oe mirror angle")
                self.EL4_ROU = congruence.checkPositiveNumber(self.EL4_ROU, "4th oe mirror roughness")

            if not self.EL4_DEN.strip() == "?":

                self.EL4_DEN = str(congruence.checkStrictlyPositiveNumber(float(congruence.checkNumber(self.EL4_DEN, "4th oe density")), "4th oe density"))

        if self.NELEMENTS >= 5:
            self.EL5_FOR = congruence.checkEmptyString(self.EL5_FOR, "5th oe formula")

            if self.EL5_FLAG == 0: # filter
                self.EL5_THI = congruence.checkStrictlyPositiveNumber(self.EL5_THI, "5th oe filter thickness")
            elif self.EL5_FLAG == 1: # mirror
                self.EL5_ANG = congruence.checkStrictlyPositiveNumber(self.EL5_ANG, "5th oe mirror angle")
                self.EL5_ROU = congruence.checkPositiveNumber(self.EL5_ROU, "5th oe mirror roughness")

            if not self.EL5_DEN.strip() == "?":
                self.EL5_DEN = str(congruence.checkStrictlyPositiveNumber(float(congruence.checkNumber(self.EL5_DEN, "5th oe density")), "5th oe density"))
Exemplo n.º 37
0
import numpy, sys, os
import xraylib

from orangecontrib.xoppy.util.xoppy_xraylib_util import f1f2_calc

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)

#file_name = None
file_name = "/Users/labx/Desktop/AnnaB/efficiencies.asc"

try:
    if file_name is None:
        file_name = oasysgui.selectFileFromDialog(None, None, "Open ASC file")

    congruence.checkFile(file_name)

    data = numpy.loadtxt(file_name, skiprows=1)

    energies = data[:, 0]
    angles = numpy.radians((180 - data[:, 3]) / 2)
    reflectivities = numpy.zeros((energies.size, angles.size))

    density = xraylib.ElementDensity(xraylib.SymbolToAtomicNumber("Au"))

    for i, itheta in enumerate(angles):
        reflectivities[:, i] = f1f2_calc("Au",
                                         energies,
                                         itheta,
                                         F=10,
                                         rough=0.0,