Esempio n. 1
0
def aperture(angle = 1e-03, ekev = 5.0):
    
   
    wfr= construct_SA1_wavefront(512, 512, ekev, 0.25)
    
    bl = get_beamline_object(ekev, apertures = True, surface = True,
                             crop = ["d1", "HOM1"], theta_HOM = angle)
    
    bl.propagate(wfr)
     
    return wfr.get_intensity().sum()
Esempio n. 2
0
def no_mirror(ekev = 5.0):
    wfr= construct_SA1_wavefront(512, 512, ekev, 0.25)
        
    bl = get_beamline_object(ekev, apertures = False, surface = False,
                             crop = ["d1", "d1"])
    
    bl.propagate(wfr)
    ii = wfr.get_intensity().sum()
    plot_intensity_map(wfr)
    
    return ii
Esempio n. 3
0
def test_coherent_pulse_fwhm(E, sdir=None):
    """
    Test that the FWHM of the source matches the analytical prediction
    
    :param E: list/array of energies [keV]
    :param sdir: output directory [str]
    """

    print("Testing Source Size vs. Energy and Resolution")

    sns.set()

    fig = plt.figure(figsize=[12, 8])
    ax = fig.add_subplot(111)
    ax.set_title("Source Size Radiation Dependence", fontsize=22)
    ax.set_ylabel("FWHM [$\mu$m]", fontsize=22)
    ax.set_xlabel("Radiation Energy [keV]", fontsize=22)
    ax.set_xlim([2.5, 17.5])
    ax.set_ylim([0, 55])

    E
    analytical_data = np.array([analytical_pulse_width(a) * 1e6 for a in E])

    fwhms = []

    for energy in E:
        wfr = construct_SA1_wavefront(nx=1024, ny=1024, ekev=energy, q=0.25)
        fwhms.append(calculate_fwhm(wfr)['fwhm_x'] * 1e6)

    simulation, = ax.plot(E, fwhms, 'r')
    analytical, = ax.plot(E, analytical_data, '--b')

    leg1 = ax.legend([simulation, analytical],
                     ["Simulated Data", "Analytical Model"],
                     loc='lower left',
                     fontsize=22)

    ax.add_artist(leg1)

    ax.tick_params(axis='both', which='major', labelsize=18)
    ax.tick_params(axis='both', which='minor', labelsize=14)

    if sdir is not None:
        fig.savefig(sdir + "coherent_source_test_fwhm.eps")

    plt.show()
    return wfr
Esempio n. 4
0
def define_wfr(ekev):
    """
    defines the wavefront in the plane prior to the mirror ie., after d1

    :param ekev: energy of the source
    """

    spb = Instrument()
    spb.build_elements(focus='nano')

    spb.build_beamline(focus='nano')

    spb.crop_beamline(element1="d1")

    bl = spb.get_beamline()

    wfr = construct_SA1_wavefront(512, 512, ekev, 0.25)

    bl.propagate(wfr)

    return wfr
Esempio n. 5
0
def create_mask(nx, ny):
    """
    note nx and ny are the dimensions of a single mask element
    """
    arr = np.ones([nx, ny]) * 256
    arr[arr.shape[0] // 2 - 5:arr.shape[0] // 2 + 5,
        arr.shape[1] // 2 - 5:arr.shape[1] // 2 + 5] = 0
    arr = np.tile(arr, [5, 5])
    return arr


nx = 25
ny = 25

plt.imshow(create_mask(nx, ny))
wfr = construct_SA1_wavefront(512, 512, 5, .8, mx=0, xoff=0, tiltX=0)

period = nx * wfr.get_spatial_resolution()[0] * (512 / (nx))
print(period)
wav = wfr.get_wavelength()

d = (2 * period**2) / wav

arr = create_mask(nx, ny)
np.save("/opt/arr", arr)
im = Image.fromarray(arr)
im = im.convert('RGB')
im.save("/opt/arr.png")

obj = srwloptT("/opt/arr.png",
               wfr.get_spatial_resolution()[0] * (512 / 75),
Esempio n. 6
0
def generate_wfr(nx, ny):
    
    return construct_SA1_wavefront(nx, ny, 5.0, 0.25)
Esempio n. 7
0
    #               ylabel = "z(m)",
    #               return_axes = True)
    #
    # =============================================================================
    return data_focslice


# =============================================================================
#
#     ax1.plot(data_focslice[0]*1e6, np.ones(data_focslice.shape[0])*spb.bl.params["df"]["distance"], 'r--')
#
# =============================================================================

if __name__ == '__main__':

    ekev = 9.2

    wfr = construct_SA1_wavefront(512, 512, ekev, 0.5)

    # =============================================================================
    #     sliceFocus(wfr = wfr, ekev = ekev, focus = 'micron', nslices = 500, axisName = 'x', outdir = "focus_test/")
    #     sliceFocus(wfr = wfr, ekev = ekev, focus = 'micron', nslices = 500, axisName = 'y', outdir = "focus_test/")
    #
    # =============================================================================
    df = sliceFocus(wfr=wfr,
                    ekev=ekev,
                    focus='nano',
                    nslices=50,
                    axisName='x',
                    outdir="focus_test/")
    #sliceFocus(wfr = wfr, ekev = ekev, focus = 'nano', nslices = 500, axisName = 'y', outdir = "focus_test/")
Esempio n. 8
0
    sigma = 4
    S = 4
    Seff = S/sigma

    n_samples, sampling_interval_t = temporal_sampling_requirements(pulse_time, VERBOSE = True, S = S)
    sampling_interval_w = 1/sampling_interval_t

    n_samples *= sigma

    t = np.arange(-pulse_time*4, pulse_time*4, pulse_time/n_samples)

    temporal_profile = generate_temporal_SASE_pulse(pulse_time = pulse_time,
                                                    n_samples = n_samples,
                                                    sigma = sigma,
                                                    VERBOSE = True)
    print("Number of Samples: ",n_samples)
    print(temporal_profile.dtype)
    spatial_profile = construct_SA1_wavefront(128, 128, 5.0, 0.25)

    wfr = wavefront_to_wavefield(spatial_profile, temporal_profile)

    from wpg.wpg_uti_wf import plot_intensity_map
    plot_intensity_map(wfr)
    wfr.set_electric_field_representation('f')
    from felpy.model.beamlines.exfel_spb.methods import setup_spb
    spb = setup_spb(parameter_file = "/opt/FELpy/felpy/data/params/spb-sfx_nkb_FAST.json", theta_KB = 5e-03, theta_HOM = 3.5e-03) #bl = spb.bl
    bl = spb.bl

    ## EXEC
    bl.propagate_sequential(wfr)
Esempio n. 9
0
    bl.append(s, propagation_parameters(1, 1, 1, 1, mode='fresnel'))
    bl.propagate(wfr)

    return wfr


def z_eff(z1, z2):
    return z1 * z2 / (z1 + z2)


if __name__ == '__main__':
    z = z_eff(8e-03, 3.5)
    from wpg.wpg_uti_wf import plot_intensity_map as plotIntensity
    from felpy.model.src.coherent import construct_gaussian

    wfr = construct_SA1_wavefront(1024, 1024, 9.3, 0.25)

    bl = get_beamline_object(crop="NVE")
    bl.append(Drift(2.2 + 8e-02), propagation_parameters(1 / 20, 1, 1 / 50, 1))
    bl.propagate(wfr)
    plotIntensity(wfr)
# =============================================================================
#
#     plotIntensity(wfr)
#     # print("Pixel Size: {}".format(wfr.get_spatial_resolution()))
#     propThruMaskLite(wfr)
#     plotIntensity(wfr)
#
#     bl = Beamline()
#     bl.append(Drift(z), propagation_parameters(1/10,1,1/10,1, 'quadratic'))
#     bl.propagate(wfr)
Esempio n. 10
0
    if odd_even(l) == 'odd':
        feature = f[(cx + pad - l):(cx + pad), (cy + pad):(cy + pad + l)]

    elif odd_even(l) == 'even':
        feature = f[cx + pad - l // 2:cx + pad + l // 2,
                    cy + pad - l // 2:cy + pad + l // 2]
    return feature


def window_stack(a, stepsize=1, width=3):
    n = a.shape[0]
    return np.hstack(
        [a[i:1 + n + i - width:stepsize] for i in range(0, width)])


wfr = construct_SA1_wavefront(512, 512, 5.0, q=0.1, mx=0, my=0)
w = 15e-06
wav = wfr.get_wavelength()
px = wfr.pixelsize()
z = get_required_distance(w, wfr.get_spatial_resolution()[0], wav)
print(z)
f = fresnel_criterion(w, z * 2, wav)
print(f)
z *= 2

from felpy.model.beamline import Beamline
from wpg.optical_elements import Drift
from felpy.model.tools import propagation_parameters

obj = srwloptT("/opt/FELpy/felpy/data/samples/lena.png", 0.33e-06, 0.33e-06,
               20e-06, 3.3269971E-05, 60e-06)
Esempio n. 11
0
    spb.build_elements(focus=options)
    spb.build_beamline(focus=options)

    if apertures == False and surface == 'flat':
        spb.remove_element("NVE_error")
        spb.remove_element("NHE_error")
        spb.remove_element("NKB_PSlit")

    if save_params:
        spb.export_params()

    if crop is not None:
        if type(crop) == list:
            spb.crop_beamline(*crop)
        else:
            spb.crop_beamline(crop)

    return spb


if __name__ == '__main__':
    from wpg.wpg_uti_wf import plot_intensity_map
    from felpy.model.src.coherent import construct_SA1_wavefront

    spb = setup_spb()
    bl = spb.bl
    wfr = construct_SA1_wavefront(512, 512, 5, 0.25)
    bl.propagate_sequential(wfr)
    plot_intensity_map(wfr)
Esempio n. 12
0
mask = y * phase_shift

z1 = 2
z2 = .01

bl = Beamline()

from felpy.model.src.coherent import construct_SA1_wavefront

# =============================================================================
# src = construct_gaussian(1024, 1024, ekev, extent = [-25e-04, 25e-04, -25e-04, 25e-04],
#                      sigX = .5e-04, sigY = .5e-04, divergence = np.arctan(13.5e-03/8))
#
# =============================================================================
q = 0.50
src = construct_SA1_wavefront(1024, 1024, 25.0, q)

plot_ii(src)

speckle = define_speckle_mask("../../data/samples/checkerboard-pattern.jpg",
                              rx=1e-8,
                              ry=1e-8,
                              sample_thickness=150e-06,
                              sample_delta=4e-04,
                              plot=True,
                              ekev=25)

bl.append(Drift(10), propagation_parameters(1, 1, 1, 1, mode='quadratic'))

bl.append(speckle, propagation_parameters(1, 1, 1, 1, mode='fresnel'))