opal.visualization package
Subpackages
Notebooks
- Load Dataset
- Projection Plot
- Slice Plot
- Line Plot
- Particle Plot
- Overlay Particles onto Fields
- H5Plotter_RingMultiBunch
- ProbePlotter
- ProbePlotter_PeakFile
- OptimizerPlotter
- SamplerPlotter
- StatPlotter_FODO
- StatPlotter_Gantry
- StatPlotter_RingCyclotron
- Load the RingCyclotron.stat file
- Set the plotting style
- Do some plotting …
- Load the RingCyclotron.h5 file
- Do some plotting …
- Do some statistics on data
- Load the RingCyclotron.mem file
- Do some plotting …
- Load the RingCyclotron.lbal file
- Do some plotting …
- Load the RingCyclotron-trackOrbit file
- Do some plotting …
- Load timing.dat file
- Do some plotting …
opal.visualization.AmrPlotter module
- class opal.visualization.AmrPlotter.AmrPlotter[source]
Bases:
BasePlotter
- line_plot(axis, field, **kwargs)[source]
Plot a line plot of 3D data along an axis
- Parameters:
axis (str) – Take a line cut along this axis (‘x’, ‘y’, ‘z’)
field (str) – Quantity of y-axis
unit (str, optional) – Unit of y-axis
center ((float, float)) – Center of plot through which line should go
- particle_phase_space_plot(axis, **kwargs)[source]
Plot particle phase spaces etc of 3D data
10. March 2018 http://yt-project.org/doc/reference/api/yt.visualization.particle_plots.html#yt.visualization.particle_plots.ParticlePlot
- Parameters:
axis (str) – ‘x’, ‘y’ or ‘z’
coordinate_unit (str, optional) –
momentum_unit (str, optional) –
color (str, optional) –
deposition (str, optional) –
fontsize (int, optional) –
- particle_plot(x_field, y_field, z_field=None, **kwargs)[source]
Plot particle phase spaces etc of 3D data
10. March 2018 http://yt-project.org/doc/reference/api/yt.visualization.particle_plots.html#yt.visualization.particle_plots.ParticlePlot
- Parameters:
x_field (str) – Particle field plotted on x-axis
y_field (str) – Particle field plotted on y-axis
z_field (str, optional) – Field to be displayed on the colorbar
x_unit (str, optional) –
y_unit (str, optional) –
z_unit (str, optional) –
z_log (bool, optional) –
color (str, optional) –
fontsize (int, optional) –
deposition (str, optional) –
- projection_plot(axis, field, **kwargs)[source]
Plot a projection of 3D data
- Parameters:
axis (str) – Is the direction ‘x’, ‘y’ or ‘z’
field (str) – Quantity to plot
unit (str, optional) – The data should be converted to (otherwise it takes the default given by the data)
zoom (float, optional) – Is the zoom factor (default: 1, i.e. no zoom)
color (str, optional) – Is the color for the time stamp and scale annotation
origin (str, optional) – Location of the origin of the plot coordinate system
method (str, optional) –
- Method of projection (‘mip’, ‘sum’, ‘integrate’)
’mip’: maximum of field in the line of sight
’sum’: summation of the field along the given axis
’integrate’: integrate the requested field along the line of sight
overlay_particles (bool, optional) –
time (bool, optional) –
gridcmap (str, optional) –
grids (bool, optional) –
scale (bool, optional) –
Notes
https://yt-project.org/doc/visualizing/plots.html#slice-plots
- slice_plot(normal, field, **kwargs)[source]
Plot a slice through 3D data
- Parameters:
normal (str) – Is the direction ‘x’, ‘y’ or ‘z’ (normal)
field (str) – Quantity to plot
unit (str, optional) – The data should be converted to (otherwise it takes the default given by the data)
zoom (float, optional) – Is the zoom factor (default: 1, i.e. no zoom)
color (str, optional) – Is the color for the time stamp and scale annotation
origin (str, optional) – Location of the origin of the plot coordinate system
overlay_particles (bool, optional) –
time (bool, optional) –
gridcmap (str, optional) –
grids (bool, optional) –
scale (bool, optional) –
Notes
https://yt-project.org/doc/visualizing/plots.html#slice-plots
opal.visualization.BasePlotter module
opal.visualization.FieldPlotter module
- class opal.visualization.FieldPlotter.FieldPlotter[source]
Bases:
BasePlotter
- plot_line(field, normal, step=0, **kwargs)[source]
Do a line plot through the center. The line can only be drawn orthogonal to one of the directions x, y, or z.
- Parameters:
field (str) – name of scalar field or vector field component
normal (str) – normal direction. Either ‘x’, ‘y’, or ‘z’
step (int, optional) – time step
kwargs (dict, optional) – keywords of matplotlib.pyplot.plot
- Returns:
Plot handle
- Return type:
matplotlib.pyplot
- plot_projection(field, normal, step=0, method='integrated', **kwargs)[source]
Do a projection plot.
- Parameters:
field (str) – name of scalar field or vector field component
normal (str) – normal direction. Either ‘x’, ‘y’, or ‘z’
step (int, optional) – time step
method (str, optional) – projection method: ‘integrated’, ‘sum’ or ‘max’
kwargs (dict, optional) – keywords of matplotlib.pyplot.pcolormesh
- Returns:
Plot handle
- Return type:
matplotlib.pyplot
- plot_slice(field, normal, pos=0.0, index=0, step=0, **kwargs)[source]
Do a slice plot.
- Parameters:
field (str) – name of scalar field or vector field component
normal (str) – normal direction. Either ‘x’, ‘y’, or ‘z’
pos (float, optional) – coordinate position of slice
step (int, optional) – time step
index (int, optional) – if index > 0, pos is ignored.
kwargs (dict, optional) – keywords of matplotlib.pyplot.pcolormesh
- Returns:
Plot handle
- Return type:
matplotlib.pyplot
opal.visualization.GridPlotter module
- class opal.visualization.GridPlotter.GridPlotter[source]
Bases:
BasePlotter
opal.visualization.H5Plotter module
- class opal.visualization.H5Plotter.H5Plotter[source]
Bases:
ProbePlotter
- plot_classification(xvar, yvar, value, **kwargs)[source]
Classification Plot
Scatter plot where the points are colored according the value of the probability density function pdf(x, y) computed through kernel density estimation.
- Parameters:
xvar (str) – x-axis variable to consider
yvar (str) – y-axis variable to consider
value (float) – Boundary value of classification
step (int, optional) – Step of dataset
- Returns:
Plot handle
- Return type:
matplotlib.pyplot
- plot_density(xvar, yvar, **kwargs)[source]
Do a density plot.
- Parameters:
xvar (str) – x-axis variable to consider
yvar (str) – y-axis variable to consider
step (int, optional) – Step of dataset
bins (array_like or int, optional) – Number of bins
cmap ((matplotlib.pyplot.Colormap, str), optional) – Color map
References
(22. March 2018) https://stackoverflow.com/questions/20105364/how-can-i-make-a-scatter-plot-colored-by-density-in-matplotlib
- Returns:
Plot handle
- Return type:
matplotlib.pyplot
- plot_density_scipy(xvar, yvar, **kwargs)[source]
Do a density plot
- Parameters:
xvar (str) – x-axis variable to consider
yvar (str) – y-axis variable to consider
step (int, optional) – Step of dataset
nxbin (int, optional) – Number of bins for x-axis
nybin (int, optional) – Number of bins for y-axis
cmap (str, optional) – Colormap
doShading (bool, optional) – If true, it uses ‘gouraud’ shading, else ‘flat’ shading
xlim (tuple, optional) – If not specified use data to compute limits
ylim (tuple, optional) – If not specified use data to compute limits
clabel (str, optional) – Label of colorbar
Notes
https://matplotlib.org/examples/pylab_examples/pcolor_demo.html
- Returns:
Plot handle
- Return type:
matplotlib.pyplot
- plot_histogram(var, **kwargs)[source]
Plot a 1D histogram.
- Parameters:
var (str) – Variable to consider
step (int, optional) – Step of dataset
bins (int or str, optional) – Binning type or number of bins (see https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.histogram.html)
density (bool, optional) –
- Normalize such that integral over
range is 1.
- Returns:
Plot handle
- Return type:
matplotlib.pyplot
- plot_joint(xvar, yvar, join, **kwargs)[source]
Do a joint plot (marginals + contour / scatter)
- Parameters:
xvar (str) – x-axis variable to consider
yvar (str) – y-axis variable to consider
join (str) – ‘all’, ‘contour’ or ‘scatter’
step (int, optional) – Step of dataset
See also
visualization.statistics.impl_plots.plot_joint
- Returns:
Plot handle
- Return type:
matplotlib.pyplot
- plot_phase_space(xvar, yvar, **kwargs)[source]
Plot a 2D phase space plot.
- Parameters:
xvar (str) – Variable for x-axis
yvar (str) – Variable for y-axis
step (int, optional) – Step of dataset
bins (list or integer, optional) – Color energy bins
xscale (str, optional) – ‘linear’, ‘log’
yscale (str, optional) – ‘linear’, ‘log’
xsci (bool, optional) – x-ticks in scientific notation
ysci (bool, optional) – y-ticks in scientific notation
markersize (int) – Size of markers in scatter plot
- Returns:
Plot handle
- Return type:
matplotlib.pyplot
opal.visualization.MemoryPlotter module
- class opal.visualization.MemoryPlotter.MemoryPlotter[source]
Bases:
BasePlotter
opal.visualization.OptimizerPlotter module
- class opal.visualization.OptimizerPlotter.OptimizerPlotter[source]
Bases:
BasePlotter
- __find(lst, key, value)
- __natural_sort(l)
- __sort_list(names, dimension, key)
- plot_dvar_evolution(opt=0, dvars=[], op=<built-in function min>, **kwargs)[source]
Plot the evolution of the design variable values dependent on the improvement of the objectives with generation.
The operator ‘op’ is executed on two objective value sums of two individuals.
- Parameters:
opt (int, optional) – Optimizer number (default: 0)
dvars (list of str, optional) – List of design variables, if not specified all are plotted
op (callable, optional) – Operator, e.g. max, min, etc
xscale (str, optional) – ‘linear’, ‘log’
yscale (str, optional) – ‘linear’, ‘log’
grid (bool, optional) –
- plot_individual_bounds(n, opt=0, **kwargs)[source]
Plot all design variables and their bounds.
This will show if a design variable is close to one of its bounds.
- Parameters:
n (int) – Take the first n-th best individuals
opt (int, optional) – Optimizer number (default: 0)
- Returns:
Plot handle
- Return type:
matplotlib.pyplot
- plot_objective_evolution(opt=0, objs=[], op=<built-in function min>, **kwargs)[source]
Plot the improvement of the objectives with generation.
The operator ‘op’ is executed between individuals per population
- Parameters:
opt (int, optional) – Optimizer number (default: 0)
objs (list of str, optional) – List of objectives, if not specified all are plotted
op (callable, optional) – Operator, e.g. max, min, etc
xscale (str, optional) – ‘linear’, ‘log’
yscale (str, optional) – ‘linear’, ‘log’
grid (bool, optional) –
total (bool, optional) – Show sum of objectives
label_rep (dict, optional) – Replace labels by
as_bar (bool, optional) –
colorlist (list of str, optional) –
- plot_objectives(opt=0, **kwargs)[source]
Plotting function for multiobjective optimizer output.
Show the trend of the sum of the objectives with the generation.
- Parameters:
opt (int, optional) – Optimizer number (default: 0)
xscale (str, optional) – ‘linear’ or ‘log’, default: linear
yscale (str, optional) – ‘linear’ or ‘log’, default: linear
grid (bool, optional) – Show grid, default: False
avg (bool, optional) – Take averaged sum over all objectives default: true
- Returns:
Plot handle
- Return type:
matplotlib.pyplot
- plot_parallel_coordinates(gen, opt=0, **kwargs)[source]
Plotting function for multiobjective optimizer output.
- Parameters:
gen (int) – Generation to plot
opt (int, optional) – Optimizer number (default: 0)
Notes
(30. April 2018) https://plot.ly/python/static-image-export/ https://plot.ly/python/parallel-coordinates-plot/ https://stackoverflow.com/questions/40243446/how-to-save-plotly-offline-graph-in-format-png
opal.visualization.PeakPlotter module
- class opal.visualization.PeakPlotter.PeakPlotter[source]
Bases:
BasePlotter
- plot_peak_difference(dset, **kwargs)[source]
Plot the peak difference of a probe output.
- Parameters:
dset (PeakDataset) – A dataset
grid (bool, optional) – Draw grid
raxis (bool, optional) – Do radius vs radius plot instead
begin (int, optional) – First peak
end (int, optional) – Last peak
- Returns:
Plot handle
- Return type:
matplotlib.pyplot
opal.visualization.ProbePlotter module
- class opal.visualization.ProbePlotter.ProbePlotter[source]
Bases:
BasePlotter
- plot_probe_histogram(**kwargs)[source]
Plot a histogram of the probe histogram bin count vs. radius.
- Parameters:
grid (bool, optional) – Draw grid
scale (bool, optional) – Scales to 1.0 (default: False)
bunch (int, optional) – Bunch number (default: 0)
begin (int, optional) – Start step (default: 0)
end (int, optional) – End step (default: ds.size)
**kwargs – In case of H5: additional arguments passed to matplotlib.pyplot.hist
- Returns:
Plot handle
- Return type:
matplotlib.pyplot
opal.visualization.ProfilingPlotter module
- class opal.visualization.ProfilingPlotter.ProfilingPlotter[source]
Bases:
BasePlotter
- plot_lbal_boxplot(**kwargs)[source]
Particle load balancing.
Does a (simulation) time series boxplot of the particle load balancing.
- plot_lbal_histogram(**kwargs)[source]
Particle load balancing.
Plots the time series (i.e. simulation time) histogram with the number of cores having the same amount of particles. The user can specify ranges givin the upper and lower boundary, i.e. ‘bupper’ and, respectively, ‘blower’. Those boundaries are given in percent.
opal.visualization.SamplerPlotter module
- class opal.visualization.SamplerPlotter.SamplerPlotter[source]
Bases:
BasePlotter
- _autolabel(ax, rects, xpos='center')[source]
Attach a text label above each bar in rects, displaying its height.
Copied from matplotlib.org. It’s slightly modified.
xpos indicates which side to place the text w.r.t. the center of the bar. It can be one of the following {‘center’, ‘right’, ‘left’}.
- plot_auto_correlation(ind, **kwargs)[source]
Compare a sample set with itself.
- Parameters:
ind (list) – Indices of the sample set.
nsamples (bool, optional) – Show a horizontal line indicating the total number of samples
percent (bool, optional) – Indicate the agreement in percent above each bar
- Returns:
Plot handle
- Return type:
matplotlib.pyplot
- plot_sample_input_statistics(**kwargs)[source]
Bar plot showing the number of samples per design variable. This makes only sense for sampling with only a few states.
- Returns:
Plot handle
- Return type:
matplotlib.pyplot
- plot_training_vs_validation(train0, **kwargs)[source]
Bar plot comparing training with validation set.
- Parameters:
train0 (list) – Indices of the training points.
train1 (list, optional) – More lists with indices train2, train3, etc. are also keywords
nsamples (bool, optional) – Show a horizontal line indicating the total number of samples
percent (bool, optional) – Indicate the agreement in percent above each bar
- Returns:
Plot handle
- Return type:
matplotlib.pyplot
- plot_variability(fname, xvar, yvar, **kwargs)[source]
Plot the mean, min and max over all samples.
- Parameters:
fname (str) – File containing the data (xvar and yvar)
xvar (str) – x-axis data
yvar (str) – y-axis data
idx (bool, optional) – Fix the x-axis labels (takes the original data order but uses the indices to plot and the values as ticks), useful for periodic values (e.g. azimuth)
nticks (int, optional) – Number of ticks on axes (only for idx=True)
- Returns:
Plot handle
- Return type:
matplotlib.pyplot
opal.visualization.SolverPlotter module
opal.visualization.StatPlotter module
- class opal.visualization.StatPlotter.StatPlotter[source]
Bases:
BasePlotter
- plot_envelope(xvar='position', **kwargs)[source]
Create an envelope plot.
Author: Philippe Ganz Date: 2018
- Parameters:
xvar (str) – x-axis variable
dset (list [StatDataset], optional) – List of other statistic datasets
lfile (str, optional) – Lattice file (
*
.lattice)
- Returns:
Plot handle
- Return type:
matplotlib.pyplot
- plot_profile1D(xvar, yvar, **kwargs)[source]
Plot a 1D profile.
- Parameters:
xvar (str) – Variable for x-axis
yvar (str) – Variable for y-axis
xscale (str, optional) – ‘linear’, ‘log’
yscale (str, optional) – ‘linear’, ‘log’
xsci (bool, optional) – x-ticks in scientific notation
ysci (bool, optional) – y-ticks in scientific notation
- Returns:
Plot handle
- Return type:
matplotlib.pyplot
opal.visualization.StdOpalOutputPlotter module
- class opal.visualization.StdOpalOutputPlotter.StdOpalOutputPlotter[source]
Bases:
TimingPlotter
opal.visualization.TimingPlotter module
- class opal.visualization.TimingPlotter.TimingPlotter[source]
Bases:
BasePlotter
- __mostConsuming(n, times, labels, prop)
Retturn time and label of the first n most time consuming timings.
- Parameters:
timings (labels ([]) list of labels to appropriate) –
data (times ([]) list of timing) –
timings –
- Return type:
sorted times and labels
- plot_efficiency(dsets, what, prop, **kwargs)[source]
Efficiency plot of a timing benchmark study
E_p = S_p / p
where E_p is the efficiency and S_p the speed-up with p cores / nodes.
- Parameters:
datasets (dsets ([TimeDataset]) all timing) –
name (what (str) timing) –
property (prop (str)) – ‘wall avg’, ‘wall max’, ‘wall min’ or ‘cpu tot’ and ‘wall tot’ (only for main timing)
avg' (i.e. 'cpu) – ‘wall avg’, ‘wall max’, ‘wall min’ or ‘cpu tot’ and ‘wall tot’ (only for main timing)
max' ('cpu) – ‘wall avg’, ‘wall max’, ‘wall min’ or ‘cpu tot’ and ‘wall tot’ (only for main timing)
min' ('cpu) – ‘wall avg’, ‘wall max’, ‘wall min’ or ‘cpu tot’ and ‘wall tot’ (only for main timing)
- :param‘wall avg’, ‘wall max’, ‘wall min’ or
‘cpu tot’ and ‘wall tot’ (only for main timing)
- Parameters:
Optionals –
--------- –
scale (yscale (str) y-axis) –
'log' ('linear' or) –
scale –
'log' –
true (grid (bool) if) –
grid (plot) –
percentage (percent (bool) efficiency in) –
'#cores' (xlabel (str) label for x-axis. Default) –
node (core2node (int) scale #cores == 1) – (useful with xlabel=’#nodes’)
- Return type:
a matplotlib.pyplot handle
- plot_pie_chart(prop, **kwargs)[source]
Create a pie plot of the first N most time consuming timings.
- Parameters:
dataset (ds (DatasetBase) timing) –
property (prop (str)) – ‘wall avg’, ‘wall max’, ‘wall min’ or ‘cpu tot’ and ‘wall tot’ (only for main timing)
avg' (i.e. 'cpu) – ‘wall avg’, ‘wall max’, ‘wall min’ or ‘cpu tot’ and ‘wall tot’ (only for main timing)
max' ('cpu) – ‘wall avg’, ‘wall max’, ‘wall min’ or ‘cpu tot’ and ‘wall tot’ (only for main timing)
min' ('cpu) – ‘wall avg’, ‘wall max’, ‘wall min’ or ‘cpu tot’ and ‘wall tot’ (only for main timing)
- :param‘wall avg’, ‘wall max’, ‘wall min’ or
‘cpu tot’ and ‘wall tot’ (only for main timing)
- Parameters:
Optionals –
--------- –
specialized (first=None (int) take only the first N) – timings
timings (exclude ([]) do not use these) –
name (tag='' (str) what tag should be in) –
scheme (cmap_name='YlGn' (str) color) –
Notes
Throws an exception if file not available or the key is not part of the dictionary
- Return type:
a matplotlib.pyplot handle
- plot_speedup(dsets, what, prop, **kwargs)[source]
Speedup plot of a timing benchmark study
S_p = T_1 / T_p
where T_1 is the time for a single core run (or reference run with several cores / nodes) and T_p the time with p cores. S_p then represents the speed-up with p cores / nodes.
- Parameters:
datasets (dsets ([TimeDataset]) all timing) –
name (what (str) timing) –
property (prop (str)) – ‘wall avg’, ‘wall max’, ‘wall min’ or ‘cpu tot’ and ‘wall tot’ (only for main timing)
avg' (i.e. 'cpu) – ‘wall avg’, ‘wall max’, ‘wall min’ or ‘cpu tot’ and ‘wall tot’ (only for main timing)
max' ('cpu) – ‘wall avg’, ‘wall max’, ‘wall min’ or ‘cpu tot’ and ‘wall tot’ (only for main timing)
min' ('cpu) – ‘wall avg’, ‘wall max’, ‘wall min’ or ‘cpu tot’ and ‘wall tot’ (only for main timing)
- :param‘wall avg’, ‘wall max’, ‘wall min’ or
‘cpu tot’ and ‘wall tot’ (only for main timing)
- Parameters:
Optionals –
--------- –
scale (yscale (str) y-axis) –
'log' ('linear' or) –
scale –
'log' –
true (grid (bool) if) –
grid (plot) –
plot (efficiency (bool) add efficiency to) –
'#cores' (xlabel (str) label for x-axis. Default) –
node (core2node (int) scale #cores == 1) – (useful with xlabel=’#nodes’)
line (perfect_scaling (bool) add speed-up perfect scaling) –
- Return type:
a matplotlib.pyplot handle
- plot_time_scaling(dsets, prop, **kwargs)[source]
Plot timing benchmark.
- Parameters:
datasets (dsets ([TimeDataset]) all timing) –
property (prop (str)) –
'cpu ('wall' or) –
Optionals –
--------- –
specialized (first=None (int) take only the first N) –
scale (yscale (str) y-axis) –
'log' ('linear' or) –
scale –
'log' –
true (grid (bool) if) –
grid (plot) –
'#cores' (xlabel (str) label for x-axis. Default) –
node (core2node (int) scale #cores == 1) – (useful with xlabel=’#nodes’)
timings (exclude ([]) do not use these) –
tag (tag='' (str) take only timings containing this) –
line (perfect_scaling (bool) add speed-up perfect scaling) –
- Return type:
a matplotlib.pyplot handle
- plot_time_summary(prop, **kwargs)[source]
Create a plot with minimum, maximum and average timings
- Parameters:
dataset (ds (DatasetBase) timing) –
property (prop (str)) –
'cpu ('wall' or) –
Optionals –
--------- –
scale (yscale (str) y-axis) –
'log' ('linear' or) –
true (grid (bool) if) –
grid (plot) –
timings (exclude ([]) do not use these) –
tag (tag='' (str) take only timings containing this) –
- Return type:
a matplotlib.pyplot handle
opal.visualization.TrackOrbitPlotter module
- class opal.visualization.TrackOrbitPlotter.TrackOrbitPlotter[source]
Bases:
BasePlotter
- plot_beta_beat(nsteps=-1, **kwargs)[source]
- Parameters:
nsteps (int, optional) – Number of steps per turn (default -1: detect automatically)
- Returns:
Plot handle
- Return type:
matplotlib.pyplot
- plot_energy(nsteps=-1, **kwargs)[source]
- Parameters:
nsteps (int, optional) – Number of steps per turn (default -1: detect automatically)
- Returns:
Plot handle
- Return type:
matplotlib.pyplot
- plot_energy_gain(nsteps=-1, **kwargs)[source]
- Parameters:
nsteps (int, optional) – Number of steps per turn (default -1: detect automatically)
- Returns:
Plot handle
- Return type:
matplotlib.pyplot
- plot_orbits(pid=0, **kwargs)[source]
Do an orbit plot.
- Parameters:
pid (int, optional) – Which particle id (default: 0)
- Returns:
Plot handle
- Return type:
matplotlib.pyplot
- plot_turn_separation(nsteps=-1, angle=0.0, asFunctionOfTurnNumber=True, asFunctionOfEnergy=False, **kwargs)[source]
- Parameters:
nsteps (int, optional) – Number of steps per turn (default -1: detect automatically)
angle (float, optional) – Angle of reference line in radians
asFunctionOfTurnNumber (bool) – x-axis turn number
asFunctionOfEnergy (bool) – x-axis energy
- Returns:
Plot handle
- Return type:
matplotlib.pyplot