Double slit in a beamline

[1]:
%matplotlib inline
import matplotlib
matplotlib.rcParams['figure.dpi'] = 100

try:
    import srxraylib.plot.gol as _gol
    _gol.set_qt = lambda: None
except Exception:
    pass

[2]:

from syned.util.json_tools import load_from_json_file from syned.storage_ring.electron_beam import ElectronBeam from syned.storage_ring.magnetic_structures.undulator import Undulator from syned.beamline.optical_elements.ideal_elements.screen import Screen from syned.beamline.optical_elements.absorbers.slit import Slit from syned.storage_ring.light_source import LightSource from syned.beamline.beamline import Beamline from syned.beamline.beamline_element import BeamlineElement from syned.beamline.element_coordinates import ElementCoordinates from syned.beamline.shape import MultiplePatch # this is an example of a double slit (a slit with two rectangular apertures). if __name__ == "__main__": # source src1 = ElectronBeam.initialize_as_pencil_beam(energy_in_GeV=6.0,current=0.2) src2 = Undulator() lightsource1 = LightSource("test_source",src1, src2) # check file o/i for test lightsource1.to_json("tmp.json") tmp = load_from_json_file("tmp.json") print("returned class: ",type(tmp)) print(lightsource1.to_dictionary()) print(tmp.to_dictionary()) assert (lightsource1.to_dictionary() == tmp.to_dictionary()) #optical elements patches = MultiplePatch() patches.append_rectangle(-0.02,-0.01,-0.001,0.001) patches.append_rectangle(0.01,0.02,-0.001,0.001) slit1 = Slit(name="slit1", boundary_shape=patches) # check file o/i for test individual elements mylist = [src1, src2, slit1] for i,element in enumerate(mylist): element.to_json("tmp_%d.json"%i) for i, element in enumerate(mylist): print("\nloading element %d"%i) tmp = load_from_json_file("tmp_%d.json"%i) print("returned class: ",type(tmp)) print(mylist[i].to_dictionary()) print(tmp.to_dictionary()) assert (mylist[i].to_dictionary() == tmp.to_dictionary()) # test Beamline bl_slit1 = BeamlineElement(optical_element=slit1, coordinates=ElementCoordinates(p=10.0,q=3.0)) BL = Beamline(light_source=lightsource1, beamline_elements_list=[bl_slit1]) # check file o/i for test full beamline BL.to_json("tmp_bl.json") tmp = load_from_json_file("tmp_bl.json") print("returned class: ",type(tmp)) print(BL.to_dictionary()) print(tmp.to_dictionary()) assert(BL.to_dictionary() == tmp.to_dictionary()) print(BL.info())
File written to disk: tmp.json
returned class:  <class 'syned.storage_ring.light_source.LightSource'>
OrderedDict({'CLASS_NAME': 'LightSource', 'name': 'test_source', 'electron_beam': OrderedDict({'CLASS_NAME': 'ElectronBeam', 'energy_in_GeV': 6.0, 'energy_spread': 0.0, 'current': 0.2, 'number_of_bunches': 1, 'moment_xx': 0.0, 'moment_xxp': 0.0, 'moment_xpxp': 0.0, 'moment_yy': 0.0, 'moment_yyp': 0.0, 'moment_ypyp': 0.0, 'dispersion_x': 0.0, 'dispersion_y': 0.0, 'dispersionp_x': 0.0, 'dispersionp_y': 0.0}), 'magnetic_structure': OrderedDict({'CLASS_NAME': 'Undulator', 'K_vertical': 0.0, 'K_horizontal': 0.0, 'period_length': 0.0, 'number_of_periods': 1.0})})
OrderedDict({'CLASS_NAME': 'LightSource', 'name': 'test_source', 'electron_beam': OrderedDict({'CLASS_NAME': 'ElectronBeam', 'energy_in_GeV': 6.0, 'energy_spread': 0.0, 'current': 0.2, 'number_of_bunches': 1, 'moment_xx': 0.0, 'moment_xxp': 0.0, 'moment_xpxp': 0.0, 'moment_yy': 0.0, 'moment_yyp': 0.0, 'moment_ypyp': 0.0, 'dispersion_x': 0.0, 'dispersion_y': 0.0, 'dispersionp_x': 0.0, 'dispersionp_y': 0.0}), 'magnetic_structure': OrderedDict({'CLASS_NAME': 'Undulator', 'K_vertical': 0.0, 'K_horizontal': 0.0, 'period_length': 0.0, 'number_of_periods': 1.0})})
File written to disk: tmp_0.json
File written to disk: tmp_1.json
File written to disk: tmp_2.json

loading element 0
returned class:  <class 'syned.storage_ring.electron_beam.ElectronBeam'>
OrderedDict({'CLASS_NAME': 'ElectronBeam', 'energy_in_GeV': 6.0, 'energy_spread': 0.0, 'current': 0.2, 'number_of_bunches': 1, 'moment_xx': 0.0, 'moment_xxp': 0.0, 'moment_xpxp': 0.0, 'moment_yy': 0.0, 'moment_yyp': 0.0, 'moment_ypyp': 0.0, 'dispersion_x': 0.0, 'dispersion_y': 0.0, 'dispersionp_x': 0.0, 'dispersionp_y': 0.0})
OrderedDict({'CLASS_NAME': 'ElectronBeam', 'energy_in_GeV': 6.0, 'energy_spread': 0.0, 'current': 0.2, 'number_of_bunches': 1, 'moment_xx': 0.0, 'moment_xxp': 0.0, 'moment_xpxp': 0.0, 'moment_yy': 0.0, 'moment_yyp': 0.0, 'moment_ypyp': 0.0, 'dispersion_x': 0.0, 'dispersion_y': 0.0, 'dispersionp_x': 0.0, 'dispersionp_y': 0.0})

loading element 1
returned class:  <class 'syned.storage_ring.magnetic_structures.undulator.Undulator'>
OrderedDict({'CLASS_NAME': 'Undulator', 'K_vertical': 0.0, 'K_horizontal': 0.0, 'period_length': 0.0, 'number_of_periods': 1.0})
OrderedDict({'CLASS_NAME': 'Undulator', 'K_vertical': 0.0, 'K_horizontal': 0.0, 'period_length': 0.0, 'number_of_periods': 1.0})

loading element 2
returned class:  <class 'syned.beamline.optical_elements.absorbers.slit.Slit'>
OrderedDict({'CLASS_NAME': 'Slit', 'name': 'slit1', 'boundary_shape': OrderedDict({'CLASS_NAME': 'MultiplePatch', 'patch_list': [OrderedDict({'CLASS_NAME': 'Rectangle', 'x_left': -0.02, 'x_right': -0.01, 'y_bottom': -0.001, 'y_top': 0.001}), OrderedDict({'CLASS_NAME': 'Rectangle', 'x_left': 0.01, 'x_right': 0.02, 'y_bottom': -0.001, 'y_top': 0.001})]})})
OrderedDict({'CLASS_NAME': 'Slit', 'name': 'slit1', 'boundary_shape': OrderedDict({'CLASS_NAME': 'MultiplePatch', 'patch_list': [OrderedDict({'CLASS_NAME': 'Rectangle', 'x_left': -0.02, 'x_right': -0.01, 'y_bottom': -0.001, 'y_top': 0.001}), OrderedDict({'CLASS_NAME': 'Rectangle', 'x_left': 0.01, 'x_right': 0.02, 'y_bottom': -0.001, 'y_top': 0.001})]})})
File written to disk: tmp_bl.json
returned class:  <class 'syned.beamline.beamline.Beamline'>
OrderedDict({'CLASS_NAME': 'Beamline', 'light_source': OrderedDict({'CLASS_NAME': 'LightSource', 'name': 'test_source', 'electron_beam': OrderedDict({'CLASS_NAME': 'ElectronBeam', 'energy_in_GeV': 6.0, 'energy_spread': 0.0, 'current': 0.2, 'number_of_bunches': 1, 'moment_xx': 0.0, 'moment_xxp': 0.0, 'moment_xpxp': 0.0, 'moment_yy': 0.0, 'moment_yyp': 0.0, 'moment_ypyp': 0.0, 'dispersion_x': 0.0, 'dispersion_y': 0.0, 'dispersionp_x': 0.0, 'dispersionp_y': 0.0}), 'magnetic_structure': OrderedDict({'CLASS_NAME': 'Undulator', 'K_vertical': 0.0, 'K_horizontal': 0.0, 'period_length': 0.0, 'number_of_periods': 1.0})}), 'beamline_elements_list': [OrderedDict({'CLASS_NAME': 'BeamlineElement', 'optical_element': OrderedDict({'CLASS_NAME': 'Slit', 'name': 'slit1', 'boundary_shape': OrderedDict({'CLASS_NAME': 'MultiplePatch', 'patch_list': [OrderedDict({'CLASS_NAME': 'Rectangle', 'x_left': -0.02, 'x_right': -0.01, 'y_bottom': -0.001, 'y_top': 0.001}), OrderedDict({'CLASS_NAME': 'Rectangle', 'x_left': 0.01, 'x_right': 0.02, 'y_bottom': -0.001, 'y_top': 0.001})]})}), 'coordinates': OrderedDict({'CLASS_NAME': 'ElementCoordinates', 'p': 10.0, 'q': 3.0, 'angle_radial': 0.0, 'angle_radial_out': None, 'angle_azimuthal': 0.0})})]})
OrderedDict({'CLASS_NAME': 'Beamline', 'light_source': OrderedDict({'CLASS_NAME': 'LightSource', 'name': 'test_source', 'electron_beam': OrderedDict({'CLASS_NAME': 'ElectronBeam', 'energy_in_GeV': 6.0, 'energy_spread': 0.0, 'current': 0.2, 'number_of_bunches': 1, 'moment_xx': 0.0, 'moment_xxp': 0.0, 'moment_xpxp': 0.0, 'moment_yy': 0.0, 'moment_yyp': 0.0, 'moment_ypyp': 0.0, 'dispersion_x': 0.0, 'dispersion_y': 0.0, 'dispersionp_x': 0.0, 'dispersionp_y': 0.0}), 'magnetic_structure': OrderedDict({'CLASS_NAME': 'Undulator', 'K_vertical': 0.0, 'K_horizontal': 0.0, 'period_length': 0.0, 'number_of_periods': 1.0})}), 'beamline_elements_list': [OrderedDict({'CLASS_NAME': 'BeamlineElement', 'optical_element': OrderedDict({'CLASS_NAME': 'Slit', 'name': 'slit1', 'boundary_shape': OrderedDict({'CLASS_NAME': 'MultiplePatch', 'patch_list': [OrderedDict({'CLASS_NAME': 'Rectangle', 'x_left': -0.02, 'x_right': -0.01, 'y_bottom': -0.001, 'y_top': 0.001}), OrderedDict({'CLASS_NAME': 'Rectangle', 'x_left': 0.01, 'x_right': 0.02, 'y_bottom': -0.001, 'y_top': 0.001})]})}), 'coordinates': OrderedDict({'CLASS_NAME': 'ElementCoordinates', 'p': 10.0, 'q': 3.0, 'angle_radial': 0.0, 'angle_radial_out': None, 'angle_azimuthal': 0.0})})]})
    -------Beamline---------
        -------LightSource---------
        name: 'test_source'  # Name
        -------ElectronBeam---------
        energy_in_GeV: 6.0 GeV # Electron beam energy
        energy_spread: 0.0  # Electron beam energy spread (relative)
        current: 0.2 A # Electron beam current
        number_of_bunches: 1  # Number of bunches
        moment_xx: 0.0 m^2 # Moment (spatial^2, horizontal)
        moment_xxp: 0.0 m # Moment (spatial-angular, horizontal)
        moment_xpxp: 0.0  # Moment (angular^2, horizontal)
        moment_yy: 0.0 m^2 # Moment (spatial^2, vertical)
        moment_yyp: 0.0 m # Moment (spatial-angular, vertical)
        moment_ypyp: 0.0  # Moment (angular^2, vertical)
        dispersion_x: 0.0  # Dispersion (horizontal)
        dispersion_y: 0.0  # Dispersion (vertical)
        dispersionp_x: 0.0  # Dispersion Derivative (horizontal)
        dispersionp_y: 0.0  # Dispersion Derivative (vertical)
        -------Undulator---------
        K_vertical: 0.0  # K value (vertical)
        K_horizontal: 0.0  # K value (horizontal)
        period_length: 0.0 m # Period length
        number_of_periods: 1.0  # Number of periods
        -------BeamlineElement---------
        -------Slit---------
        name: 'slit1'  # Name
        -------MultiplePatch---------
        -------Rectangle---------
        x_left: -0.02 m # x (width) minimum (signed)
        x_right: -0.01 m # x (width) maximum (signed)
        y_bottom: -0.001 m # y (length) minimum (signed)
        y_top: 0.001 m # y (length) maximum (signed)
        -------Rectangle---------
        x_left: 0.01 m # x (width) minimum (signed)
        x_right: 0.02 m # x (width) maximum (signed)
        y_bottom: -0.001 m # y (length) minimum (signed)
        y_top: 0.001 m # y (length) maximum (signed)
        -------ElementCoordinates---------
        p: 10.0 m # distance from previous continuation plane
        q: 3.0 m # distance to next continuation plane
        angle_radial: 0.0 rad # incident angle [to normal]
        angle_radial_out: None rad # output angle [to normal]
        angle_azimuthal: 0.0 rad # rotation along beam axis