示例#1
0
def mirror_acceptance_test(ekev, q, A):
    
    iwfr = construct_SA1_pulse(1024, 1024, 2, ekev, q)
    
    ix, iy, axis_x, axis_y = [get_obstructed_profile(deepcopy(iwfr), beamline_setup(mode = 'post',
                                                      ekev = ekev,
                                                      ang = ang)) for ang in tqdm(A)]
    ux, uy = get_unobstructed_profile(ekev, q)
    line_plot(ix, ux, axis_x)
示例#2
0
def test_coherent_pulse_divergence(E, Q, sdir):
    """
    Test that the FWHM of the source matches the analytical prediction
    
    :param E: list/array of energies [keV]
    :param q: list/array of beam-charges [nC]
    :param outdir: output directory [str]
    """

    sns.set()

    fig = plt.figure(figsize=[12, 8])
    ax = fig.add_subplot(111)
    ax.set_title("Source Divergence FWHM", fontsize=22)
    ax.set_ylabel(r"d$\theta$ [$\mu$rad]", fontsize=16)
    ax.set_xlabel("Radiation Energy [keV]", fontsize=16)
    ax.set_xlim([2.5, 17.5])

    nx, ny = 1024, 1024

    for q in Q:

        divergences = []

        for energy in E:
            wfr = construct_SA1_pulse(512, 512, 2, energy, q)
            divergences.append(wfr.get_divergence()[0])

        ax.scatter(E, np.array(divergences) * 1e6, marker='o')

        analytical_data = [
            analytical_pulse_divergence(q, energy) for energy in E
        ]
        ax.plot(E, np.array(analytical_data) * 1e6, '--')

    ax.legend(["{} nC".format(q) for q in Q])

    if sdir == None:
        pass
    else:
        fig.savefig(sdir + "coherent_source_test_divergence.eps")
示例#3
0
def get_unobstructed_profile(ekev, q):
    """
    Return one-dimensional profiles of the source in the entry-plane of the aperture
    
    :param ekev: radiation energy [keV]
    :param q: electron beam charge [nC]
    
    :returns ix: horizontal intensity profile
    :returns iy: vertical intensity profile
    :returns ax: spatial axis along x profilefrom tqdm import tqdm
    :returns ay: spatial axis along y profile
    """

    
    wfr = construct_SA1_pulse(1024, 1024, 2, ekev, q)
    bl = beamline_setup(mode = 'pre', ekev = ekev)

    bl.propagate(wfr)    
    ix, iy = get_profile_1d(wfr)

    return ix, iy, get_axis(wfr, axis = 'x'), get_axis(wfr, axis = 'y')
示例#4
0
    return get_longitudinal_coherence(ii, dx)


@timing
def new(ii, dx):
    return get_longitudinal_coherence(ii, dx)


def speed_test(ii, dx):

    for i in range(5):

        ans1 = old(ii, dx)
        ans2 = new(ii, dx)
        print(ans1 == ans2)
        print("")


if __name__ == '__main__':

    from scipy.signal import coherence
    from matplotlib import pyplot as plt

    nx, ny, nz = 500, 500, 5
    ii = construct_SA1_pulse(nx, ny, nz, 5.0, 0.1)
    ii = ii.as_complex_array()
    #ii = get_complex_radial_profile(ii)[0]
    speed_test(1, ii)

    #c = coherence(ii, ii[:,-1:])[1]
示例#5
0
# -*- coding: utf-8 -*-
import numpy as np
from felpy.model.beamlines.methods import get_beamline_object
from felpy.model.src.coherent import construct_SA1_pulse

if __name__ == '__main__':
    wfr = construct_SA1_pulse(1024, 1024, 5, 5.0, 0.25)
    spb = get_beamline_object(apertures=True, surface="on")
    spb.propagate_sequential(wfr)
示例#6
0
    #     ### test gaussian fit
    #     x = np.linspace(-100,100,100)
    #
    #     f = gaussian(x, sigma = 15, x0 = 10)*np.arange(100)
    #
    #     plt.plot(x,f)
    #     params, params_covariance = fit_gaussian(x, f)
    #     plt.scatter(x, gaussian(x, *params))
    # =============================================================================

    ### test gaussian fit w/ wavefront

    from felpy.model.src.coherent import construct_SA1_pulse

    # setup
    wfr = construct_SA1_pulse(512, 512, 2, 5.0, 0.25)

    x = wfr.x_axis
    y = wfr.y_axis

    ix = wfr.x_profile
    iy = wfr.y_profile

    imax = wfr.peak_intensity

    ### fit x
    initial_guess = [wfr.get_fwhm()[0], wfr.com[0], imax]
    p, co = fit_gaussian(x, ix, p0=initial_guess)

    fwhm_x = p[0] * sigma_to_fwhm
示例#7
0
        bl.append(
            Drift(0),
            propagation_parameters(self.mesh.dx / wfr.dx, 1,
                                   self.mesh.dy / wfr.dy, 1))
        bl.propagate(wfr)

        ii = wfr.get_intensity().sum(-1)
        ii = compress_and_average(ii, (self.mesh.nx, self.mesh.ny))

        return ii


if __name__ == '__main__':

    from felpy.model.src.coherent import construct_SA1_pulse

    wfr = construct_SA1_pulse(512, 512, 3, 10, 0.25)
    [wxMin, wxMax, wyMax, wyMin] = wfr.get_limits()
    wnx, wny = wfr.nx, wfr.ny
    wdx, wdy = wfr.dx, wfr.dy

    detector_mesh = Mesh(nx=400, ny=270, dx=5e-06, dy=12e-06)

    d = Detector(mesh=detector_mesh)
    i = d.detect(wfr)

    print("Desired Properties/Actual Values")
    print("nx: {}/{}".format(detector_mesh.nx, wfr.params.Mesh.nx))
    print("ny: {}/{}".format(detector_mesh.ny, wfr.ny))
    print("dx: {}/{}".format(detector_mesh.dx, wfr.dx))
    print("dy: {}/{}".format(detector_mesh.dy, wfr.dy))
示例#8
0
    s = np.diag(np.fliplr(s))
    freq = np.linspace(-s.shape[0] // 2 * spatial_sampling,
                       s.shape[0] // 2 * spatial_sampling, s.shape[0])

    return freq[s.shape[0] // 2:], s[s.shape[0] // 2:]


if __name__ == '__main__':

    from matplotlib import pyplot as plt
    from felpy.model.src.coherent import construct_SA1_pulse

    from felpy.utils.vis_utils import Grids
    from matplotlib.ticker import FormatStrFormatter

    wfr = construct_SA1_pulse(512, 512, 2, 5, 1)

    ef = wfr.as_complex_array().sum(-1)
    ef *= np.random.rand(512, 512)

    freq, s = power_spectral_density(ef,
                                     spatial_sampling=wfr.dx,
                                     pulse_duration=wfr.pulse_duration)

    grid = Grids()
    grid.create_grid(1, 1)
    ax = grid.axes
    ax.semilogy(freq, s)

    ax.xaxis.set_major_formatter(FormatStrFormatter('%.e'))