Пример #1
0
def main():
    conf = toml.load(sys.argv[1])

    common.setup_plot()
    with PdfPages(conf['Output']) as output:
        for page_conf in conf['Pages']:
            dump(output, conf, page_conf)
def main():
    common.setup_plot()

    output = PdfPages('quadrupole-trajectory-diagram.pdf')
    plot_quadrupole(output)
    output.close()

    output = PdfPages('sextupole-trajectory-diagram.pdf')
    plot_sextupole(output)
    output.close()
Пример #3
0
def main():
    common.setup_plot()
    plot.rc('figure.subplot', right=0.96, top=0.97, bottom=0.15, left=0.13)

    output = PdfPages('comparison.pdf')
    for thickness in common.thickness_vals:
        for energy in common.energy_vals:
            for particle in ['e-']:
                desc = '{:.3f}mm_{:.3f}MeV'.format(round(thickness / mm, 3),
                                                   round(energy / MeV, 3))
                filename = 'out/' + desc + '.h5'
                plot_run(output, filename, thickness, energy, particle)
    output.close()
Пример #4
0
def main():
    args = get_args()
    conf = args.conf
    fin = h5py.File(conf['Files']['Input'], 'r')
    run_index = tuple(conf['Files']['RunIndex'])
    edep = fin['edep'][run_index] * eV
    xbin = fin['xbin'][:] * mm
    ybin = fin['ybin'][:] * mm
    zbin = fin['zbin'][:] * mm

    common.setup_plot()

    out_fname = conf['Files']['Output']
    os.makedirs(os.path.dirname(out_fname), exist_ok=True)
    output = PdfPages(out_fname)
    plot_deposition_2d(output, conf, edep, xbin, ybin, zbin)
    output.close()
    return 0
Пример #5
0
def main():
    common.setup_plot()

    with PdfPages('collimation-output.pdf') as output:
        dump(
            output, 'results/W-5-p45-10.h5', 'results/uncollimated.h5',
            'Tungsten collimator\n' +
            r'$a = 5\,{\rm mm}, r = 0.45\,a, d = 10\,{\rm mm}$')
        dump(
            output, 'results/W-4-p43-12.h5', 'results/uncollimated.h5',
            'Tungsten collimator\n' +
            r'$a = 4\,{\rm mm}, r = 0.43\,a, d = 12\,{\rm mm}$')
        dump(
            output, 'results/W-5-p42-15.h5', 'results/uncollimated.h5',
            'Tungsten collimator\n' +
            r'$a = 5\,{\rm mm}, r = 0.42\,a, d = 15\,{\rm mm}$')
        dump(
            output, 'results/Al-5-p45-10.h5', 'results/uncollimated.h5',
            'Aluminum collimator\n' +
            r'$a = 5\,{\rm mm}, r = 0.45\,a, d = 10\,{\rm mm}$')
Пример #6
0
def main():
    fin = h5py.File('d2W.h5', 'r')
    common.setup_plot()
    os.makedirs('figs', exist_ok=True)

    # PWFA
    if True:
        pwfa_drive_datasets = [
            'E300 PWFA/Unmatched Trailing (s=0.17)/drive',
            'E300 PWFA/Unmatched Trailing (s=0.14)/drive',
            'E300 PWFA/Matched Trailing (s=0.06)/drive',
            'E300 PWFA/Unmatched Trailing (s=0.01)/drive']
        pwfa_trailing_datasets = [
            'E300 PWFA/Unmatched Trailing (s=0.17)/trailing',
            'E300 PWFA/Unmatched Trailing (s=0.14)/trailing',
            'E300 PWFA/Matched Trailing (s=0.06)/trailing',
            'E300 PWFA/Unmatched Trailing (s=0.01)/trailing']
        output = PdfPages('figs/pwfa.pdf')

        plot_spectral_photon_density(
            output, fin, pwfa_trailing_datasets[1:2],
            (MeV, 'MeV'),
            (1/MeV, '1/MeV'),
            (-0.1, 2.0), (1e7, 1e13))

        plot_d2W(
            output, fin, pwfa_trailing_datasets[1],
            )

        for x in pwfa_trailing_datasets:
            plot_double_differential(
                output, fin, x, 8,
                (MeV, 'MeV'), (mrad, 'mrad'),
                (uJ/(mrad*MeV), r'uJ/(mrad$^\cdot$MeV)'),
                (0.01, 1.0), (-2.0, 2.0))
        output.close()
Пример #7
0
def main():
    args = get_args()
    conf = args.conf
    fin = h5py.File(conf['Files']['Input'], 'r')
    run_index = tuple(conf['Files']['RunIndex'])
    num_events = fin['num_events'][run_index]
    gin = fin[conf['Files']['Group']]
    edep = gin['edep'][run_index] * MeV
    xbin = gin['xbin'][:] * mm
    ybin = gin['ybin'][:] * mm
    zbin = gin['zbin'][:] * mm

    common.setup_plot()

    filename = conf['Files']['Output']
    path = os.path.dirname(filename)
    if path != '':
        os.makedirs(path, exist_ok=True)


#    output = PdfPages(filename)
    plot_deposition_2d(filename, conf, edep, num_events, xbin, ybin, zbin)
    #    output.close()
    return 0
Пример #8
0
def main():
    common.setup_plot()

    energy = []
    position = []
    theta0 = 28.0 * deg

    M = compton.build_transformation(
        [['TranslateX', 'RotateY', 'TranslateZ'], [-40.1, -28.0, -30.0]], mm,
        deg)

    with h5py.File('trajectories/trajectories.h5', 'r') as fin:
        for gin in fin.values():
            E0 = get_energy(gin)
            x0 = gin['x'][0] * meter
            x1 = gin['x'][-1] * meter
            if x0[1] != 0.0:
                continue
            x1 = compton.transform(M, x1)
            energy.append(E0)
            position.append(x1[2])
    energy = np.array(energy)
    position = np.array(position)
    args = np.argsort(energy)
    energy = energy[args]
    position = position[args]

    mod = lmfit.Model(fit_func)
    params = mod.make_params(c0=0.0, c1=0.0, c2=0.0)

    result = mod.fit(data=energy / MeV, x=position, params=params)
    print(result.fit_report())

    v = result.params.valuesdict()
    print(v['c0'])
    print(v['c1'])
    print(v['c2'])

    x_fit = np.linspace(position[0], position[-1], 200)

    fig = plot.figure(figsize=(244.0 / 72, 120.0 / 72))
    ax = fig.add_subplot(1, 1, 1)

    ax.semilogy(x_fit / mm, result.eval(x=x_fit), linewidth=0.6)

    ax.semilogy(position / mm,
                energy / MeV,
                marker='.',
                ls='',
                markersize=0.001,
                color='k')

    ax.text(0.05,
            0.8,
            r'$E(z_s)/{\rm MeV} = \exp (c_0 + c_1 z_s + c_2 z_s^2)$',
            fontsize=7.0,
            transform=ax.transAxes)

    text = r'$c_0 = {:.3}$'.format(v['c0']) + '\n'
    text += r'$c_1 = {:.3}'.format(num2tex(v['c1'] * mm))
    text += r'\;{\rm mm}^{-1}$' + '\n'
    text += r'$c_2 = {:.3}'.format(num2tex(v['c2'] * mm**2))
    text += r'\;{\rm mm}^{-2}$' + '\n'
    print(text)
    ax.text(0.5, 0.2, text, transform=ax.transAxes)

    ax.set_xlabel(r'$z_s$ (mm)', labelpad=-1.0)
    ax.set_ylabel(r"Energy (MeV)", labelpad=2.0)
    # ax.set_xlim(0, 250)
    ax.set_ylim(0.1, 20)
    ax.xaxis.set_minor_locator(matplotlib.ticker.AutoMinorLocator())

    filename = 'out/energy-scale.pdf'
    os.makedirs(os.path.dirname(filename), exist_ok=True)
    plot.savefig(filename, transparent=True)
Пример #9
0
def plot_homing_map(filename, homing_map, hull):
    os.makedirs(os.path.dirname(filename), exist_ok=True)
    output = PdfPages(filename)
    common.setup_plot()
    plot.rc('figure.subplot', right=0.99, top=0.99, bottom=0.09, left=0.10)

    mesh_dx = 0.5 * mm

    Y, Z = np.meshgrid(
        np.arange(hull.min_bound[0] - mesh_dx, hull.max_bound[0] + mesh_dx,
                  mesh_dx),
        np.arange(hull.min_bound[1] - mesh_dx, hull.max_bound[1] + mesh_dx,
                  mesh_dx))
    smoothed_xi = homing_map(Y, Z)[:, :, 0]
    smoothed_phi = homing_map(Y, Z)[:, :, 1]

    fig = plot.figure(figsize=(244 / 72, 100 / 72))
    ax = fig.add_subplot(1, 1, 1, aspect=1.0)
    ax.contour(Z / mm,
               Y / mm,
               smoothed_xi,
               levels=np.linspace(-1.0, 1.0, 20),
               linewidths=0.3,
               colors='#0083b8',
               linestyles='solid',
               zorder=0)
    ax.fill(hull.points[hull.vertices, 1] / mm,
            hull.points[hull.vertices, 0] / mm,
            fill=False,
            linewidth=0.5,
            edgecolor='k',
            zorder=10)
    scale_limits(ax.xaxis, 1.1)
    scale_limits(ax.yaxis, 1.1)
    plot.title(r'$\xi(z, y)$')
    plot.xlabel(r'$z_{\rm scint}$ (mm)', labelpad=0.0)
    plot.ylabel(r'$y_{\rm scint}$ (mm)', labelpad=0.0)
    ax.xaxis.set_minor_locator(matplotlib.ticker.AutoMinorLocator())
    ax.yaxis.set_minor_locator(matplotlib.ticker.AutoMinorLocator())
    output.savefig(fig, transparent=True)

    fig = plot.figure(figsize=(244 / 72, 100 / 72))
    ax = fig.add_subplot(1, 1, 1, aspect=1.0)
    ax.contour(Z / mm,
               Y / mm,
               smoothed_phi,
               levels=20,
               linewidths=0.3,
               colors='#0083b8',
               linestyles='solid',
               zorder=0)
    ax.fill(hull.points[hull.vertices, 1] / mm,
            hull.points[hull.vertices, 0] / mm,
            fill=False,
            linewidth=0.5,
            edgecolor='k',
            zorder=10)
    scale_limits(ax.xaxis, 1.1)
    scale_limits(ax.yaxis, 1.1)
    plot.title(r'$\phi(z, y)$')
    plot.xlabel(r'$z_{\rm scint}$ (mm)', labelpad=0.0)
    plot.ylabel(r'$y_{\rm scint}$ (mm)', labelpad=0.0)
    ax.xaxis.set_minor_locator(matplotlib.ticker.AutoMinorLocator())
    ax.yaxis.set_minor_locator(matplotlib.ticker.AutoMinorLocator())
    output.savefig(fig, transparent=True)
    output.close()
Пример #10
0
def main():
    fin = h5py.File('d2W.h5', 'r')
    common.setup_plot()
    os.makedirs('figs', exist_ok=True)

    # PWFA
    if True:
        pwfa_drive_datasets = [
            'E300 PWFA/Unmatched Trailing (s=0.17)/drive',
            'E300 PWFA/Unmatched Trailing (s=0.14)/drive',
            'E300 PWFA/Matched Trailing (s=0.06)/drive',
            'E300 PWFA/Unmatched Trailing (s=0.01)/drive'
        ]
        pwfa_trailing_datasets = [
            'E300 PWFA/Unmatched Trailing (s=0.17)/trailing',
            'E300 PWFA/Unmatched Trailing (s=0.14)/trailing',
            'E300 PWFA/Matched Trailing (s=0.06)/trailing',
            'E300 PWFA/Unmatched Trailing (s=0.01)/trailing'
        ]
        output = PdfPages('figs/pwfa.pdf')
        plot_spectral_energy_density(output, fin, pwfa_drive_datasets,
                                     (MeV, 'MeV'), (mJ / MeV, 'mJ/MeV'),
                                     (-0.1, 2.0), (-0.05, 2.6))
        plot_spectral_energy_density(output, fin, pwfa_trailing_datasets,
                                     (MeV, 'MeV'), (mJ / MeV, 'mJ/MeV'),
                                     (-0.1, 2.0), (-0.05, 2.6))
        plot_spectral_photon_density(output, fin, pwfa_drive_datasets,
                                     (MeV, 'MeV'), (1 / MeV, '1/MeV'),
                                     (-0.1, 2.0), (1e7, 1e13))
        plot_spectral_photon_density(output, fin, pwfa_trailing_datasets,
                                     (MeV, 'MeV'), (1 / MeV, '1/MeV'),
                                     (-0.1, 2.0), (1e7, 1e13))
        for x in pwfa_drive_datasets:
            plot_spot(output, fin, x, 6, (mJ / mrad**2, r'mJ/mrad$^2$'),
                      (-2.0, 2.0), (-1.5, 1.5))
        for x in pwfa_trailing_datasets:
            plot_spot(output, fin, x, 6, (mJ / mrad**2, r'mJ/mrad$^2$'),
                      (-2.0, 2.0), (-1.5, 1.5))
        for x in pwfa_drive_datasets:
            plot_double_differential(
                output, fin, x, 8, (MeV, 'MeV'), (mrad, 'mrad'),
                (uJ / (mrad * MeV), r'uJ/(mrad$^\cdot$MeV)'), (0.01, 1.0),
                (-2.0, 2.0))
        for x in pwfa_trailing_datasets:
            plot_double_differential(
                output, fin, x, 8, (MeV, 'MeV'), (mrad, 'mrad'),
                (uJ / (mrad * MeV), r'uJ/(mrad$^\cdot$MeV)'), (0.01, 1.0),
                (-2.0, 2.0))
        output.close()

    # Filamentation
    if True:
        output = PdfPages('figs/filamentation.pdf')
        plot_spectral_energy_density(output,
                                     fin, ['Filamentation/solid'],
                                     (MeV, 'MeV'), (uJ / MeV, 'uJ/MeV'),
                                     (-4, 60.0), (-5, 100),
                                     display_legend=False)
        plot_spectral_photon_density(output,
                                     fin, ['Filamentation/solid'],
                                     (MeV, 'MeV'), (1 / MeV, '1/MeV'),
                                     (-2, 60.0), (1e6, 1e10),
                                     display_legend=False)
        plot_spot(output, fin, 'Filamentation/solid', 5,
                  (mJ / mrad**2, r'mJ/mrad$^2$'), (-0.2, 0.2), (-0.2, 0.2), '')
        plot_double_differential(output, fin, 'Filamentation/solid', 8,
                                 (MeV, 'MeV'), (mrad, 'mrad'),
                                 (uJ / (mrad * MeV), r'uJ/(mrad$\cdot$MeV)'),
                                 (1, 30), (-0.2, 0.2), '')
        output.close()

    # SFQED
    if True:
        output = PdfPages('figs/sfqed.pdf')
        sfqed_datasets = [
            'SFQED/MPIK/LCFA_w3.0_xi5.7', 'SFQED/MPIK/LCFA_w2.4_xi7.2',
            'SFQED/MPIK/LCS+LCFA_w3.0_xi5.7', 'SFQED/MPIK/LCS+LCFA_w2.4_xi7.2'
        ]
        sfqed_labels = [
            r'LCFA ($a_0=5.7, w_0=3.0\;\mu{\rm m}$)',
            r'LCFA ($a_0=7.2, w_0=2.4\;\mu{\rm m}$)',
            r'QED ($a_0=5.7, w_0=3.0\;\mu{\rm m}$)',
            r'QED ($a_0=7.2, w_0=2.4\;\mu{\rm m}$)'
        ]
        plot_spectral_energy_density(output,
                                     fin,
                                     sfqed_datasets, (GeV, 'GeV'),
                                     (mJ / GeV, 'mJ/GeV'), (-0.1, 10.0),
                                     (-0.1, 4),
                                     labels=sfqed_labels)
        plot_spectral_energy_density(output,
                                     fin,
                                     sfqed_datasets, (MeV, 'MeV'),
                                     (uJ / MeV, 'uJ/MeV'), (-1, 60.0),
                                     (-0.1, 3),
                                     labels=sfqed_labels)
        plot_spectral_photon_density(output,
                                     fin,
                                     sfqed_datasets, (GeV, 'GeV'),
                                     (1 / GeV, '1/GeV'), (-0.1, 10.0),
                                     (1e1, 1e9),
                                     labels=sfqed_labels)
        plot_spectral_photon_density(output,
                                     fin,
                                     sfqed_datasets, (MeV, 'MeV'),
                                     (1 / MeV, '1/MeV'), (-1, 60.0),
                                     (2e4, 4e7),
                                     labels=sfqed_labels)
        for x, y in zip(sfqed_datasets, sfqed_labels):
            plot_double_differential(output,
                                     fin,
                                     x,
                                     8, (MeV, 'MeV'), (mrad, 'mrad'),
                                     (uJ /
                                      (mrad * MeV), r'uJ/(mrad$\cdot$MeV)'),
                                     (1, 30), (-0.5, 0.5),
                                     label=y)
        for x, y in zip(sfqed_datasets, sfqed_labels):
            plot_spot(output,
                      fin,
                      x,
                      6, (mJ / mrad**2, r'mJ/mrad$^2$'), (-0.3, 0.3),
                      (-0.1, 0.1),
                      label=y)
        output.close()
Пример #11
0
def main():
    args = get_args()
    conf = args.conf

    # create safe interpreter for evaluation of configuration expressions
    aeval = asteval.Interpreter(use_numpy=True)
    for q in common.units.__all__:
        aeval.symtable[q] = common.units.__dict__[q]

    pconf = conf['Projection']
    M = compton.build_transformation(pconf['Transformation'], mm, deg)
    prefilter = np.array(pconf['Prefilter']) * mm
    postfilter = np.array(pconf['Postfilter']) * mm

    energy = []
    position = []

    x = []
    E0 = []
    with h5py.File(conf['Files']['Input'], 'r') as fin:
        for gin in fin.values():
            x.append((gin['x'][0] * meter,
                      compton.transform(M, gin['x'][-1] * meter)))
            E0.append(get_energy(gin))
    x = np.array(x)
    E0 = np.array(E0)
    prefilter_mask = compton.in_volume(prefilter, x[:, 0, :])
    x_pre = x[prefilter_mask, :, :]
    E0_pre = E0[prefilter_mask]
    postfilter_mask = compton.in_volume(postfilter, x_pre[:, 1, :])
    x_post = x_pre[postfilter_mask, :, :]
    E0_post = E0_pre[postfilter_mask]

    energy = E0_post.copy()
    position = x_post[:, 1, 2].copy()
    args = np.argsort(energy)
    energy = energy[args]
    position = position[args]

    mod = lmfit.Model(fit_func)
    params = mod.make_params(c0=0.0, c1=0.0, c2=0.0, c3=0.0)

    result = mod.fit(data=np.log(energy / MeV), x=position, params=params)

    v = result.params.valuesdict()
    x_fit = np.linspace(position[0], position[-1], 200)

    common.setup_plot()

    fig = plot.figure(figsize=np.array(conf['Plot']['FigSize']) / 72)
    ax = fig.add_subplot(1, 1, 1)

    axes = [get_axis(aeval, *conf['Plot'][x]) for x in ['XAxis', 'YAxis']]

    ax.semilogy(x_fit / axes[0].unit,
                np.exp(result.eval(x=x_fit)),
                linewidth=0.6)

    ax.semilogy(position / axes[0].unit,
                energy / axes[1].unit,
                marker='.',
                ls='',
                markersize=2.0,
                markeredgewidth=0,
                color='k')

    aeval.symtable['fitval'] = v
    aeval.symtable['num2tex'] = num2tex
    plot_annotation(ax, aeval, conf['Plot'])

    ax.set_xlabel(axes[0].label, labelpad=-1.0)
    ax.set_ylabel(axes[1].label, labelpad=2.0)

    ax.set_xlim(*axes[0].xlim)
    ax.set_ylim(*axes[1].xlim)
    ax.xaxis.set_minor_locator(matplotlib.ticker.AutoMinorLocator())

    filename = conf['Files']['PlotOutput']
    path = os.path.dirname(filename)
    if path != '':
        os.makedirs(path, exist_ok=True)
    plot.savefig(filename, transparent=True)

    if 'CalcOutput' in conf['Files']:
        filename = conf['Files']['CalcOutput']
        path = os.path.dirname(filename)
        if path != '':
            os.makedirs(path, exist_ok=True)
        calc_output = {
            'EnergyScaleCoefficients': {
                'c0': float(v['c0']),
                'c1': float(v['c1'] * mm),
                'c2': float(v['c2'] * mm**2),
                'c3': float(v['c3'] * mm**3)
            }
        }
        with open(filename, 'w') as fout:
            toml.dump(calc_output, fout)