Ejemplo 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.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)
Ejemplo n.º 2
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.checkUrl(self.FILE)
        elif self.FIELD == 2:
            congruence.checkUrl(self.FILE)
Ejemplo n.º 3
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.checkUrl(self.FILE)
        elif self.FIELD == 2:
            congruence.checkUrl(self.FILE)
Ejemplo n.º 4
0
    def runShadowSource(self):
        #self.error(self.error_id)
        self.setStatusMessage("")
        self.progressBarInit()

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

        try:
            self.checkFields()

            ###########################################
            # TODO: TO BE ADDED JUST IN CASE OF BROKEN
            #       ENVIRONMENT: MUST BE FOUND A PROPER WAY
            #       TO TEST SHADOW
            self.fixWeirdShadowBug()
            ###########################################

            wigFile = bytes(congruence.checkFileName("xshwig.sha"), 'utf-8')

            if self.type_combo == 0:
                inData = ""
            elif self.type_combo == 1:
                inData = congruence.checkUrl(self.file_with_b_vs_y)
            elif self.type_combo == 2:
                inData = congruence.checkUrl(self.file_with_harmonics)

            self.progressBarSet(10)
            #self.information(0, "Calculate electron trajectory")

            self.shadow_output.setText("")

            self.setStatusMessage("Calculate electron trajectory")


            (traj, pars) = srfunc.wiggler_trajectory(b_from=self.type_combo,
                                                     inData=inData,
                                                     nPer=self.number_of_periods,
                                                     nTrajPoints=501,
                                                     ener_gev=self.energy,
                                                     per=self.id_period,
                                                     kValue=self.k_value,
                                                     trajFile=congruence.checkFileName("tmp.traj"),
                                                     shift_x_flag=self.shift_x_flag,
                                                     shift_x_value=self.shift_x_value,
                                                     shift_betax_flag=self.shift_betax_flag,
                                                     shift_betax_value=self.shift_betax_value)

            #
            # calculate cdf and write file for Shadow/Source
            #

            self.progressBarSet(20)
            #self.information(0, "Calculate cdf and write file for Shadow/Source")
            self.setStatusMessage("Calculate cdf and write file for Shadow/Source")

            srfunc.wiggler_cdf(traj,
                               enerMin=self.e_min,
                               enerMax=self.e_max,
                               enerPoints=1001,
                               outFile=wigFile,
                               elliptical=False)

            #self.information(0, "CDF written to file %s \n"%(wigFile))
            self.setStatusMessage("CDF written to file %s \n"%(str(wigFile)))

            self.progressBarSet(40)

            #self.information(0, "Set the wiggler parameters in the wiggler container")
            self.setStatusMessage("Set the wiggler parameters in the wiggler container")

            shadow_src = ShadowSource.create_wiggler_src()

            self.populateFields(shadow_src)

            shadow_src.src.FILE_TRAJ = wigFile


            self.progressBarSet(50)

            self.setStatusMessage("Running Shadow/Source")

            write_begin_file, write_start_file, write_end_file = self.get_write_file_options()

            beam_out = ShadowBeam.traceFromSource(shadow_src,
                                                  write_begin_file=write_begin_file,
                                                  write_start_file=write_start_file,
                                                  write_end_file=write_end_file)

            if self.trace_shadow:
                grabber.stop()

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

            #self.information(0, "Plotting Results")
            self.setStatusMessage("Plotting Results")

            self.progressBarSet(80)

            self.plot_results(beam_out, progressBarValue=80)

            self.setStatusMessage("Plotting Wiggler Data")

            self.plot_wiggler_results()

            #self.information()
            self.setStatusMessage("")

            self.send("Beam", beam_out)

            #
            # create python script for the preprocessors and display in the standard output
            #
            dict_parameters = {
                "b_from"               : self.type_combo,
                "inData"               : inData,
                "nPer"                 : self.number_of_periods,
                "nTrajPoints"          : 501,
                "ener_gev"             : self.energy,
                "per"                  : self.id_period,
                "kValue"               : self.k_value,
                "trajFile"             : "tmp.traj",
                "shift_x_flag"         : self.shift_x_flag,
                "shift_x_value"        : self.shift_x_value,
                "shift_betax_flag"     : self.shift_betax_flag,
                "shift_betax_value"    : self.shift_betax_value,
                "enerMin"              : self.e_min,
                "enerMax"              : self.e_max,
                "enerPoints"           : 1001,
                "outFile"              : wigFile,
                "elliptical"           : False,
                "electron_current_mA"  : self.electron_current,
            }

            # write python script in standard output
            print(self.script_template().format_map(dict_parameters))

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

            #self.error_id = self.error_id + 1
            #self.error(self.error_id, "Exception occurred: " + str(exception))


        self.progressBarFinished()