Exemple #1
0
def example_point_source():

    a = SourceGaussian.initialize_point_source(
        number_of_rays=10000,
        sigmaXprime=3e-6,
        sigmaZprime=1e-6,
        real_space_center=[0.0, 0.0, 0.0],
        direction_space_center=[0.0, 0.0])
    print(a.info())

    x, y, z = a.get_arrays_real_space()
    print("x.shape:", x.shape)
    print("y.shape:", y.shape)
    print("z.shape:", z.shape)

    xp, zp = a.get_arrays_direction_space()
    print("xp.shape:", xp.shape)
    print("zp.shape:", zp.shape)

    VP = a.get_volume_divergences()
    print("VP", VP.shape, VP.size)

    Vx = a.get_volume_real_space()
    print("Vx: ", Vx.shape)

    V = a.get_volume()
    print("V: ", V.shape)

    beam = a.get_beam()

    plotxy(beam, 4, 6, title="point source")
Exemple #2
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))
Exemple #3
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")
Exemple #4
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)
Exemple #5
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'")
Exemple #6
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))
Exemple #7
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())
Exemple #8
0
def example_collimated_source():
    #
    a = SourceGaussian.initialize_collimated_source(
        number_of_rays=10000,
        sigmaX=1.0,
        sigmaY=0.0,
        sigmaZ=1.0,
        real_space_center=[0.0, 0.0, 0.0],
        direction_space_center=[0.0, 0.0])

    print(a.info())
    beam = a.get_beam()

    plotxy(beam, 1, 3, title="collimated source")

    plot_scatter(beam.get_column(1),
                 beam.get_column(3),
                 xtitle="col 1",
                 ytitle="col 3",
                 title="collimated source")
    print(beam.info())
Exemple #9
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)
Exemple #10
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)
Exemple #11
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)
Exemple #12
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))
Exemple #13
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)
Exemple #14
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)
Exemple #15
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)
Exemple #16
0
    print(mirror1.info())

    mirror1e = S4PlaneMirrorElement(optical_element=mirror1,
                                    coordinates=coordinates_syned)
    #
    # run
    #
    beam1, mirr1 = mirror1e.trace_beam(beam0, flag_lost_value=-11000.0)
    print(mirror1e.info())

    #
    # check
    #

    if do_plot:
        plotxy(beam3, 1, 3, title="Image 1 shadow3", nbins=101, nolost=1)
        beam1s3 = Beam3.initialize_from_shadow4_beam(beam1)
        plotxy(beam1s3, 1, 3, title="Image 1 shadow4", nbins=101, nolost=1)

    mirr3 = Beam3(N=beam0.rays.shape[0])
    mirr3.load("mirr.01")

    print("\ncol#   m-shadow4  m-shadow3  source")
    for i in range(18):
        print(
            "col%d   %20.10f  %20.10f  %20.10f  " %
            (i + 1, mirr1.rays[10, i], mirr3.rays[10, i], source3.rays[10, i]))
        if do_assert:
            assert_almost_equal(mirr1.rays[:, i], mirr3.rays[:, i], 1)

    print("\ncol#   shadow4  shadow3  source")
Exemple #17
0
                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
    #
    beam3 = run_beamline(beam3_source, define_beamline())

    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)
    check_almost_equal(beam3, beam4, do_assert=True, level=2)
Exemple #18
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)
Exemple #19
0
    print(patches.info())

    for i, patch in enumerate(patches.get_patches()):
        print(">> patch ", i, patch.info())

    # patches = MultiplePatch()
    # patches.append_polygon([-1,-1,1,1],[-1,1,1,-1])

    source3, beam3 = run_shadow3()

    #
    if do_plot:
        plotxy(beam3,
               1,
               3,
               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)
Exemple #20
0
                                       bending_magnet_magnetic_structure=bm)

    print(ls_bm.info())

    beam4 = ls_bm.get_beam(
        F_COHER=oe0.F_COHER,
        NRAYS=oe0.NPOINT,
        SEED=oe0.ISTAR1,
        EPSI_DX=oe0.EPSI_DX,
        EPSI_DZ=oe0.EPSI_DZ,
        psi_interval_in_units_one_over_gamma=None,
        psi_interval_number_of_points=1001,
        verbose=False,
    )

    #
    # compare
    #

    plotxy(beam3, 1, 3, nbins=201, title="BM shadow3")
    plotxy(beam4, 1, 3, nbins=201, title="BM shadow4")

    from shadow4tests.compatibility.compare_beams import check_six_columns_mean_and_std

    check_six_columns_mean_and_std(beam3,
                                   beam4,
                                   do_plot=True,
                                   do_assert=True,
                                   assert_value=1e-2,
                                   to_meters=to_meters)
Exemple #21
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)
Exemple #22
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))
Exemple #23
0
    set_qt()
    do_plot = True

    source = SourceGaussian.initialize_from_keywords(number_of_rays=10000,
                                                     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)

    rlen1 = 0.6
    rlen2 = 0.6
    rwidx1 = 0.05
    rwidx2 = 0.05

    base_element = S4ToroidalMirror(name="M1b",
                                    surface_calculation=SurfaceCalculation.EXTERNAL,
                                    min_radius=0.157068,
                                    maj_radius=358.124803 - 0.157068,
                                    boundary_shape=Rectangle(x_left=-rwidx2, x_right=rwidx1, y_bottom=-rlen2,
                                                             y_top=rlen1))

    # base_element = S4SphereMirror(name="M1b",
    #                                 surface_calculation=SurfaceCalculation.EXTERNAL,
Exemple #24
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)
Exemple #25
0
        #
        # shadow3
        #
        beam3, oe0 = run_shadow3(photon_energy, n_rays=n_rays, emittance=False)

        #
        # shadow4
        #
        beam4 = run_shadow4(photon_energy, n_rays=n_rays, emittance=False)

        tkt3 = beam3.histo2(4, 6, nolost=1, ref=23, nbins=201)
        beam4_3 = Beam3.initialize_from_shadow4_beam(beam4)
        tkt4 = beam4_3.histo2(4, 6, nolost=1, ref=23, nbins=201)

        if i == 0:
            plotxy(beam3, 4, 6, nolost=1, ref=23, nbins=201, title="shadow3")
            plotxy(beam4_3, 4, 6, nolost=1, ref=23, nbins=201, title="shadow4")

        print(">>>>>", photon_energy, tkt3["fwhm_v"], tkt4["fwhm_v"],
              tkt4["fwhm_v"].shape)
        fwhm_v_3[i] = tkt3["fwhm_v"]
        fwhm_v_4[i] = tkt4["fwhm_v"]

    f = open("tmp.dat", 'w')
    for i in range(photon_energies.size):
        f.write("%f  %f  %f %g \n" %
                (photon_energies[i], fwhm_v_3[i], fwhm_v_4[i],
                 (fwhm_v_3[i] - fwhm_v_4[i])))
    f.close()
    print("File tmp.dat written to disk."
          )  # moved to ./test_wiggler_BEATS_JR_against_shadow3.dat