def define_source(): # # initialize shadow3 source (oe0) and beam # oe0 = Shadow.Source() # Define variables. See https://raw.githubusercontent.com/oasys-kit/shadow3/master/docs/source.nml oe0.FDISTR = 3 oe0.HDIV1 = 0.0 oe0.HDIV2 = 0.0 oe0.IDO_VX = 0 oe0.IDO_VZ = 0 oe0.IDO_X_S = 0 oe0.IDO_Y_S = 0 oe0.IDO_Z_S = 0 oe0.ISTAR1 = 5676561 oe0.NPOINT = 100000 oe0.PH1 = 1.0 oe0.SIGDIX = 1e-06 oe0.SIGDIZ = 1e-06 oe0.SIGMAX = 5e-06 oe0.SIGMAZ = 5e-06 oe0.VDIV1 = 0.0 oe0.VDIV2 = 0.0 return oe0
def shadow_source(): iwrite = 0 beam = Shadow.Beam() oe0 = Shadow.Source() oe0.FDISTR = 3 oe0.F_PHOT = 0 oe0.HDIV1 = 1.0 oe0.HDIV2 = 1.0 oe0.IDO_VX = 0 oe0.IDO_VZ = 0 oe0.IDO_X_S = 0 oe0.IDO_Y_S = 0 oe0.IDO_Z_S = 0 oe0.NPOINT = 25000 oe0.PH1 = 10000.0 oe0.SIGDIX = 8.84999972e-05 oe0.SIGDIZ = 7.1999998e-06 oe0.SIGMAX = 5.7000001e-05 oe0.SIGMAZ = 1.04e-05 oe0.VDIV1 = 1.0 oe0.VDIV2 = 1.0 if iwrite: oe0.write("start.00") beam.genSource(oe0) if iwrite: oe0.write("end.00") beam.write("begin.dat") return beam
def shadow_source(): iwrite = 0 beam = Shadow.Beam() oe0 = Shadow.Source() oe0.FDISTR = 1 oe0.FSOUR = 1 oe0.F_PHOT = 0 oe0.HDIV1 = 0.0 oe0.HDIV2 = 0.0 oe0.IDO_VX = 0 oe0.IDO_VZ = 0 oe0.IDO_X_S = 0 oe0.IDO_Y_S = 0 oe0.IDO_Z_S = 0 oe0.PH1 = 1000.0 oe0.VDIV1 = 0.0 oe0.VDIV2 = 0.0 if iwrite: oe0.write("start.00") beam.genSource(oe0) if iwrite: oe0.write("end.00") beam.write("begin.dat") return beam
def create_src(cls): self = cls.__new__(ShadowSource, src=Shadow.Source()) self.src.OE_NUMBER = 0 self.src.FILE_TRAJ = bytes("NONESPECIFIED", 'utf-8') self.src.FILE_SOURCE = bytes("NONESPECIFIED", 'utf-8') self.src.FILE_BOUND = bytes("NONESPECIFIED", 'utf-8') return self
def run_shadow_source(): # # Python script to run shadow3. Created automatically with ShadowTools.make_python_script_from_list(). # import Shadow import numpy # write (1) or not (0) SHADOW files start.xx end.xx star.xx iwrite = 0 # # initialize shadow3 source (oe0) and beam # beam = Shadow.Beam() oe0 = Shadow.Source() oe1 = Shadow.OE() oe2 = Shadow.OE() # # Define variables. See meaning of variables in: # https://raw.githubusercontent.com/srio/shadow3/master/docs/source.nml # https://raw.githubusercontent.com/srio/shadow3/master/docs/oe.nml # oe0.FDISTR = 1 oe0.FSOUR = 0 oe0.F_PHOT = 0 oe0.HDIV1 = 0.005 oe0.HDIV2 = 0.005 oe0.IDO_VX = 0 oe0.IDO_VZ = 0 oe0.IDO_X_S = 0 oe0.IDO_Y_S = 0 oe0.IDO_Z_S = 0 oe0.NPOINT = 10000 oe0.PH1 = 1000.0 oe0.VDIV1 = 0.05 oe0.VDIV2 = 0.05 # Run SHADOW to create the source if iwrite: oe0.write("start.00") beam.genSource(oe0) if iwrite: oe0.write("end.00") beam.write("begin.dat") # # run optical element 1 return beam
def get_beam(): # # Python script to run shadow3. Created automatically with ShadowTools.make_python_script_from_list(). # # write (1) or not (0) SHADOW files start.xx end.xx star.xx iwrite = 0 # # initialize shadow3 source (oe0) and beam # beam = Shadow.Beam() oe0 = Shadow.Source() oe1 = Shadow.OE() # # Define variables. See meaning of variables in: # https://raw.githubusercontent.com/srio/shadow3/master/docs/source.nml # https://raw.githubusercontent.com/srio/shadow3/master/docs/oe.nml # oe0.FSOUR = 1 oe0.HDIV1 = 1e-08 oe0.HDIV2 = 1e-08 oe0.IDO_VX = 0 oe0.IDO_VZ = 0 oe0.IDO_X_S = 0 oe0.IDO_Y_S = 0 oe0.IDO_Z_S = 0 oe0.PH1 = 1.54 oe0.VDIV1 = 1e-08 oe0.VDIV2 = 1e-08 oe0.WXSOU = 0.08 oe0.WZSOU = 0.08 #Run SHADOW to create the source if iwrite: oe0.write("start.00") beam.genSource(oe0) if iwrite: oe0.write("end.00") beam.write("begin.dat") return beam
def test_1(capsys): from sys import stderr import Shadow beam = Shadow.Beam() src = Shadow.Source() assert 2 == src.FDISTR, \ 'Basic value for Source' # Would like to capture stdout, but too complex with extensions. # Probably extension needs to call a python output method. beam.genSource(src) assert 5000 == beam.nrays(), \ 'Basic method call for Beam' oe = Shadow.OE() oe.D_SPACING = 3 assert 3 == oe.D_SPACING, \ 'Basic assignment for OE' beam.traceOE(oe, 1)
def create_start_files(): # write (1) or not (0) SHADOW files start.xx end.xx star.xx iwrite = 1 # # initialize shadow3 source (oe0) and beam # oe0 = Shadow.Source() oe1 = Shadow.OE() # # Define variables. See meaning of variables in: # https://raw.githubusercontent.com/srio/shadow3/master/docs/source.nml # https://raw.githubusercontent.com/srio/shadow3/master/docs/oe.nml # oe0.FDISTR = 3 oe0.F_COLOR = 3 oe0.F_PHOT = 0 oe0.HDIV1 = 0.0 oe0.HDIV2 = 0.0 oe0.IDO_VX = 0 oe0.IDO_VZ = 0 oe0.IDO_X_S = 0 oe0.IDO_Y_S = 0 oe0.IDO_Z_S = 0 oe0.PH1 = 5000.0 oe0.PH2 = 45000.0 oe0.SIGDIX = 8.84999972e-05 oe0.SIGDIZ = 7.1999998e-06 oe0.SIGMAX = 0.0057000001 oe0.SIGMAZ = 0.00104 oe0.VDIV1 = 0.0 oe0.VDIV2 = 0.0 oe1.DUMMY = 1.0 oe1.FMIRR = 3 oe1.T_IMAGE = 1000.0 oe1.T_INCIDENCE = 89.885408 oe1.T_REFLECTION = 89.885408 oe1.T_SOURCE = 3000.0 oe0.write("start.00") oe1.write("start.01")
def shadow_src_beam(n_rays=10000, ran_seed=15829, dist_type=3, sigx=4.42e-05, sigz=2.385e-05, sigdix=3.52e-05, sigdiz=2.875e-05, hdiv1=0.0, hdiv2=0.0, vdiv1=0.0, vdiv2=0.0, ph_energy=1e3): """ This function computes a shadow beam object from a specified source. """ source = Shadow.Source() beam = Shadow.Beam() source.NPOINT = n_rays # no. of rays (1 on-axis ray, 4 deviations) source.ISTAR1 = ran_seed #source.FSOUR = src_type # source type (0 = point, 3 = Gsn) #source.WXSOU = wx #source.WZSOU = wz source.SIGMAX = sigx source.SIGMAZ = sigz source.FDISTR = dist_type source.SIGDIX = sigdix source.SIGDIZ = sigdiz source.F_POLAR = 0 source.HDIV1 = hdiv1 source.HDIV2 = hdiv2 source.VDIV1 = vdiv1 source.VDIV2 = vdiv2 source.IDO_VX = 0 source.IDO_VZ = 0 source.IDO_X_S = 0 source.IDO_Y_S = 0 source.IDO_Z_S = 0 source.F_PHOT = 0 source.PH1 = ph_energy beam.genSource(source) return beam
def shadowSourceFromSourceGaussian(self, source_gaussian): source = Shadow.Source() # TODO: FIX!!! source.FDISTR = 3 source.HDIV1 = 1.0 source.HDIV2 = 1.0 source.VDIV1 = 1.0 source.VDIV2 = 1.0 source.F_PHOT = 0 source.NPOINT = source_gaussian._optical_element.driverSettings( ).valueByName("Number of rays") source.SIGMAX = source_gaussian.sigmaX() source.SIGMAZ = source_gaussian.sigmaY() source.SIGDIX = source_gaussian.sigmaXPrime() source.SIGDIZ = source_gaussian.sigmaYPrime() source.PH1 = source_gaussian.energy() return source
def define_source(): # # initialize shadow3 source (oe0) and beam # oe0 = Shadow.Source() # Define variables. See https://raw.githubusercontent.com/oasys-kit/shadow3/master/docs/source.nml oe0.BENER = 6.04 oe0.EPSI_X = 3.8e-07 oe0.EPSI_Z = 3.8e-09 oe0.FDISTR = 4 oe0.FSOURCE_DEPTH = 4 oe0.F_COLOR = 3 oe0.F_PHOT = 0 oe0.HDIV1 = 0.0005 oe0.HDIV2 = 0.0005 oe0.ISTAR1 = 5676561 oe0.NCOL = 0 oe0.NPOINT = 50000 oe0.N_COLOR = 0 oe0.PH1 = 5000.0 oe0.PH2 = 100000.0 oe0.POL_DEG = 0.0 oe0.R_ALADDIN = 25.1772 oe0.R_MAGNET = 25.1772 oe0.SIGDIX = 0.0 oe0.SIGDIZ = 0.0 oe0.SIGMAX = 0.0078 oe0.SIGMAY = 0.0 oe0.SIGMAZ = 0.0036 oe0.VDIV1 = 1.0 oe0.VDIV2 = 1.0 oe0.WXSOU = 0.0 oe0.WYSOU = 0.0 oe0.WZSOU = 0.0 return oe0
# # -More information in these files available in the source distribution: # README_PYTHON.txt General information on SHADOW-python # source.nml the description of the variables in Shadow.Source # oe.nml the description of the variables in Shadow.OE # import Shadow # write (1) or not (0) SHADOW files start.xx end.xx star.xx iwrite = 0 # # initialize elements # source = Shadow.Source() oe = Shadow.OE() beam = Shadow.Beam() # # Source definition: point source with flat divergence # source.NPOINT = 30000 #number of rays source.ISTAR1 = 10001 #seed source.FSOUR = 0 #point source source.FDISTR = 1 #flat distribution in divergences, and values source.HDIV1 = 0.05 source.HDIV2 = 0.05 source.VDIV1 = 0.01 source.VDIV2 = 0.01 #monochromatic: 0 eV
def run_shadow3(): # # Python script to run shadow3. Created automatically with ShadowTools.make_python_script_from_list(). # import Shadow import numpy # write (1) or not (0) SHADOW files start.xx end.xx star.xx iwrite = 0 # # initialize shadow3 source (oe0) and beam # source = Shadow.Beam() beam = Shadow.Beam() oe0 = Shadow.Source() oe1 = Shadow.OE() # # Define variables. See meaning of variables in: # https://raw.githubusercontent.com/srio/shadow3/master/docs/source.nml # https://raw.githubusercontent.com/srio/shadow3/master/docs/oe.nml # oe0.CONE_MAX = 0.05 oe0.FDISTR = 5 oe0.FSOUR = 0 oe0.IDO_VX = 0 oe0.IDO_VZ = 0 oe0.IDO_X_S = 0 oe0.IDO_Y_S = 0 oe0.IDO_Z_S = 0 oe0.NPOINT = 25000 oe0.PH1 = 1.47642 oe1.DUMMY = 1.0 oe1.FILE_SCR_EXT = numpy.array( [b'grid.pol', b'', b'', b'', b'', b'', b'', b'', b'', b'']) oe1.FWRITE = 3 oe1.F_REFRAC = 2 oe1.F_SCREEN = 1 oe1.I_SLIT = numpy.array([1, 0, 0, 0, 0, 0, 0, 0, 0, 0]) oe1.I_STOP = numpy.array([1, 0, 0, 0, 0, 0, 0, 0, 0, 0]) oe1.K_SLIT = numpy.array([2, 0, 0, 0, 0, 0, 0, 0, 0, 0]) oe1.N_SCREEN = 1 oe1.T_IMAGE = 5.0 oe1.T_INCIDENCE = 0.0 oe1.T_REFLECTION = 180.0 oe1.T_SOURCE = 322.971 # Run SHADOW to create the source if iwrite: oe0.write("start.00") source.genSource(oe0) beam.genSource(oe0) if iwrite: oe0.write("end.00") beam.write("begin.dat") # # run optical element 1 # print(" Running optical element: %d" % (1)) if iwrite: oe1.write("start.01") beam.traceOE(oe1, 1) if iwrite: oe1.write("end.01") beam.write("star.01") # Shadow.ShadowTools.plotxy(beam, 1, 3, nbins=101, nolost=1, title="Real space") # Shadow.ShadowTools.plotxy(beam,1,4,nbins=101,nolost=1,title="Phase space X") # Shadow.ShadowTools.plotxy(beam,3,6,nbins=101,nolost=1,title="Phase space Z") return source, beam
def run_shadow3_from_start_files(iwrite=0): # # initialize shadow3 source (oe0) and beam # beam = Shadow.Beam() oe0 = Shadow.Source() oe0_before_run = Shadow.Source() # TODO: this is a turn-around for the Linux bug... if platform.system() == "Linux": str = open('start.00', 'r').read() lines = str.split("\n") for line in lines: command = "oe0." + line try: exec(command) except: print("run_shadow3_from_start_files: Failed to exec: %s" % command) command = "oe0_before_run." + line try: exec(command) except: print("run_shadow3_from_start_files: Failed to exec: %s" % command) else: oe0.load("start.00") oe0_before_run.load("start.00") beam.genSource(oe0) if iwrite: oe0.write("end.00") beam.write("begin.dat") beam_source = beam.duplicate() # return beam,beam.rays.T.copy() oe1 = Shadow.OE() oe1_before_run = Shadow.OE() if platform.system() == "Linux": str = open('start.01', 'r').read() lines = str.split("\n") for line in lines: command1 = "oe1."+line.replace("(1)","[0]")\ .replace("(2)","[1]")\ .replace("(3)","[2]")\ .replace("(4)","[3]")\ .replace("(5)","[4]")\ .replace("(6)","[5]")\ .replace("(7)","[6]")\ .replace("(8)","[7]")\ .replace("(9)","[8]")\ .replace("(10)","[9]") command2 = "oe1_before_run."+line.replace("(1)","[0]")\ .replace("(2)","[1]")\ .replace("(3)","[2]")\ .replace("(4)","[3]")\ .replace("(5)","[4]")\ .replace("(6)","[5]")\ .replace("(7)","[6]")\ .replace("(8)","[7]")\ .replace("(9)","[8]")\ .replace("(10)","[9]") try: exec(command1) except: print("run_shadow3_from_start_files: Failed to exec: %s" % command1) try: exec(command2) except: print("run_shadow3_from_start_files: Failed to exec: %s" % command2) else: oe1.load("start.01") oe1_before_run.load("start.01") beam.traceOE(oe1, 1) if iwrite: oe1.write("end.01") beam.write("star.01") return beam_source, beam, oe0_before_run, oe1_before_run
def run_example_attenuator(user_units_to_cm=1.0, npoint=5000, iwrite=0): # # Python script to run shadow3. Created automatically with ShadowTools.make_python_script_from_list(). # # # initialize shadow3 source (oe0) and beam # beam = Shadow.Beam() oe0 = Shadow.Source() oe1 = Shadow.OE() # # Define variables. See meaning of variables in: # https://raw.githubusercontent.com/srio/shadow3/master/docs/source.nml # https://raw.githubusercontent.com/srio/shadow3/master/docs/oe.nml # oe0.FDISTR = 1 oe0.FSOUR = 0 oe0.FSOURCE_DEPTH = 0 oe0.F_PHOT = 0 oe0.PH1 = 10000.0 oe0.ISTAR1 = 1234567 oe0.NPOINT = npoint oe1.F_REFRAC = 2 oe1.DUMMY = user_units_to_cm oe1.T_SOURCE = 100.0 / user_units_to_cm oe1.T_IMAGE = 100.0 / user_units_to_cm oe1.T_INCIDENCE = 0.0 oe1.T_REFLECTION = 180.0 oe1.F_SCREEN = 1 oe1.N_SCREEN = 1 oe1.I_ABS = numpy.array([1, 0, 0, 0, 0, 0, 0, 0, 0, 0]) oe1.FILE_ABS = numpy.array( [b'prerefl.dat', b'', b'', b'', b'', b'', b'', b'', b'', b'']) oe1.THICK = numpy.array([ 10e-4 / user_units_to_cm, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]) #Run SHADOW to create the source if iwrite: oe0.write("start.00") beam.genSource(oe0) if iwrite: oe0.write("end.00") beam.write("begin.dat") # #run optical element 1 # print(" Running optical element: %d" % (1)) if iwrite: oe1.write("start.01") beam.traceOE(oe1, 1) if iwrite: oe1.write("end.01") beam.write("star.01") print(oe1.mirinfo()) return beam
def run_source_wiggler(): from srxraylib.sources import srfunc (traj, pars) = srfunc.wiggler_trajectory(b_from=1, inData="/home/manuel/Oasys/BM_only7.b", nPer=1, nTrajPoints=501, ener_gev=2.0, per=0.01, kValue=1.0, trajFile="tmp.traj", shift_x_flag=4, shift_x_value=0.042, shift_betax_flag=4, shift_betax_value=0.035) # # calculate cdf and write file for Shadow/Source # srfunc.wiggler_cdf(traj, enerMin=1000.0, enerMax=1000.1, enerPoints=1001, outFile=b'/home/manuel/Oasys/xshwig.sha', elliptical=False) calculate_spectrum = False if calculate_spectrum: e, f, w = srfunc.wiggler_spectrum(traj, enerMin=1000.0, enerMax=1000.1, nPoints=500, electronCurrent=500.0 * 1e-3, outFile="spectrum.dat", elliptical=False) from srxraylib.plot.gol import plot plot(e, f, xlog=False, ylog=False, show=False, xtitle="Photon energy [eV]", ytitle="Flux [Photons/s/0.1%bw]", title="Flux") plot(e, w, xlog=False, ylog=False, show=True, xtitle="Photon energy [eV]", ytitle="Spectral Power [E/eV]", title="Spectral Power") # # end script # # write (1) or not (0) SHADOW files start.xx end.xx star.xx iwrite = 0 # # initialize shadow3 source (oe0) and beam # beam = Shadow.Beam() oe0 = Shadow.Source() # # Define variables. See meaning of variables in: # https://raw.githubusercontent.com/srio/shadow3/master/docs/source.nml # https://raw.githubusercontent.com/srio/shadow3/master/docs/oe.nml # oe0.BENER = 2.0 oe0.CONV_FACT = 1.0 oe0.EPSI_X = 70e-12 oe0.EPSI_Z = 70e-12 oe0.FDISTR = 0 oe0.FILE_TRAJ = b'/home/manuel/Oasys/xshwig.sha' oe0.FSOUR = 0 oe0.FSOURCE_DEPTH = 0 oe0.F_COLOR = 0 oe0.F_PHOT = 0 oe0.F_WIGGLER = 1 oe0.HDIV1 = 1.0 oe0.HDIV2 = 1.0 oe0.IDO_VX = 0 oe0.IDO_VZ = 0 oe0.IDO_X_S = 0 oe0.IDO_Y_S = 0 oe0.IDO_Z_S = 0 oe0.ISTAR1 = 5676561 oe0.NCOL = 0 oe0.NPOINT = 50000 oe0.N_COLOR = 0 oe0.PH1 = 1000.0 oe0.PH2 = 1000.1 oe0.POL_DEG = 0.0 oe0.SIGMAX = 7e-06 oe0.SIGMAY = 0.0 oe0.SIGMAZ = 1e-05 oe0.VDIV1 = 1.0 oe0.VDIV2 = 1.0 oe0.WXSOU = 0.0 oe0.WYSOU = 0.0 oe0.WZSOU = 0.0 #Run SHADOW to create the source if iwrite: oe0.write("start.00") beam.genSource(oe0) if iwrite: oe0.write("end.00") beam.write("begin.dat") return beam
def run_shadow3_for_ellipsoid(iwrite=1): # # Python script to run shadow3. Created automatically with ShadowTools.make_python_script_from_list(). # import Shadow import numpy # write (1) or not (0) SHADOW files start.xx end.xx star.xx # iwrite = 1 # # initialize shadow3 source (oe0) and beam # beam = Shadow.Beam() oe0 = Shadow.Source() oe1 = Shadow.OE() # # Define variables. See meaning of variables in: # https://raw.githubusercontent.com/srio/shadow3/master/docs/source.nml # https://raw.githubusercontent.com/srio/shadow3/master/docs/oe.nml # oe0.FDISTR = 3 oe0.F_COLOR = 3 oe0.F_PHOT = 0 oe0.HDIV1 = 0.0 oe0.HDIV2 = 0.0 oe0.IDO_VX = 0 oe0.IDO_VZ = 0 oe0.IDO_X_S = 0 oe0.IDO_Y_S = 0 oe0.IDO_Z_S = 0 oe0.PH1 = 5000.0 oe0.PH2 = 45000.0 oe0.SIGDIX = 8.84999972e-05 oe0.SIGDIZ = 7.1999998e-06 oe0.SIGMAX = 0.0057000001 oe0.SIGMAZ = 0.00104 oe0.VDIV1 = 0.0 oe0.VDIV2 = 0.0 oe1.DUMMY = 1.0 oe1.FMIRR = 2 oe1.T_IMAGE = 100.0 oe1.T_INCIDENCE = 89.885408 oe1.T_REFLECTION = 89.885408 oe1.T_SOURCE = 3000.0 # Run SHADOW to create the source if iwrite: oe0.write("start.00") beam.genSource(oe0) if iwrite: oe0.write("end.00") beam.write("begin.dat") # # run optical element 1 # print(" Running optical element: %d" % (1)) if iwrite: oe1.write("start.01") beam.traceOE(oe1, 1) if iwrite: oe1.write("end.01") beam.write("star.01")
# # # import block # import numpy import Shadow as sh import Shadow.ShadowTools as st # # initialize Shadow containers and load existing system # oe0 = sh.Source() oe1= sh.OE() oe2= sh.OE() oe3= sh.OE() # # >>>>>>>>>>> inputs <<<<<<<<<<<<< # # #flags # write = 0 # 0=No 1=Yes (write shadow binary and start.xx end.xx files)
def run_example_grating(user_units_to_cm=1.0, npoint=5000, iwrite=0): # # Python script to run shadow3. Created automatically with ShadowTools.make_python_script_from_list(). # # # initialize shadow3 source (oe0) and beam # beam = Shadow.Beam() oe0 = Shadow.Source() oe1 = Shadow.OE() oe2 = Shadow.OE() oe3 = Shadow.OE() # # Define variables. See meaning of variables in: # https://raw.githubusercontent.com/srio/shadow3/master/docs/source.nml # https://raw.githubusercontent.com/srio/shadow3/master/docs/oe.nml # oe0.CONE_MAX = 0.0549999997 oe0.FDISTR = 5 oe0.FSOUR = 0 oe0.FSOURCE_DEPTH = 0 oe0.F_COLOR = 2 oe0.F_POLAR = 0 oe0.NPOINT = npoint oe0.PH1 = 5145.0 oe0.PH2 = 5145.24023 oe1.FMIRR = 1 oe1.F_DEFAULT = 0 oe1.THETA = 5.0 oe1.T_INCIDENCE = 5.0 oe1.T_REFLECTION = 5.0 oe1.DUMMY = user_units_to_cm oe1.SIMAG = 1.00000003e+16 / user_units_to_cm oe1.SSOUR = 85.0 / user_units_to_cm oe1.T_SOURCE = 85.0 / user_units_to_cm oe1.T_IMAGE = 75.0 / user_units_to_cm oe2.ALPHA = 180.0 oe2.F_CENTRAL = 1 oe2.F_GRATING = 1 oe2.F_PHOT_CENT = 1 oe2.R_LAMBDA = 5145.0 oe2.T_INCIDENCE = 5.0 oe2.T_REFLECTION = 5.0 oe2.F_RULING = 1 # works for 0, 1 and 4 (cte in XY, cte in grating, VLS with zero coeffs) oe2.DUMMY = user_units_to_cm oe2.RULING = 18000.0 * user_units_to_cm oe2.T_IMAGE = 0.0 / user_units_to_cm oe2.T_SOURCE = 0.0 / user_units_to_cm oe3.ALPHA = 180.0 oe3.FMIRR = 1 oe3.F_DEFAULT = 0 oe3.THETA = 5.0 oe3.T_INCIDENCE = 5.0 oe3.T_REFLECTION = 5.0 oe3.DUMMY = user_units_to_cm oe3.SIMAG = 85.0 / user_units_to_cm oe3.SSOUR = 100000000000000.0 / user_units_to_cm oe3.T_IMAGE = 85.0 / user_units_to_cm oe3.T_SOURCE = 105.0 / user_units_to_cm #Run SHADOW to create the source if iwrite: oe0.write("start.00") beam.genSource(oe0) if iwrite: oe0.write("end.00") beam.write("begin.dat") # #run optical element 1 # print(" Running optical element: %d" % (1)) if iwrite: oe1.write("start.01") beam.traceOE(oe1, 1) if iwrite: oe1.write("end.01") beam.write("star.01") # #run optical element 2 # print(" Running optical element: %d" % (2)) if iwrite: oe2.write("start.02") beam.traceOE(oe2, 2) if iwrite: oe2.write("end.02") beam.write("star.02") # #run optical element 3 # print(" Running optical element: %d" % (3)) if iwrite: oe3.write("start.03") beam.traceOE(oe3, 3) if iwrite: oe3.write("end.03") beam.write("star.03") #print(oe1.mirinfo()) print(oe2.mirinfo()) #print(oe3.mirinfo()) return beam
def ray_tracing(E,BW): # # Python script to run shadow3. Created automatically with ShadowTools.make_python_script_from_list(). # import Shadow import numpy # write (1) or not (0) SHADOW files start.xx end.xx star.xx iwrite = 0 # # initialize shadow3 source (oe0) and beam # beam = Shadow.Beam() oe0 = Shadow.Source() oe1 = Shadow.OE() # # Define variables. See meaning of variables in: # https://raw.githubusercontent.com/srio/shadow3/master/docs/source.nml # https://raw.githubusercontent.com/srio/shadow3/master/docs/oe.nml # NEWSIGMAS = get_sigmas_EBS(E,0.016*125) oe0.FDISTR = 3 oe0.FSOUR = 3 oe0.F_COLOR = 3 oe0.F_PHOT = 0 oe0.HDIV1 = 0.0 oe0.HDIV2 = 0.0 oe0.ISTAR1 = 5676561 oe0.NPOINT = 50000 oe0.PH1 = E oe0.PH2 = E oe0.SIGDIX = NEWSIGMAS[0] oe0.SIGDIZ = NEWSIGMAS[1] oe0.SIGMAX = NEWSIGMAS[2] oe0.SIGMAZ = NEWSIGMAS[3] oe0.VDIV1 = 0.0 oe0.VDIV2 = 0.0 oe1.DUMMY = 100.0 oe1.FWRITE = 0 oe1.F_REFRAC = 2 oe1.F_SCREEN = 1 oe1.N_SCREEN = 1 oe1.T_IMAGE = 0.0 oe1.T_INCIDENCE = 0.0 oe1.T_REFLECTION = 180.0 oe1.T_SOURCE = 30.0 #Run SHADOW to create the source if iwrite: oe0.write("start.00") beam.genSource(oe0) if iwrite: oe0.write("end.00") beam.write("begin.dat") # #run optical element 1 # print(" Running optical element: %d"%(1)) if iwrite: oe1.write("start.01") beam.traceOE(oe1,1) if iwrite: oe1.write("end.01") beam.write("star.01") # Shadow.ShadowTools.plotxy(beam,1,3,nbins=101,nolost=1,title="Real space E=%f"%E) # Shadow.ShadowTools.plotxy(beam,1,4,nbins=101,nolost=1,title="Phase space X") # Shadow.ShadowTools.plotxy(beam,3,6,nbins=101,nolost=1,title="Phase space Z") hist2=beam.histo2(1,3,nbins=50,nbins_h=100,nbins_v=100) fwhm_h=hist2.get("fwhm_h") fwhm_v=hist2.get("fwhm_v") return beam,E,fwhm_h,fwhm_v
def run_example_crystal_mosaic(user_units_to_cm=1.0, iwrite=0): # # Python script to run shadow3. Created automatically with ShadowTools.make_python_script_from_list(). # # # initialize shadow3 source (oe0) and beam # beam = Shadow.Beam() oe0 = Shadow.Source() oe1 = Shadow.OE() # # Define variables. See meaning of variables in: # https://raw.githubusercontent.com/srio/shadow3/master/docs/source.nml # https://raw.githubusercontent.com/srio/shadow3/master/docs/oe.nml # oe0.FSOUR = 0 oe0.F_COLOR = 2 oe0.F_PHOT = 0 oe0.HDIV1 = 0.0005 oe0.HDIV2 = 0.0005 oe0.N_COLOR = 3 oe0.PH1 = 7996.0 oe0.PH2 = 8000.0 oe0.PH3 = 8004.0 oe0.VDIV1 = 0.0001 oe0.VDIV2 = 0.0001 oe0.WYSOU = 0.0 oe0.ISTAR1 = 1234567 oe0.NPOINT = 10000 oe1.DUMMY = user_units_to_cm oe1.T_IMAGE = 1000.0 / user_units_to_cm oe1.T_SOURCE = 1000.0 / user_units_to_cm oe1.THICKNESS = 0.1 / user_units_to_cm oe1.FILE_REFL = b'HOPG2_20.002' oe1.F_CENTRAL = 1 oe1.F_CRYSTAL = 1 oe1.F_MOSAIC = 1 oe1.PHOT_CENT = 8000.0 oe1.R_LAMBDA = 5000.0 oe1.SPREAD_MOS = 0.2 oe1.T_INCIDENCE = 76.617 oe1.T_REFLECTION = 76.617 #Run SHADOW to create the source if iwrite: oe0.write("start.00") beam.genSource(oe0) if iwrite: oe0.write("end.00") beam.write("begin.dat") # #run optical element 1 # print(" Running optical element: %d" % (1)) if iwrite: oe1.write("start.01") beam.traceOE(oe1, 1) if iwrite: oe1.write("end.01") beam.write("star.01") print(oe1.mirinfo()) return beam
def run_shadow(incidence=67.7, radius=1.0): # # Python script to run shadow3. Created automatically with ShadowTools.make_python_script_from_list(). # import Shadow import numpy # write (1) or not (0) SHADOW files start.xx end.xx star.xx iwrite = 0 # # initialize shadow3 source (oe0) and beam # beam = Shadow.Beam() oe0 = Shadow.Source() oe1 = Shadow.OE() oe2 = Shadow.OE() # # Define variables. See meaning of variables in: # https://raw.githubusercontent.com/srio/shadow3/master/docs/source.nml # https://raw.githubusercontent.com/srio/shadow3/master/docs/oe.nml # oe0.BENER = 2.0 oe0.EPSI_X = 7e-11 oe0.EPSI_Z = 7e-11 oe0.FDISTR = 6 oe0.FSOURCE_DEPTH = 4 oe0.F_COLOR = 3 oe0.F_PHOT = 0 oe0.HDIV1 = 0.033 oe0.HDIV2 = 0.033 oe0.ISTAR1 = 5676561 oe0.NCOL = 0 oe0.NPOINT = 300000 oe0.N_COLOR = 0 oe0.PH1 = 0.1 oe0.PH2 = 0.101 oe0.POL_DEG = 0.0 oe0.R_ALADDIN = -7.615618611829955 oe0.R_MAGNET = -7.615618611829955 oe0.SIGDIX = 0.0 oe0.SIGDIZ = 0.0 oe0.SIGMAX = 7e-06 oe0.SIGMAY = 0.0 oe0.SIGMAZ = 1e-05 oe0.VDIV1 = 0.05 oe0.VDIV2 = 0.05 oe0.WXSOU = 0.0 oe0.WYSOU = 0.0 oe0.WZSOU = 0.0 oe1.ALPHA = 90.0 oe1.DUMMY = 100.0 oe1.FCYL = 1 oe1.FMIRR = 1 oe1.FWRITE = 1 oe1.F_EXT = 1 oe1.RMIRR = radius oe1.T_IMAGE = 0.0 oe1.T_INCIDENCE = incidence oe1.T_REFLECTION = incidence oe1.T_SOURCE = 1.58 oe2.ALPHA = 90.0 oe2.DUMMY = 100.0 oe2.FCYL = 1 oe2.FHIT_C = 1 oe2.FMIRR = 1 oe2.F_DEFAULT = 0 oe2.RLEN1 = 6.0 oe2.RLEN2 = 6.0 oe2.RWIDX1 = 0.65 oe2.RWIDX2 = 0.65 oe2.SIMAG = 2.697 oe2.SSOUR = 3.31 oe2.THETA = 45.0 oe2.T_IMAGE = 2.697 oe2.T_INCIDENCE = 45.0 oe2.T_REFLECTION = 45.0 oe2.T_SOURCE = 1.73 # Run SHADOW to create the source if iwrite: oe0.write("start.00") beam.genSource(oe0) if iwrite: oe0.write("end.00") beam.write("begin.dat") # # run optical element 1 # print(" Running optical element: %d" % (1)) if iwrite: oe1.write("start.01") beam.traceOE(oe1, 1) if iwrite: oe1.write("end.01") beam.write("star.01") # # run optical element 2 # print(" Running optical element: %d" % (2)) if iwrite: oe2.write("start.02") beam.traceOE(oe2, 2) if iwrite: oe2.write("end.02") beam.write("star.02") # Shadow.ShadowTools.plotxy(beam, 1, 3, nbins=101, nolost=1, title="Real space") # Shadow.ShadowTools.plotxy(beam,1,4,nbins=101,nolost=1,title="Phase space X") # Shadow.ShadowTools.plotxy(beam,3,6,nbins=101,nolost=1,title="Phase space Z") return beam, oe1
def run_shadow3_source(ener_gev=6.04,use_emittances=True,EMIN=10000.0,EMAX=11000.0,NRAYS=500): import Shadow oe0 = Shadow.Source() beam = Shadow.Beam() oe0.BENER = ener_gev oe0.CONV_FACT = 100.0 oe0.FDISTR = 0 oe0.FILE_TRAJ = b'xshwig.sha' # b'xshwig.sha' oe0.FSOUR = 0 oe0.FSOURCE_DEPTH = 0 oe0.F_COLOR = 0 oe0.F_PHOT = 0 oe0.F_WIGGLER = 1 oe0.HDIV1 = 1.0 oe0.HDIV2 = 1.0 oe0.IDO_VX = 0 oe0.IDO_VZ = 0 oe0.IDO_X_S = 0 oe0.IDO_Y_S = 0 oe0.IDO_Z_S = 0 oe0.ISTAR1 = 5676561 oe0.NCOL = 0 oe0.N_COLOR = 0 oe0.PH1 = EMIN oe0.PH2 = EMAX oe0.POL_DEG = 0.0 oe0.NPOINT = NRAYS if use_emittances: moment_xx=(400e-6)**2 moment_xxp=0.0 moment_xpxp=(10e-6)**2 moment_yy=(10e-6)**2 moment_yyp=0.0 moment_ypyp=(4e-6)**2 oe0.SIGMAX = 1e2 * numpy.sqrt(moment_xx) oe0.SIGMAY = 0.0 oe0.SIGMAZ = 1e2 * numpy.sqrt(moment_yy) oe0.EPSI_X = 1e2 * numpy.sqrt(moment_xx) * numpy.sqrt(moment_xpxp) oe0.EPSI_Z = 1e2 * numpy.sqrt(moment_yy) * numpy.sqrt(moment_ypyp) else: oe0.SIGMAX = 0.0 oe0.SIGMAY = 0.0 oe0.SIGMAZ = 0.0 oe0.EPSI_X = 0.0 oe0.EPSI_Z = 0.0 oe0.VDIV1 = 1.0 oe0.VDIV2 = 1.0 oe0.WXSOU = 0.0 oe0.WYSOU = 0.0 oe0.WZSOU = 0.0 oe0.write("start.00") beam.genSource(oe0) beam.write("begin.dat") return beam
# # import block # import numpy #import sys import copy import Shadow as sh import Shadow.ShadowTools as st # # initialize Shadow containers # src = sh.Source() oe1 = sh.OE() beamSource = sh.Beam() # # >>>>>>>>>>> inputs <<<<<<<<<<<<< # # #flags # source_create = 1 # create source (1) or read from file (0) noplot = 1 # 0=plot 1=no plot write = 0 # 0=No 1=Yes (write shadow binary files) #
# # # It uses the currently defined Shadow system defined in the (existing) # files start.xx and systemfile.dat # # Author: Niccolo Canestrari, Manuel Sanchew del Rio # ESRF (c) 2011 # # # import block # import Shadow import sys src = Shadow.Source() oe1 = Shadow.OE() beam = Shadow.Beam() i = 0 if len(sys.argv) == 1: print( "Usage: \n trace3_py.py -a ->creates source \n trace3_py.py -t ->runs trace (optical system) \n trace3_py.py -a ->runs both source and trace \n" ) exit() if sys.argv[1] == '-s': src.load('start.00') beam.genSource(src) if sys.argv[1] == '-t':
def run_example_crystal_laue(user_units_to_cm=1.0, npoint=5000, iwrite=0): # # Python script to run shadow3. Created automatically with ShadowTools.make_python_script_from_list(). # import Shadow import numpy # write (1) or not (0) SHADOW files start.xx end.xx star.xx iwrite = 0 # # initialize shadow3 source (oe0) and beam # beam = Shadow.Beam() oe0 = Shadow.Source() oe1 = Shadow.OE() # # Define variables. See meaning of variables in: # https://raw.githubusercontent.com/srio/shadow3/master/docs/source.nml # https://raw.githubusercontent.com/srio/shadow3/master/docs/oe.nml # oe0.FDISTR = 3 oe0.FSOURCE_DEPTH = 0 oe0.F_COLOR = 3 oe0.F_PHOT = 0 oe0.HDIV1 = 0.0 oe0.HDIV2 = 0.0 oe0.PH1 = 9098.0 oe0.PH2 = 9102.0 oe0.SIGDIX = 1.70200001e-05 oe0.SIGDIZ = 1.10600004e-05 oe0.SIGMAX = 0.0407229997 / user_units_to_cm oe0.SIGMAZ = 0.00902100001 / user_units_to_cm oe0.VDIV1 = 0.0 oe0.VDIV2 = 0.0 oe0.NPOINT = npoint oe1.A_BRAGG = 55.0 oe1.FHIT_C = 1 oe1.FILE_REFL = b'bragg.dat' oe1.F_BRAGG_A = 1 oe1.F_CENTRAL = 1 oe1.F_CRYSTAL = 1 oe1.F_REFRAC = 1 oe1.PHOT_CENT = 9100.0 oe1.T_INCIDENCE = 15.682 oe1.T_REFLECTION = 125.682 oe1.RLEN1 = 0.300000012 / user_units_to_cm oe1.RLEN2 = 0.300000012 / user_units_to_cm oe1.RWIDX1 = 0.300000012 / user_units_to_cm oe1.RWIDX2 = 0.300000012 / user_units_to_cm oe1.THICKNESS = 0.0099999998 / user_units_to_cm oe1.T_IMAGE = 0.0 / user_units_to_cm oe1.T_SOURCE = 4000.0 / user_units_to_cm oe1.DUMMY = user_units_to_cm #Run SHADOW to create the source if iwrite: oe0.write("start.00") beam.genSource(oe0) if iwrite: oe0.write("end.00") beam.write("begin.dat") # #run optical element 1 # print(" Running optical element: %d" % (1)) if iwrite: oe1.write("start.01") beam.traceOE(oe1, 1) if iwrite: oe1.write("end.01") beam.write("star.01") print(oe1.mirinfo()) return beam
def run_example_lens(user_units_to_cm=1.0, npoint=5000, use_prerefl=0): # # Python script to run shadow3. Created automatically with ShadowTools.make_python_script_from_list(). # # # initialize shadow3 source (oe0) and beam # beam = Shadow.Beam() oe0 = Shadow.Source() oe1 = Shadow.OE() oe2 = Shadow.OE() # # Define variables. See meaning of variables in: # https://raw.githubusercontent.com/srio/shadow3/master/docs/source.nml # https://raw.githubusercontent.com/srio/shadow3/master/docs/oe.nml # oe0.FDISTR = 3 oe0.FSOURCE_DEPTH = 0 oe0.F_PHOT = 0 oe0.HDIV1 = 1.0 oe0.HDIV2 = 1.0 oe0.ISTAR1 = 0 oe0.NPOINT = 500000 oe0.PH1 = 8000.0 oe0.SIGDIX = 2.49999994e-05 oe0.SIGDIZ = 8.00000089e-06 oe0.SIGMAX = 0.0122999996 / user_units_to_cm oe0.SIGMAZ = 0.000699999975 / user_units_to_cm oe0.VDIV1 = 1.0 oe0.VDIV2 = 1.0 oe1.CCC = numpy.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0]) oe1.FCYL = 1 if use_prerefl: oe1.F_R_IND = 2 oe1.R_ATTENUATION_OBJ = 0.0 oe1.R_IND_OBJ = 1.0 oe1.FILE_R_IND_IMA = b'prerefl.dat' else: oe1.F_R_IND = 0 oe1.R_IND_OBJ = 1.0 oe1.R_IND_IMA = 0.9999923264754235 oe1.R_ATTENUATION_OBJ = 0.0 oe1.R_ATTENUATION_IMA = 150.727 oe1.FMIRR = 10 oe1.FWRITE = 3 oe1.F_EXT = 1 oe1.F_REFRAC = 1 oe1.T_INCIDENCE = 0.0 oe1.T_REFLECTION = 180.0 oe1.T_SOURCE = 4700.9 / user_units_to_cm oe1.T_IMAGE = 0.01 / user_units_to_cm oe1.DUMMY = user_units_to_cm oe2.CCC = numpy.array([ 0.0, 292.67523 * user_units_to_cm**2, 0.0045013279 * user_units_to_cm**2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.13418387 * user_units_to_cm, 0.0 ]) oe2.FCYL = 1 if use_prerefl: oe2.F_R_IND = 1 oe2.FILE_R_IND_OBJ = b'prerefl.dat' oe2.R_ATTENUATION_IMA = 0.0 oe2.R_IND_IMA = 1.0 else: oe2.F_R_IND = 0 oe2.R_IND_OBJ = 0.9999923264754235 oe2.R_IND_IMA = 1.0 oe2.R_ATTENUATION_OBJ = 150.727 oe2.R_ATTENUATION_IMA = 0.0 oe2.FMIRR = 10 oe2.FWRITE = 3 oe2.F_EXT = 1 oe2.F_REFRAC = 1 oe2.T_INCIDENCE = 0.0 oe2.T_REFLECTION = 180.0 oe2.T_SOURCE = 0.0 / user_units_to_cm oe2.T_IMAGE = 30.065 / user_units_to_cm oe2.DUMMY = user_units_to_cm beam.genSource(oe0) # #run optical element 1 # print(" Running optical element: %d" % (1)) beam.traceOE(oe1, 1) # #run optical element 2 # print(" Running optical element: %d" % (2)) beam.traceOE(oe2, 2) # print(oe0.sourcinfo()) # print(oe1.mirinfo()) # print(oe2.mirinfo()) return beam
def make_python_script_from_list(element_list, script_file=""): """ program to build automatically a python script to run shadow3 the system is read from a list of instances of Shadow.Source and Shadow.OE :argument list of optical_elements A python list with intances of Shadow.Source and Shadow.OE objects :param script_file: a string with the name of the output file (default="", no output file) :return: template with the script """ template = """import Shadow import numpy as np from optlnls.hybrid import run_hybrid from orangecontrib.shadow.util.shadow_objects import ShadowBeam, ShadowOpticalElement, ShadowSource beam = ShadowBeam() """ n_elements = len(element_list) params = [] for i, element in enumerate(element_list): if isinstance(element[1], Shadow.Source): template += "oe0 = Shadow.Source()\n" elif isinstance(element[1], Shadow.OE): template += "oe%d = Shadow.OE()\n" % (i) elif isinstance(element[1], Shadow.IdealLensOE): template += "oe%d = Shadow.IdealLensOE()\n" % (i) else: raise Exception("Error: Element not known") with element[0].hybrid_dialog.param as elem: params.append( '''beam, diff_plane={0}, calcType={1}, dist_to_img_calc={2}, distance={3}, focal_length_calc={4}, focallength={5}, nf={6}, nbins_x={7}, nbins_z={8}, npeak={9}, fftnpts={10}, write_file={11}, automatic={12}, send_original_beam={13}'''.format( elem.diff_plane, elem.calcType, elem.dist_to_img_calc, elem.distance, elem.focallength_calc, elem.focallength_value, elem.nfc, elem.nbins_x, elem.nbins_z, elem.npeaks, elem.fft, elem.write_file, elem.automatic, elem.send_original_beam)) template += "\n#\n# Define variables. See meaning of variables in: \n" \ "# https://raw.githubusercontent.com/srio/shadow3/master/docs/source.nml \n" \ "# https://raw.githubusercontent.com/srio/shadow3/master/docs/oe.nml\n#\n" for ioe, oe1B in enumerate(element_list): template += "\n" if isinstance(oe1B[1], Shadow.Source): oe1 = Shadow.Source() elif isinstance(oe1B[1], Shadow.OE): oe1 = Shadow.OE() elif isinstance(oe1B[1], Shadow.IdealLensOE): oe1 = Shadow.IdealLensOE() else: raise Exception("Error: Element not known") if isinstance(oe1B[1], Shadow.IdealLensOE): template += "oe" + str(ioe) + ".T_SOURCE = " + str( oe1B[1].T_SOURCE).strip() + "\n" template += "oe" + str(ioe) + ".T_IMAGE = " + str( oe1B[1].T_IMAGE).strip() + "\n" template += "oe" + str(ioe) + ".focal_x = " + str( oe1B[1].focal_x).strip() + "\n" template += "oe" + str(ioe) + ".focal_z = " + str( oe1B[1].focal_z).strip() + "\n" else: memB = inspect.getmembers(oe1B[1]) mem = inspect.getmembers(oe1) for i, var in enumerate(memB): ivar = mem[i] ivarB = memB[i] if ivar[0].isupper(): if isinstance(ivar[1], numpy.ndarray): if not ((ivar[1] == ivarB[1]).all()): line = "oe" + str( ioe) + "." + ivar[0] + " = np.array(" + str( ivarB[1].tolist()) + ")\n" template += line else: if ivar[1] != ivarB[1]: if isinstance(ivar[1], (str, bytes)): line = "oe" + str( ioe) + "." + ivar[0] + " = " + str( ivarB[1]).strip() + "\n" #line = re.sub('\s{2,}', ' ',line) if "SPECIFIED" in line: pass else: template += line else: line = "oe" + str( ioe) + "." + ivar[0] + " = " + str( ivarB[1]) + "\n" template += line template += """\n##########################\n # Run SHADOW to create the source src = ShadowSource(oe0) beam = ShadowBeam().traceFromSource(src)""" template_oeA = """\n # Run optical element {0} print(" Running optical element: %d"%({0})) oe_{0} = ShadowOpticalElement(oe{0})""" for i in range(1, n_elements): template += template_oeA.format(i, "%02d" % (i)) if isinstance(element_list[i][1], Shadow.OE): template += "\nbeam = beam.traceFromOE(beam, oe_{0}, widget_class_name='{1}')".format( i, element_list[i][0].hybrid_dialog.name) if element_list[i][0].use_hybrid: template += '\nbeam = run_hybrid(' + params[i] + ')' elif isinstance(element_list[i][1], Shadow.IdealLensOE): template += "\nbeam = beam.traceIdealLensOE(beam, oe_{0}, widget_class_name='{1}')".format( i, element_list[i][0].hybrid_dialog.name) if element_list[i][0].use_hybrid: template += '\nbeam = run_hybrid(' + params[i] + ')' template += """\n # Shadow.ShadowTools.plotxy(beam._beam,1,3,nbins=101,nolost=1,title="Real space") # Shadow.ShadowTools.plotxy(beam._beam,1,4,nbins=101,nolost=1,title="Phase space X") # Shadow.ShadowTools.plotxy(beam._beam,3,6,nbins=101,nolost=1,title="Phase space Z")""" if script_file != "": open(script_file, "wt").write(template) print("File written to disk: %s" % (script_file)) return template
# # import block # import numpy import Shadow import copy do_intermediate_plots = 0 horizontal_divergence_in_mrad = 5.0 # # initialize shadow3 source (oe0) and beam # beam = Shadow.Beam() oe0 = Shadow.Source() oe1 = Shadow.OE() oe2 = Shadow.OE() oe0.BENER = 6.03999996 oe0.EPSI_X = 3.89999997e-07 oe0.EPSI_Z = 3.89999988e-09 oe0.FDISTR = 4 oe0.FSOURCE_DEPTH = 4 oe0.F_COLOR = 3 oe0.F_PHOT = 0 oe0.HDIV1 = 0.05 * 1e-3 * horizontal_divergence_in_mrad oe0.HDIV2 = 0.05 * 1e-3 * horizontal_divergence_in_mrad oe0.ISTAR1 = 567656675 oe0.NCOL = 0 oe0.NPOINT = 25000
def run_bm_shadow3(iwrite=0): # # Python script to run shadow3. Created automatically with ShadowTools.make_python_script_from_list(). # # write (1) or not (0) SHADOW files start.xx end.xx star.xx # # initialize shadow3 source (oe0) and beam # beam = Shadow.Beam() oe0 = Shadow.Source() # # Define variables. See meaning of variables in: # https://raw.githubusercontent.com/srio/shadow3/master/docs/source.nml # https://raw.githubusercontent.com/srio/shadow3/master/docs/oe.nml # oe0.NPOINT = 5000 oe0.BENER = 6.04 oe0.EPSI_X = 3.8e-07 oe0.EPSI_Z = 3.8e-09 oe0.FDISTR = 4 oe0.FSOURCE_DEPTH = 4 oe0.F_COLOR = 3 oe0.F_PHOT = 0 oe0.HDIV1 = 0.0005 oe0.HDIV2 = 0.0005 oe0.NCOL = 0 oe0.N_COLOR = 0 oe0.PH1 = 5000.0 oe0.PH2 = 100000.0 oe0.POL_DEG = 0.0 oe0.R_ALADDIN = 2517.72 oe0.R_MAGNET = 25.1772 oe0.SIGDIX = 0.0 oe0.SIGDIZ = 0.0 oe0.SIGMAX = 0.0078 oe0.SIGMAY = 0.0 oe0.SIGMAZ = 0.0036 oe0.VDIV1 = 1.0 oe0.VDIV2 = 1.0 oe0.WXSOU = 0.0 oe0.WYSOU = 0.0 oe0.WZSOU = 0.0 #Run SHADOW to create the source if iwrite: oe0.write("start.00") beam.genSource(oe0) if iwrite: oe0.write("end.00") beam.write("begin.dat") # Shadow.ShadowTools.plotxy(beam,1,3,nbins=101,nolost=1,title="Real space") # Shadow.ShadowTools.plotxy(beam,2,1,nbins=101,nolost=1,title="top view") # Shadow.ShadowTools.plotxy(beam,3,6,nbins=101,nolost=1,title="Phase space Z") return beam, oe0