Low level parsing of Impact output files¶
Note that the Impact class does this automatically.
In [1]:
Copied!
from impact.parsers import fort_files, load_fort, load_many_fort, parse_impact_input
from impact.parsers import fort_files, load_fort, load_many_fort, parse_impact_input
In [2]:
Copied!
opath = "templates/lcls_injector/output/"
# Find fort.X output files in path
fortfiles = fort_files(opath)
fortfiles
opath = "templates/lcls_injector/output/"
# Find fort.X output files in path
fortfiles = fort_files(opath)
fortfiles
Out[2]:
['templates/lcls_injector/output/fort.102', 'templates/lcls_injector/output/fort.18', 'templates/lcls_injector/output/fort.24', 'templates/lcls_injector/output/fort.25', 'templates/lcls_injector/output/fort.26', 'templates/lcls_injector/output/fort.27', 'templates/lcls_injector/output/fort.28', 'templates/lcls_injector/output/fort.29', 'templates/lcls_injector/output/fort.30', 'templates/lcls_injector/output/fort.40', 'templates/lcls_injector/output/fort.50', 'templates/lcls_injector/output/fort.60', 'templates/lcls_injector/output/fort.70']
In [3]:
Copied!
# Load one file
load_fort(fortfiles[1]).keys()
# Load one file
load_fort(fortfiles[1]).keys()
Loaded fort 18 : Time and energy
Out[3]:
dict_keys(['t', 'mean_z', 'mean_gamma', 'mean_kinetic_energy_MeV', 'mean_beta', 'max_r', 'sigma_gamma'])
In [4]:
Copied!
# Load many
# Load many
In [5]:
Copied!
data = load_many_fort(opath, verbose=True)
data = load_many_fort(opath, verbose=True)
Loaded fort 18 : Time and energy Loaded fort 24 : RMS X information Loaded fort 25 : RMS Y information Loaded fort 26 : RMS Z information Loaded fort 27 : Max amplitude information Loaded fort 28 : Load balance and loss diagnostics Loaded fort 29 : Cube root of third moments of the beam distribution Loaded fort 30 : Fourth root of the fourth moments of the beam distribution
Plot¶
In [6]:
Copied!
from bokeh.io import output_notebook
from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource
from impact.parsers import UNITS
output_notebook()
from bokeh.io import output_notebook
from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource
from impact.parsers import UNITS
output_notebook()
In [7]:
Copied!
ds = ColumnDataSource(data)
ds = ColumnDataSource(data)
In [8]:
Copied!
def plot1(y_axis, x_axis="mean_z", source=ds):
yunit = UNITS[y_axis]
ylabel = y_axis + " (" + yunit + ")"
xunit = UNITS[x_axis]
xlabel = x_axis + " (" + xunit + ")"
p = figure(width=600, height=200, x_axis_label=xlabel, y_axis_label=ylabel)
p.line(x_axis, y_axis, source=source, color="red")
return p
show(plot1("norm_emit_x"))
def plot1(y_axis, x_axis="mean_z", source=ds):
yunit = UNITS[y_axis]
ylabel = y_axis + " (" + yunit + ")"
xunit = UNITS[x_axis]
xlabel = x_axis + " (" + xunit + ")"
p = figure(width=600, height=200, x_axis_label=xlabel, y_axis_label=ylabel)
p.line(x_axis, y_axis, source=source, color="red")
return p
show(plot1("norm_emit_x"))
In [9]:
Copied!
data.keys()
data.keys()
Out[9]:
dict_keys(['t', 'mean_z', 'mean_gamma', 'mean_kinetic_energy_MeV', 'mean_beta', 'max_r', 'sigma_gamma', 'mean_x', 'sigma_x', 'mean_gammabeta_x', 'sigma_gammabeta_x', '-cov_x__gammabeta_x', 'norm_emit_x', 'mean_y', 'sigma_y', 'mean_gammabeta_y', 'sigma_gammabeta_y', '-cov_y__gammabeta_y', 'norm_emit_y', 'sigma_z', 'mean_gammabeta_z', 'sigma_gammabeta_z', '-cov_z__gammabeta_z', 'norm_emit_z', 'max_amplitude_x', 'max_amplitude_gammabeta_x', 'max_amplitude_y', 'max_amplitude_gammabeta_y', 'max_amplitude_z', 'max_amplitude_gammabeta_z', 'loadbalance_min_n_particle', 'loadbalance_max_n_particle', 'n_particle', 'moment3_x', 'moment3_gammabeta_x', 'moment3_y', 'moment3_gammabeta_y', 'moment3_z', 'moment3_gammabeta_z', 'moment4_x', 'moment4_gammabeta_x', 'moment4_y', 'moment4_gammabeta_y', 'moment4_z', 'moment4_gammabeta_z'])
In [10]:
Copied!
infile = "templates/lcls_injector/ImpactT.in"
dat = parse_impact_input(infile)
header = dat["header"]
lattice = dat["lattice"]
infile = "templates/lcls_injector/ImpactT.in"
dat = parse_impact_input(infile)
header = dat["header"]
lattice = dat["lattice"]