コード例 #1
0
def refractive_interface_with_collimated_beam(do_plot=True):

    #
    # collimated source
    #

    src = SourceGeometrical()
    src.set_energy_distribution_singleline(value=5000, unit='A')
    src.set_spatial_type_rectangle(width=1e-3, height=1e-3)
    src.set_angular_distribution_uniform(0, 0, 0, 0)

    beam = src.get_beam()

    print(beam.info())
    SX, SZ = (1e6 * beam.get_standard_deviation(1),
              1e6 * beam.get_standard_deviation(3))

    #
    # lens definition
    #

    interface1 = S4ConicInterfaceElement(optical_element=S4ConicInterface(
        name="Conic Refractive Interface",
        boundary_shape=None,
        material_object="vacuum",
        material_image="glass",
        f_r_ind=0,
        r_ind_obj=1.0,
        r_ind_ima=1.5,
        conic_coefficients=[
            1.0, 1.0, 1.0, 0.0, -0.0, -0.0, 0.0, 0.0, 3350.0e-3, 0.0
        ],
    ),
                                         coordinates=ElementCoordinates(
                                             p=0.0,
                                             q=5000.0e-3,
                                             angle_radial=0.0,
                                             angle_azimuthal=0.0,
                                             angle_radial_out=numpy.pi))

    print(interface1.info())
    print(interface1.get_optical_element().get_surface_shape().
          get_conic_coefficients())
    #
    # trace
    #

    beam2, mirr2 = interface1.trace_beam(beam)

    #
    if do_plot:
        plotxy(beam2, 1, 3, nbins=100, title="FOCAL PLANE")
        plotxy(mirr2, 1, 3, nbins=100, title="LENS HEIGHT")
        # plotxy(mirr2, 4, 5, nbins=100, title="FOOT DIV")

    FX, FZ = (1e6 * beam2.get_standard_deviation(1),
              1e6 * beam2.get_standard_deviation(3))
    print("Source dimensions: %f %f um" % (SX, SZ))
    print("Focal dimensions: %f %f um" % (FX, FZ))
    print("Demagnification: %g %g" % (SX / FX, SX / FZ))
コード例 #2
0
def example_screen(do_plot=True):

    #
    # collimated source
    #
    src = SourceGaussian.initialize_collimated_source(number_of_rays=10000,
                                                      sigmaX=1e-6,
                                                      sigmaZ=1e-6)

    beam = src.get_beam()

    print(beam.info())

    #
    # screen definition
    #

    screen1 = S4ScreenElement(optical_element=S4Screen(),
                              coordinates=ElementCoordinates(p=100.0, q=0.0))

    print(screen1.info())

    beam2, tmp = screen1.trace_beam(beam)

    #
    if do_plot:
        plotxy(beam2, 1, 3, nbins=100, title="SCREEN")
コード例 #3
0
def example_beam_stopper(do_plot=True):

    src = SourceGaussian.initialize_collimated_source(number_of_rays=10000,
                                                      sigmaX=1e-6,
                                                      sigmaZ=1e-6)
    beam = src.get_beam()

    #
    # slit definition
    #
    boundary_shape = Ellipse(-1e-6, 1e-6, -0.5e-6, 0.5e-6)
    coordinates = ElementCoordinates(p=100.0, q=0.0)
    optical_element = S4Screen(name="slit1",
                               boundary_shape=boundary_shape,
                               i_abs=False,
                               i_stop=True,
                               thick=0.0,
                               file_abs="")

    screen1 = S4ScreenElement(optical_element=optical_element,
                              coordinates=coordinates)

    print(screen1.info())

    #
    # trace
    #

    beam2, tmp = screen1.trace_beam(beam)

    #
    if do_plot:
        plotxy(beam2, 1, 3, nbins=100, title="BEAM STOPPER", nolost=True)
コード例 #4
0
def example_branch_3(surface_shape_file, do_plot=True):
    #
    # source
    #
    # beam0 = Beam.initialize_as_pencil(N=500)
    source = SourceGaussian.initialize_from_keywords(
        number_of_rays=100000,
        sigmaX=0.0,
        sigmaY=0.0,
        sigmaZ=0.0,
        sigmaXprime=1e-4,
        sigmaZprime=1e-4,
    )
    beam0 = Beam()
    beam0.genSource(source)
    print(beam0.info())

    if do_plot:
        plotxy(beam0, 4, 6, title="Image 0", nbins=201)

    #
    # syned definitopns
    #

    # boundaries
    rlen1 = 0.6
    rlen2 = 0.6
    rwidx1 = 0.05
    rwidx2 = 0.05

    #
    # shadow definitions
    #
    mirror1 = S4SurfaceDataMirrorElement(optical_element=S4SurfaceDataMirror(
        name="M1",
        surface_data_file=surface_shape_file,
        boundary_shape=Rectangle(x_left=-rwidx2,
                                 x_right=rwidx1,
                                 y_bottom=-rlen2,
                                 y_top=rlen1)),
                                         coordinates=ElementCoordinates(
                                             p=100.0,
                                             q=1000.0,
                                             angle_radial=numpy.radians(88.8)))
    print(mirror1.info())

    #
    # run
    #
    beam1, mirr1 = mirror1.trace_beam(beam0)
    print(mirr1.info())

    #
    # check
    #

    if do_plot:
        plotxy(beam1, 1, 3, title="Image 1", nbins=101, nolost=1)
        plotxy(mirr1, 2, 1, title="Footprint 1", nbins=101, nolost=1)
コード例 #5
0
 def __init__(self, optical_element=None, coordinates=None):
     super().__init__(
         optical_element if optical_element is not None else S4Grating(),
         coordinates if coordinates is not None else ElementCoordinates())
     if not isinstance(self.get_optical_element().get_surface_shape(),
                       Plane):
         raise ValueError(
             "Wrong Optical Element: only Plane shape is accepted")
コード例 #6
0
    def __init__(self, optical_element=None, coordinates=None):
        super().__init__(
            optical_element if optical_element is not None else S4Crystal(),
            coordinates if coordinates is not None else ElementCoordinates())

        self._crystalpy_diffraction_setup = None

        self.align_crystal()
コード例 #7
0
def crystal_diffraction_with_collimated_beam(do_plot=True):

    #
    # collimated source
    #

    if True:
        src = SourceGeometrical()
        src.set_energy_distribution_singleline(value=8000, unit='eV')
        src.set_spatial_type_rectangle(width=1e-3, height=1e-3)
        src.set_angular_distribution_uniform(0,0,-100e-6,100e-6)

        beam = src.get_beam(POL_DEG=0.5, POL_ANGLE=numpy.pi/4, F_COHER=False)

        print(beam.info())
        SX, SZ = (1e6*beam.get_standard_deviation(1),1e6*beam.get_standard_deviation(3))


    #
    # crystal definition
    #


    crystal1 = S4PlaneCrystalElement(
                                optical_element=S4PlaneCrystal(
                                    name="Plane crystal",
                                    boundary_shape=None,
                                    material="Si",
                                    diffraction_geometry=DiffractionGeometry.BRAGG,  # ?? not supposed to be in syned...
                                    miller_index_h=1,
                                    miller_index_k=1,
                                    miller_index_l=1,
                                    asymmetry_angle=0.0,
                                    thickness=0.010,  ###########################
                                    f_central=True,
                                    f_phot_cent=0,
                                    phot_cent=8000.0,
                                    file_refl="",
                                    f_bragg_a=False,
                                    # a_bragg=0.0,
                                    f_johansson=False,
                                    r_johansson=1.0,
                                    f_mosaic=False,
                                    spread_mos=0.4 * numpy.pi / 180,
                                    f_ext=0,                                    ),
                                coordinates=ElementCoordinates(p=0.0, q=5000.0e-3,
                                            angle_radial=0.0, angle_azimuthal=0.0, angle_radial_out=0.0))

    # print(crystal1.info())
    # print(crystal1.get_optical_element().get_surface_shape().get_conic_coefficients())
    #
    # trace
    #

    beam2, mirr2 = crystal1.trace_beam(beam)

    if do_plot:
        plotxy(beam2, 6, 23, nbins=100, title="INTENSITY VS Z'")
コード例 #8
0
 def __init__(self,
              optical_element=OpticalElement(),
              coordinates=ElementCoordinates()):
     self._optical_element = optical_element
     self._coordinates = coordinates
     # support text containg name of variable, help text and unit. Will be stored in self._support_dictionary
     self._set_support_text([
         ("optical_element", "Optical Element", ""),
         ("coordinates", "Element coordinates", ""),
     ])
コード例 #9
0
def example_branch_2(do_plot=True):
    source = SourceGaussian.initialize_from_keywords(
        number_of_rays=100000,
        sigmaX=0.0,
        sigmaY=0.0,
        sigmaZ=0.0,
        sigmaXprime=1e-6,
        sigmaZprime=1e-6,
    )
    beam0 = Beam()
    beam0.genSource(source)
    print(beam0.info())

    if do_plot:
        plotxy(beam0, 4, 6, title="Image 0", nbins=201)

    #
    # syned definitopns
    #

    # boundaries
    boundary_shape = None  #Rectangle(x_left=-rwidx2,x_right=rwidx1,y_bottom=-rlen2,y_top=rlen1)

    #
    # shadow definitions
    #
    mirror1 = S4ToroidalMirrorElement(optical_element=S4ToroidalMirror(
        name="M1",
        surface_calculation=SurfaceCalculation.EXTERNAL,
        min_radius=0.157068,
        maj_radius=358.124803 - 0.157068,
        boundary_shape=boundary_shape),
                                      coordinates=ElementCoordinates(
                                          p=10.0,
                                          q=6.0,
                                          angle_radial=numpy.radians(88.8)))

    print(mirror1.info())

    #
    # run
    #
    beam1, mirr1 = mirror1.trace_beam(beam0)
    print(mirr1.info())

    #
    # check
    #

    if do_plot:
        plotxy(beam1, 1, 3, title="Image 1", nbins=101, nolost=1)
        plotxy(mirr1, 2, 1, title="Footprint 1", nbins=101, nolost=1)
コード例 #10
0
def lens_with_divergent_beam(do_plot=True):



    src = SourceGaussian.initialize_from_keywords(number_of_rays=100000,
                                                  sigmaX=     20e-6/2.35,sigmaZ=     10e-6/2.35,
                                                  sigmaXprime=50e-6/2.35,sigmaZprime=10e-6/2.35)

    beam = src.get_beam()

    SX, SZ = (1e6*beam.get_standard_deviation(1),1e6*beam.get_standard_deviation(3))

    if do_plot:
        plotxy(beam,4,6,nbins=100,title="SOURCE DIVERGENCES")

    beam_tmp = beam.duplicate()
    beam_tmp.retrace(100.0)
    if do_plot:
        plotxy(beam_tmp,1,3,nbins=100,title="SOURCE AFTER 10m")


    #
    # lens definition
    #

    p = 10.0
    q = 10.0
    F = 1.0 / (1/p + 1/q)

    lens1e = S4IdealLensElement(optical_element=S4IdealLens(name="Undefined", focal_x=F, focal_y=F),
                                coordinates=ElementCoordinates(p=p, q=q))

    print(lens1e.info())
    beam2, tmp = lens1e.trace_beam(beam)


    X = beam2.get_column(1)
    Y = beam2.get_column(3)
    print("X: ",X.min(),X.max(),X.std())
    print("Y: ",Y.min(),Y.max(),Y.std())


    if do_plot:
        plotxy(beam2,1,3,nbins=100,title="FOCAL PLANE",xrange=[-5e-5,5e-5],yrange=[-5e-5,5e-5])

    FX, FZ = (1e6*beam2.get_standard_deviation(1),1e6*beam2.get_standard_deviation(3))
    print("Source dimensions (rms): %f %f um"%(SX,SZ))
    print("Focal dimensions (rms): %f %f um"%(FX,FZ))
    print("Demagnification: H:%g V:%g (theoretical: %g) "%(SX/FX,SZ/FZ,p/q))
コード例 #11
0
def lens_with_collimated_beam(do_plot=True):

    #
    # collimated source
    #
    src = SourceGaussian.initialize_collimated_source(number_of_rays=10000,sigmaX=1e-6,sigmaZ=1e-6)




    beam = src.get_beam()

    print(beam.info())
    SX, SZ = (1e6*beam.get_standard_deviation(1),1e6*beam.get_standard_deviation(3))

    if do_plot:
        plotxy(beam,1,3,nbins=100,title="SOURCE")
        # histo1(beam, 1, nbins=100)

    #
    # lens definition
    #



    lens1e = S4IdealLensElement(optical_element=S4IdealLens(name="Undefined", focal_x=10.0, focal_y=10.0),
                                coordinates=ElementCoordinates(p=100.0, q=10.0))


    print(lens1e.info())

    #
    # trace
    #

    beam2, tmp = lens1e.trace_beam(beam)

    #
    if do_plot:
        plotxy(beam2,1,3,nbins=100,title="FOCAL PLANE")

    FX, FZ = (1e6*beam2.get_standard_deviation(1),1e6*beam2.get_standard_deviation(3))
    print("Source dimensions: %f %f um"%(SX,SZ))
    print("Focal dimensions: %f %f um"%(FX,FZ))
    print("Demagnification: %g %g"%(SX/FX,SX/FZ))
コード例 #12
0
def example_filter(do_plot=True):

    src = SourceGaussian.initialize_collimated_source(number_of_rays=10000,
                                                      sigmaX=1e-6,
                                                      sigmaZ=1e-6)
    beam = src.get_beam()

    #
    # slit definition
    #

    from shadow4.physical_models.prerefl.prerefl import PreRefl
    PreRefl.prerefl(interactive=False,
                    SYMBOL="Be",
                    DENSITY=1.848,
                    FILE="Be.dat",
                    E_MIN=100.0,
                    E_MAX=20000.0,
                    E_STEP=100.0)

    optical_element = S4Screen(name="filter1",
                               boundary_shape=None,
                               i_abs=True,
                               i_stop=False,
                               thick=10e-6,
                               file_abs="Be.dat")
    coordinates = ElementCoordinates(p=100.0, q=0.0)
    filter1 = S4ScreenElement(optical_element=optical_element,
                              coordinates=coordinates)

    print(filter1.info())

    #
    # trace
    #

    beam2, tmp = filter1.trace_beam(beam)

    #
    if do_plot:
        plotxy(beam2, 1, 3, nbins=100, title="FILTER", nolost=True)

    print("Intensity: ", beam2.intensity())
コード例 #13
0
def example_holed_filter(do_plot=True):

    src = SourceGaussian.initialize_collimated_source(number_of_rays=10000,
                                                      sigmaX=1e-6,
                                                      sigmaZ=1e-6)
    beam = src.get_beam()

    #
    # slit definition
    #
    boundary_shape = Rectangle(x_left=-0.5e-6,
                               x_right=0.5e-6,
                               y_bottom=-0.5e-6,
                               y_top=0.5e-6)

    optical_element = S4Screen(name="filter1",
                               boundary_shape=boundary_shape,
                               i_abs=True,
                               i_stop=True,
                               thick=10e-6,
                               file_abs="Be.dat")

    coordinates = ElementCoordinates(p=100.0, q=0.0)
    filter1 = S4ScreenElement(optical_element=optical_element,
                              coordinates=coordinates)

    print(filter1.info())

    #
    # trace
    #

    beam2, tmp = filter1.trace_beam(beam)

    #
    if do_plot:
        plotxy(beam2, 1, 3, nbins=100, title="HOLED FILTER", nolost=True)
コード例 #14
0
def run_hyperboloid(kind="hyperboloid"):
    #
    # shadow3
    #
    if kind == "hyperboloid":
        from shadow4tests.oasys_workspaces.mirrors_branch5_hyperboloid import define_source, run_source, define_beamline, run_beamline
    else:
        raise Exception("Bad input")

    oe0 = define_source()
    beam3_source = run_source(oe0)

    #
    # shadow4
    #

    from shadow4.syned.element_coordinates import ElementCoordinates

    oe = define_beamline()[0]

    beam4_source = Beam.initialize_from_array(beam3_source.rays)
    beam4 = beam4_source

    check_congruence(oe)

    #
    # shadow definitions
    #

    if oe.F_DEFAULT == 0:
        p_focus = oe.SSOUR
        q_focus = oe.SIMAG
        grazing_angle = numpy.radians(90 - oe.THETA)
    elif oe.F_DEFAULT == 1:
        p_focus = oe.T_SOURCE
        q_focus = oe.T_IMAGE
        grazing_angle = numpy.radians(90 - oe.T_INCIDENCE)

    is_cylinder = oe.FCYL

    if oe.CIL_ANG == 0:
        cylinder_direction = Direction.TANGENTIAL
    else:
        cylinder_direction = Direction.SAGITTAL

    if oe.F_CONVEX == 0:
        convexity = Convexity.UPWARD
    elif oe.F_CONVEX == 1:
        convexity = Convexity.DOWNWARD

    name = "Hyperboloid Mirror (%s) " % kind
    mirror1 = S4HyperboloidMirrorElement(
        optical_element=S4HyperboloidMirror(
            name=name,
            boundary_shape=None,
            surface_calculation=SurfaceCalculation.INTERNAL,
            is_cylinder=is_cylinder,
            cylinder_direction=cylinder_direction,
            convexity=convexity,
            p_focus=p_focus,
            q_focus=q_focus,
            grazing_angle=grazing_angle,

            # inputs related to mirror reflectivity
            f_reflec=oe.
            F_REFLEC,  # reflectivity of surface: 0=no reflectivity, 1=full polarization
            # f_refl=0,  # 0=prerefl file, 1=electric susceptibility, 2=user defined file (1D reflectivity vs angle)
            #             # 3=user defined file (1D reflectivity vs energy), # 4=user defined file (2D reflectivity vs energy and angle)
            # file_refl="",  # preprocessor file fir f_refl=0,2,3,4
            # refraction_index=1.0  # refraction index (complex) for f_refl=1
        ),
        coordinates=ElementCoordinates(
            p=oe.T_SOURCE,
            q=oe.T_IMAGE,
            angle_radial=numpy.radians(oe.T_INCIDENCE),
        ),
    )

    print(mirror1.info())

    #
    # run
    #

    beam4, mirr4 = mirror1.trace_beam(beam_in=beam4, flag_lost_value=-11000)

    #
    # compare
    #
    oe_list = define_beamline()
    beam3 = run_beamline(beam3_source, oe_list)

    plotxy(beam3, 1, 3, nbins=201, nolost=1, title="%s shadow3" % name)
    plotxy(beam4, 1, 3, nbins=201, nolost=1, title="%s shadow4" % name)

    from shadow4tests.compatibility.compare_beams import check_six_columns_mean_and_std, check_almost_equal

    check_six_columns_mean_and_std(beam3,
                                   beam4,
                                   do_assert=True,
                                   do_plot=False,
                                   assert_value=1e-6)
    check_almost_equal(beam3, beam4, do_assert=False, level=3)
コード例 #15
0
 def __init__(self, optical_element=None, coordinates=None):
     super().__init__(
         optical_element if optical_element is not None else S4Mirror(),
         coordinates if coordinates is not None else ElementCoordinates())
コード例 #16
0
    #

    name = "SurfaceDataMirror"
    mirror1 = S4SurfaceDataMirrorElement(
        optical_element=S4SurfaceDataMirror(
            name=name,
            surface_data_file="../oasys_workspaces/mirrors_branch3_mesh.hdf5",
            boundary_shape=Rectangle(
                x_left=-oe.RWIDX2,
                x_right=oe.RWIDX1,
                y_bottom=-oe.RLEN2,
                y_top=oe.RLEN1,
            )),
        coordinates=ElementCoordinates(
            p=oe.T_SOURCE,
            q=oe.T_IMAGE,
            angle_radial=numpy.radians(oe.T_INCIDENCE),
        ),
    )

    print(mirror1.info())

    #
    # run
    #

    beam4, mirr4 = mirror1.trace_beam(beam_in=beam4, flag_lost_value=-11000)

    #
    # compare
    #
コード例 #17
0
def lens_id16ni(do_plot=True):

    #
    # source
    #
    ESRF =  {'sigmaX':387.8,"sigmaZ":3.5,"sigmaX'":10.3,"sigmaZ'":1.2}
    EBS =  {'sigmaX':27.2, "sigmaZ":3.4,"sigmaX'":5.2,"sigmaZ'":1.4}
    m = EBS

    photon_energy = 17000.0
    undulator_length = 1.4

    sr,srp = get_sigmas_radiation(photon_energy,undulator_length)
    print("radiation sigmas: ",sr,srp)

    demagX = [2.42,2899]
    demagZ = 1849

    #
    f2dot35 = 2*numpy.sqrt(2*numpy.log(2))
    sx,sz,sxp,szp = m['sigmaX'],m['sigmaZ'],m["sigmaX'"],m["sigmaZ'"]

    Sx  = 1e-6 * numpy.sqrt( sx**2 + sr**2)
    Sz  = 1e-6 * numpy.sqrt( sz**2 + sr**2)
    Sxp = 1e-6 * numpy.sqrt( sxp**2 + srp**2)
    Szp = 1e-6 * numpy.sqrt( szp**2 + srp**2)

    print("Gaussian source dimensions (rms) x z x' z'",1e6*Sx,1e6*Sz,1e6*Sxp,1e6*Szp)
    print("Gaussian source dimensions (FWHM) x z x' z'",f2dot35*1e6*Sx,f2dot35*1e6*Sz,f2dot35*1e6*Sxp,f2dot35*1e6*Szp)

    src = SourceGaussian.initialize_from_keywords(number_of_rays=500000,
                                                  sigmaX=Sx,sigmaZ=Sz,
                                                  sigmaXprime=Sxp,sigmaZprime=Szp)

    beam = src.get_beam()
    SX, SZ = (1e6*beam.get_standard_deviation(1),1e6*beam.get_standard_deviation(3))

    if do_plot:
        plotxy(beam,1,3,nbins=100,title="SOURCE")

    #
    # multilayer
    #
    p = 28.3
    q = 11.70
    F = 1/(1/p+1/q)


    lens1e = S4IdealLensElement(optical_element=S4IdealLens(name="ML", focal_x=F, focal_y=0),
                                coordinates=ElementCoordinates(p=p, q=q))

    beam, tmp = lens1e.trace_beam(beam)


    FX, FZ = (1e6*beam.get_standard_deviation(1),1e6*beam.get_standard_deviation(3))
    print("----------------- Secondary source---------------------")
    print("Source dimensions (rms): %f %f um"%(SX,SZ))
    print("Focal dimensions (rms): %f %f um"%(FX,FZ))
    print("Focal dimensions (2.35*rms): %f %f um"%(f2dot35*FX,f2dot35*FZ))
    print("Demagnification: H:%g V:%g (theoretical: %g) "%(SX/FX,SZ/FZ,p/q))


    # first KB mirror
    p = 144.90
    q = 0.025
    F = 1.0/(1/184.90+1/0.10)

    lens2e = S4IdealLensElement(optical_element=S4IdealLens(name="KBV", focal_x=0, focal_y=F),
                                coordinates=ElementCoordinates(p=p, q=q))


    print(lens2e.info())
    beam, tmp = lens2e.trace_beam(beam)



    # second KB mirror
    p = 0.025
    q = 0.05
    F = 1.0/(1/144.95+1/0.05)

    lens3e = S4IdealLensElement(optical_element=S4IdealLens(name="KBH", focal_x=F, focal_y=0),
                                coordinates=ElementCoordinates(p=p, q=q))

    print(lens3e.info())
    beam, tmp = lens3e.trace_beam(beam)


    #
    #
    #
    # beam3 = Beam3.initialize_from_shadow4_beam(beam)
    if do_plot:
        tkt = plotxy(beam,1,3,nbins=300,xrange=[-0.0000005,0.0000005],yrange=[-0.0000005,0.0000005],title="FOCAL PLANE")

        print(tkt['fwhm_h'],tkt['fwhm_v'])

    FX, FZ = (1e6*beam.get_standard_deviation(1),1e6*beam.get_standard_deviation(3))
    print("----------------- Focal position ---------------------")
    print("Source dimensions (rms): %f %f um"%(SX,SZ))
    print("Source dimensions (2.35*rms): %f %f um"%(f2dot35*SX,f2dot35*SZ))
    print("Focal dimensions (rms): %f %f um"%(FX,FZ))
    print("Focal dimensions (2.35*rms): %f %f um"%(f2dot35*FX,f2dot35*FZ))
    if do_plot: print("Focal dimensions (FWHM HISTO): %f %f nm"%(1e9*tkt['fwhm_h'],1e9*tkt['fwhm_v']))
    print("Demagnification (StDev) H:%g V:%g (theoretical: %g,%g) "%(SX/FX,SZ/FZ,demagX[0]*demagX[1],demagZ))
    if do_plot: print("Demagnification:(HISTO) H:%g V:%g (theoretical: %g,%g) "%(f2dot35*SX/(f2dot35*1e6*tkt['fwhm_h']),SZ/(1e6*tkt['fwhm_v']),demagX[0]*demagX[1],demagZ))
コード例 #18
0
               nbins=100,
               title="SHADOW3 BEAMSTOPPER",
               nolost=True)

    beam = Beam.initialize_from_array(source3.rays)

    scr = S4Screen(
        name="Undefined",
        boundary_shape=patches,
        i_abs=False,  # include absorption
        i_stop=True,  # aperture/stop
        thick=0.0,  # thickness of the absorber (in SI)
        file_abs="",  # if i_abs=True, the material file (from prerefl)
    )

    coordinates = ElementCoordinates(p=322.971 * 1e-2, q=5.0 * 1e-2)

    slit1 = S4ScreenElement(optical_element=scr, coordinates=coordinates)

    print(slit1.info())

    #
    # trace
    #

    beam2, tmp = slit1.trace_beam(beam, flag_lost_value=-101)

    #
    if do_plot:
        beam2_3 = Beam3.initialize_from_shadow4_beam(beam2)
        plotxy(beam2_3,
コード例 #19
0
def example_branch_5(surface_type, do_plot=True):
    #
    # source
    #
    source = SourceGaussian.initialize_from_keywords(
        number_of_rays=100000,
        sigmaX=0.0,
        sigmaY=0.0,
        sigmaZ=0.0,
        sigmaXprime=1e-6,
        sigmaZprime=1e-6,
    )
    beam0 = Beam()
    beam0.genSource(source)
    # print(beam0.info())

    #
    # syned definitopns
    #
    # boundaries
    boundary_shape = None

    coordinates_syned = ElementCoordinates(p=10.0,
                                           q=10.0,
                                           angle_radial=numpy.radians(88.8))

    # surface shape

    if surface_type == "plane":
        mirror1 = S4PlaneMirrorElement(optical_element=S4PlaneMirror(
            name="M1", boundary_shape=boundary_shape),
                                       coordinates=coordinates_syned)
    elif surface_type == "sphere":
        mirror1 = S4SphereMirrorElement(optical_element=S4SphereMirror(
            name="M1",
            boundary_shape=boundary_shape,
            is_cylinder=False,
            surface_calculation=SurfaceCalculation.INTERNAL,
            p_focus=10.0,
            q_focus=10.0,
            grazing_angle=numpy.radians(90.0 - 88.8)),
                                        coordinates=coordinates_syned)
    elif surface_type == "spherical_cylinder_tangential":
        mirror1 = S4SphereMirrorElement(optical_element=S4SphereMirror(
            name="M1",
            boundary_shape=boundary_shape,
            is_cylinder=True,
            cylinder_direction=Direction.TANGENTIAL,
            surface_calculation=SurfaceCalculation.INTERNAL,
            p_focus=10.0,
            q_focus=10.0,
            grazing_angle=numpy.radians(90.0 - 88.8)),
                                        coordinates=coordinates_syned)
    elif surface_type == "spherical_cylinder_sagittal":
        mirror1 = S4SphereMirrorElement(optical_element=S4SphereMirror(
            name="M1",
            boundary_shape=boundary_shape,
            is_cylinder=True,
            cylinder_direction=Direction.SAGITTAL,
            surface_calculation=SurfaceCalculation.INTERNAL,
            p_focus=10.0,
            q_focus=10.0,
            grazing_angle=numpy.radians(90.0 - 88.8)),
                                        coordinates=coordinates_syned)
    elif surface_type == "ellipsoid":
        mirror1 = S4EllipsoidMirrorElement(optical_element=S4EllipsoidMirror(
            name="M1",
            boundary_shape=boundary_shape,
            is_cylinder=False,
            surface_calculation=SurfaceCalculation.INTERNAL,
            p_focus=20.0,
            q_focus=10.0,
            grazing_angle=0.003),
                                           coordinates=coordinates_syned)
    elif surface_type == "elliptical_cylinder":
        mirror1 = S4EllipsoidMirrorElement(optical_element=S4EllipsoidMirror(
            name="M1",
            boundary_shape=boundary_shape,
            is_cylinder=True,
            cylinder_direction=Direction.TANGENTIAL,
            surface_calculation=SurfaceCalculation.INTERNAL,
            p_focus=20.0,
            q_focus=10.0,
            grazing_angle=0.003),
                                           coordinates=coordinates_syned)
    elif surface_type == "hyperboloid":
        mirror1 = S4HyperboloidMirrorElement(
            optical_element=S4HyperboloidMirror(
                name="M1",
                boundary_shape=boundary_shape,
                is_cylinder=False,
                surface_calculation=SurfaceCalculation.INTERNAL,
                p_focus=20.0,
                q_focus=10.0,
                grazing_angle=0.003),
            coordinates=coordinates_syned)
    elif surface_type == "hyperbolic_cylinder":
        mirror1 = S4HyperboloidMirrorElement(
            optical_element=S4HyperboloidMirror(
                name="M1",
                boundary_shape=boundary_shape,
                is_cylinder=True,
                cylinder_direction=Direction.TANGENTIAL,
                surface_calculation=SurfaceCalculation.INTERNAL,
                p_focus=20.0,
                q_focus=10.0,
                grazing_angle=0.003),
            coordinates=coordinates_syned)
    elif surface_type == "paraboloid":
        mirror1 = S4ParaboloidMirrorElement(optical_element=S4ParaboloidMirror(
            name="M1",
            boundary_shape=boundary_shape,
            is_cylinder=False,
            surface_calculation=SurfaceCalculation.INTERNAL,
            at_infinity=Side.SOURCE,
            p_focus=20.0,
            q_focus=10.0,
            grazing_angle=0.003),
                                            coordinates=coordinates_syned)
    elif surface_type == "parabolic_cylinder":
        mirror1 = S4ParaboloidMirrorElement(optical_element=S4ParaboloidMirror(
            name="M1",
            boundary_shape=boundary_shape,
            is_cylinder=True,
            cylinder_direction=Direction.TANGENTIAL,
            surface_calculation=SurfaceCalculation.INTERNAL,
            at_infinity=Side.SOURCE,
            p_focus=20.0,
            q_focus=10.0,
            grazing_angle=0.003),
                                            coordinates=coordinates_syned)
    elif surface_type == "conic":
        mirror1 = S4ConicMirrorElement(optical_element=S4ConicMirror(
            name="M1",
            boundary_shape=boundary_shape,
            conic_coefficients=[
                0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0
            ]),
                                       coordinates=coordinates_syned)
    else:
        raise Exception("undefined surface shape")

    #
    # run
    #
    print(mirror1.info())
    beam1, mirr1 = mirror1.trace_beam(beam0)

    #
    # check
    #

    if do_plot:
        plotxy(beam1, 1, 3, nbins=101, nolost=1, title=surface_type)
コード例 #20
0
def run_conic(kind="conic"):
    #
    # shadow3
    #
    if kind == "conic":
        from shadow4tests.oasys_workspaces.mirrors_branch5_conic import define_source, run_source, define_beamline, run_beamline
    else:
        raise Exception("Bad input")

    oe0 = define_source()
    beam3_source = run_source(oe0)



    #
    # shadow4
    #

    from shadow4.syned.element_coordinates import ElementCoordinates

    oe = define_beamline()[0]

    beam4_source = Beam.initialize_from_array(beam3_source.rays)
    beam4 = beam4_source


    check_congruence(oe)


    #
    # shadow definitions
    #



    name = "Conic Mirror (%s) " % kind
    mirror1 = S4ConicMirrorElement(
        optical_element=S4ConicMirror(
                name=name,
                boundary_shape=None,
                conic_coefficients=oe.CCC.tolist(),
            # inputs related to mirror reflectivity
                f_reflec=oe.F_REFLEC,  # reflectivity of surface: 0=no reflectivity, 1=full polarization
                # f_refl=0,  # 0=prerefl file, 1=electric susceptibility, 2=user defined file (1D reflectivity vs angle)
                #             # 3=user defined file (1D reflectivity vs energy), # 4=user defined file (2D reflectivity vs energy and angle)
                # file_refl="",  # preprocessor file fir f_refl=0,2,3,4
                # refraction_index=1.0  # refraction index (complex) for f_refl=1
                ),
        coordinates=ElementCoordinates(
                p=oe.T_SOURCE,
                q=oe.T_IMAGE,
                angle_radial=numpy.radians(oe.T_INCIDENCE),
                ),
    )

    print(mirror1.info())

    #
    # run
    #

    beam4, mirr4 = mirror1.trace_beam(beam_in=beam4, flag_lost_value=-11000)



    #
    # compare
    #
    oe_list = define_beamline()
    beam3 = run_beamline(beam3_source, oe_list)

    plotxy(beam3, 1, 3, nbins=201, nolost=1, title="%s shadow3" % name)
    plotxy(beam4, 1, 3, nbins=201, nolost=1, title="%s shadow4" % name)

    from shadow4tests.compatibility.compare_beams import check_six_columns_mean_and_std, check_almost_equal

    check_six_columns_mean_and_std(beam3, beam4, do_assert=True, do_plot=False, assert_value=1e-6)
    check_almost_equal(beam3, beam4, do_assert = True, level=3)
コード例 #21
0
# input_wavefront.set_spherical_wave(radius=100,complex_amplitude=numpy.abs(input_wavefront.get_intensity()) )
# plot(input_wavefront.get_abscissas()*1e6,input_wavefront.get_intensity())

from wofry.beamline.optical_elements.ideal_elements.screen import WOScreen1D

optical_element = WOScreen1D()

#
# propagating
#
#
propagation_elements = PropagationElements()
beamline_element = BeamlineElement(
    optical_element=optical_element,
    coordinates=ElementCoordinates(p=-100.000000,
                                   q=0.000000,
                                   angle_radial=numpy.radians(0.000000),
                                   angle_azimuthal=numpy.radians(0.000000)))
propagation_elements.add_beamline_element(beamline_element)
propagation_parameters = PropagationParameters(
    wavefront=input_wavefront.duplicate(),
    propagation_elements=propagation_elements)
propagation_parameters.set_additional_parameters('magnification_x',
                                                 0.01)  #0.010000)

#
propagator = PropagationManager.Instance()
try:
    propagator.add_propagator(FresnelZoom1D())
except:
    pass
output_wavefront = propagator.do_propagation(
コード例 #22
0
        ruling_coeff_linear=260818.35944225,
        ruling_coeff_quadratic=260818.35944225,
        ruling_coeff_cubic=13648.21037618,
        ruling_coeff_quartic=0.0,
        coating=None,
        coating_thickness=None,
        f_central=False,
        f_phot_cent=0,
        phot_cent=8000.0,
        material_constants_library_flag=
        0,  # 0=xraylib, 1=dabax, 2=shadow preprocessor
        file_refl="",
        order=0,
        f_ruling=0,
    )

    coordinates_syned = ElementCoordinates(
        p=10.0,
        q=6.0,
        angle_radial=88.840655 * numpy.pi / 180,
        angle_radial_out=87.588577 * numpy.pi / 180,
        angle_azimuthal=0.0)

    ge = S4PlaneGratingElement(optical_element=g,
                               coordinates=coordinates_syned)

    print(ge.info())

    beam_out = ge.trace_beam(beam)
    plotxy(beam_out[0], 1, 3, title="Image 0", nbins=201)
コード例 #23
0
    def __init__(self, optical_element=None, coordinates=None):
        super().__init__(optical_element if optical_element is not None else S4Grating(),
                         coordinates if coordinates is not None else ElementCoordinates())

        self.align_grating()
コード例 #24
0
def example_branch_4(do_plot=True, f_refl=0):

    #
    # source
    #
    # beam0 = Beam.initialize_as_pencil(N=500)
    source = SourceGaussian.initialize_from_keywords(
        number_of_rays=100000,
        sigmaX=0.0,
        sigmaY=0.0,
        sigmaZ=0.0,
        sigmaXprime=1e-6,
        sigmaZprime=1e-6,
    )
    beam0 = Beam()
    numpy.random.seed(123456)
    beam0.genSource(source)
    beam0.set_photon_wavelength(5e-10)
    print(beam0.info())

    if do_plot:
        plotxy(beam0, 4, 6, title="Image 0", nbins=201)

    #
    # syned definitopns
    #

    # surface shape
    # boundaries
    rlen1 = 5e-05
    rlen2 = 5e-05
    rwidx1 = 2e-05
    rwidx2 = 2e-05

    boundary_shape = Rectangle(x_left=-rwidx2,
                               x_right=rwidx1,
                               y_bottom=-rlen2,
                               y_top=rlen1)

    coordinates_syned = ElementCoordinates(p=10.0,
                                           q=6.0,
                                           angle_radial=numpy.radians(88.8))

    #
    # shadow definitions
    #
    if f_refl == 0:  # prerefl

        PreRefl.prerefl(interactive=False,
                        SYMBOL="SiC",
                        DENSITY=3.217,
                        FILE="SiC.dat",
                        E_MIN=100.0,
                        E_MAX=20000.0,
                        E_STEP=100.0)
        mirror1 = S4ConicMirrorElement(optical_element=S4ConicMirror(
            name="M1",
            conic_coefficients=[
                0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0
            ],
            boundary_shape=boundary_shape,
            f_reflec=1,
            f_refl=f_refl,
            file_refl="SiC.dat"),
                                       coordinates=coordinates_syned)
    elif f_refl == 1:  # refraction index
        import xraylib
        refraction_index = xraylib.Refractive_Index("SiC", 2.4797, 3.217)
        mirror1 = S4ConicMirrorElement(optical_element=S4ConicMirror(
            name="M1",
            conic_coefficients=[
                0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0
            ],
            boundary_shape=boundary_shape,
            f_reflec=1,
            f_refl=f_refl,
            file_refl="",
            refraction_index=refraction_index),
                                       coordinates=coordinates_syned)
    elif f_refl == 2:  # user file: 1D  vs angle
        mirror1 = S4ConicMirrorElement(optical_element=S4ConicMirror(
            name="M1",
            conic_coefficients=[
                0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0
            ],
            boundary_shape=boundary_shape,
            f_reflec=1,
            f_refl=f_refl,
            file_refl="../../oasys_workspaces/xoppy_f1f2_139980555361648.dat"),
                                       coordinates=coordinates_syned)
    elif f_refl == 3:  # user file 1D vs energy
        mirror1 = S4ConicMirrorElement(optical_element=S4ConicMirror(
            name="M1",
            conic_coefficients=[
                0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0
            ],
            boundary_shape=boundary_shape,
            f_reflec=1,
            f_refl=f_refl,
            file_refl="../../oasys_workspaces/xoppy_f1f2_139981943656272.dat"),
                                       coordinates=coordinates_syned)
    elif f_refl == 4:  # user file
        mirror1 = S4ConicMirrorElement(optical_element=S4ConicMirror(
            name="M1",
            conic_coefficients=[
                0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0
            ],
            boundary_shape=boundary_shape,
            f_reflec=1,
            f_refl=f_refl,
            file_refl="../../oasys_workspaces/xoppy_f1f2_139980938100080.dat"),
                                       coordinates=coordinates_syned)

    print(mirror1.info())

    #
    # run
    #
    beam1, mirr1 = mirror1.trace_beam(beam0)
    print(mirr1.info())

    #
    # check
    #

    if do_plot:
        plotxy(beam1, 1, 3, title="Image 1", nbins=101, nolost=1)
        plotxy(mirr1, 2, 1, title="Footprint 1", nbins=101, nolost=1)
コード例 #25
0
        for i, element in enumerate(self.get_beamline_elements()):
            try:
                beam1, mirr1 = element.trace_beam(beam_in=beam0, **params)
            except:
                raise Exception("Error running beamline element # %d" %
                                (i + 1))

            beam0 = beam1
            mirr0 = mirr1

        return beam0, mirr0


if __name__ == "__main__":
    from shadow4.beamline.optical_elements.mirrors.s4_mirror import S4Mirror, S4MirrorElement
    from shadow4.syned.element_coordinates import ElementCoordinates

    m1 = S4Mirror()
    m2 = S4Mirror()

    e1 = S4MirrorElement(m1, ElementCoordinates())
    e2 = S4MirrorElement(m2, ElementCoordinates())

    bl = S4Beamline(beamline_elements_list=[e1, e2])

    print(bl.info())

    print(bl.to_python_code())

    # print(bl.run_beamline())
コード例 #26
0
    def _back_propagation_for_size_calculation(self,
                                               theta,
                                               radiation_flux,
                                               photon_energy,
                                               distance=100.0,
                                               magnification=0.010000):
        """
        Calculate the radiation_flux vs theta at a "distance"
        Back propagate to -distance
        The result is the size distrubution

        :param theta:
        :param radiation_flux:
        :param photon_energy:
        :param distance:
        :param magnification:
        :return: None; stores results in self._photon_size_distribution
        """

        from wofry.propagator.wavefront1D.generic_wavefront import GenericWavefront1D
        from wofry.propagator.propagator import PropagationManager, PropagationElements, PropagationParameters
        from syned.beamline.beamline_element import BeamlineElement
        from shadow4.syned.element_coordinates import ElementCoordinates
        from wofryimpl.propagator.propagators1D.fresnel_zoom import FresnelZoom1D
        from wofryimpl.beamline.optical_elements.ideal_elements.screen import WOScreen1D

        input_wavefront = GenericWavefront1D(
        ).initialize_wavefront_from_arrays(theta * distance,
                                           numpy.sqrt(radiation_flux) + 0j)
        input_wavefront.set_photon_energy(photon_energy)
        input_wavefront.set_spherical_wave(
            radius=distance, complex_amplitude=numpy.sqrt(radiation_flux) + 0j)
        # input_wavefront.save_h5_file("tmp2.h5","wfr")

        optical_element = WOScreen1D()
        #
        # propagating
        #
        #
        propagation_elements = PropagationElements()
        beamline_element = BeamlineElement(
            optical_element=optical_element,
            coordinates=ElementCoordinates(
                p=0.0,
                q=-distance,
                angle_radial=numpy.radians(0.000000),
                angle_azimuthal=numpy.radians(0.000000)))
        propagation_elements.add_beamline_element(beamline_element)
        propagation_parameters = PropagationParameters(
            wavefront=input_wavefront.duplicate(),
            propagation_elements=propagation_elements)
        propagation_parameters.set_additional_parameters(
            'magnification_x', magnification)

        #
        propagator = PropagationManager.Instance()
        try:
            propagator.add_propagator(FresnelZoom1D())
        except:
            pass
        output_wavefront = propagator.do_propagation(
            propagation_parameters=propagation_parameters,
            handler_name='FRESNEL_ZOOM_1D')

        self.__result_photon_size_distribution = {
            "x": output_wavefront.get_abscissas(),
            "y": output_wavefront.get_intensity()
        }
コード例 #27
0
def example_branch_1(do_plot=True):
    #
    # source
    #
    source = SourceGaussian.initialize_from_keywords(
        number_of_rays=100000,
        sigmaX=0.0,
        sigmaY=0.0,
        sigmaZ=0.0,
        sigmaXprime=1e-6,
        sigmaZprime=1e-6,
    )
    beam0 = Beam()
    beam0.genSource(source)
    print(beam0.info())

    if do_plot:
        plotxy(beam0, 4, 6, title="Image 0", nbins=201)

    #
    # syned definitopns
    #

    # surface shape

    # boundaries
    # boundary_shape = None
    rlen1 = 5e-05
    rlen2 = 5e-05
    rwidx1 = 2e-05
    rwidx2 = 2e-05
    boundary_shape = Rectangle(x_left=-rwidx2,
                               x_right=rwidx1,
                               y_bottom=-rlen2,
                               y_top=rlen1)
    # boundary_shape = Rectangle(x_left=-1e-05, x_right=2e-05, y_bottom=-5e-04, y_top=7e-04)
    # boundary_shape = Ellipse(a_axis_min=-rwidx2/2, a_axis_max=rwidx2/2, b_axis_min=-rlen2/2, b_axis_max=rlen2/2)
    # boundary_shape = Ellipse(a_axis_min=-0e-05, a_axis_max=1e-05, b_axis_min=-1.5e-05, b_axis_max=2.5e-05)
    # boundary_shape = Ellipse(a_axis_min=0, a_axis_max=1e-05, b_axis_min=-0.0005, b_axis_max=0)

    # rlen1 = -2.5e-05
    # rlen2 = 5e-05
    # rwidx1 = 1e-05
    # rwidx2 = 2e-05
    #
    # boundary_shape = TwoEllipses(
    #     a1_axis_min=-rwidx1 / 2, a1_axis_max=rwidx1 / 2, b1_axis_min=-rlen1 / 2, b1_axis_max=rlen1 / 2,
    #     a2_axis_min=-rwidx2 / 2, a2_axis_max=rwidx2 / 2, b2_axis_min=-rlen2 / 2, b2_axis_max=rlen2 / 2)

    coordinates_syned = ElementCoordinates(p=10.0,
                                           q=6.0,
                                           angle_radial=numpy.radians(88.8))

    #
    # shadow definitions
    #
    mirror1 = S4ConicMirrorElement(optical_element=S4ConicMirror(
        name="M1",
        conic_coefficients=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0],
        boundary_shape=boundary_shape),
                                   coordinates=coordinates_syned)

    print(mirror1.info())

    #
    # run
    #
    beam1, mirr1 = mirror1.trace_beam(beam_in=beam0)
    print(mirr1.info())

    #
    # check
    #

    if do_plot:
        plotxy(beam1, 1, 3, title="Image 1", nbins=101, nolost=1)
        plotxy(mirr1, 2, 1, title="Footprint 1", nbins=101, nolost=1)

    #
    # M2
    #

    mirror2 = S4ConicMirrorElement(optical_element=S4ConicMirror(
        conic_coefficients=[0, 0, 0, 0, 0, 0, 0, 0, -1, 0],
        boundary_shape=Rectangle(-100e-6, 100e-6, -150e-6, 150e-6)),
                                   coordinates=ElementCoordinates(
                                       p=10.0,
                                       q=100.0,
                                       angle_radial=(0.5 * numpy.pi - 0.003)))

    print(mirror2.info())
    #
    #
    if do_plot:
        beam2, mirr2 = mirror2.trace_beam(beam1)
        plotxy(beam2, 1, 3, title="Image 2", nbins=101, nolost=1)
        plotxy(mirr2, 2, 1, title="Footprint 2", nbins=101, nolost=1)