-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi-bunch plotting capabilities #11
Open
mattachu
wants to merge
37
commits into
impact-lbl:master
Choose a base branch
from
mattachu:feature/gui/multi-bunch
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Files were commited with CRLF (Windows-style) line endings. This stops them working on Linux. It's best to commit to Git with LF (Linux-style) line endings and use Git's own settings to make sure you get the right version when you check it out. On Windows, set Git to automatically change line endings on checkout: ``` git config core.autocrlf true ``` On Linux, set Git to checkout as-is but commit as LF: ``` git config core.autocrlf input ```
* Add new parameter `file_offset` to keep the files separate * Adjust output statements to use the new file numbers * Adjust output statements to include z-location and correctly scale `xpx` values (as in `diagnostic1avg_Output`)
* Call with a different file offset each time to avoid file clash * Call once at the start and then every 15 time steps
* Use a single plot for both single and multiple bunch plots * Use a drop-down to select bunch rather than a message window * Set the bunch selector based on number of bunches in simulation * Use methods instead of attributes to pass data
Adjusted calculation of `localmax(5)` and `localmax(6)` to match the calculation in the average diagnostic output subroutines. Previously would output maximum size in the z direction without first subtracting the beam centroid.
This deprecated class was removed in Matplotlib version 3.0.0
This deprecated method was also removed in Matplotlib version 3.0.0
Was failing to plot anything because of these inconsistencies.
Adds six new plots with multiple bunches: * Beam size (rms) * Emittance * Emittance growth * Energy * Combined energy (log-scale) * Combined phase space Can include all bunches or only a selected number of bunches. Beam size, emittance and emittance growth are plotted against time t or location z. Each bunch is plotted as a dotted line, and a combined value for all bunches as a solid line. Also plots experimental data for beam size alongside the simulation results. Energy spectra are plotted as histograms, including a combined plot for all bunches combined. Phase space plots are generated using Matplotlib's `hist2d` function, which is much faster than the custom method use for the single-file phase space plots. Also added 1D histograms to the axes. MultiBunchPlot.py can also be run as a script, outputting all files as PNG images, and can be run on a headless server. The bunches to plot can be given as a command-line parameter.
* Return 'single bunch' rather than 'bunch 1' from `MultiBunchPlot.bunch_text()` if there is only one bunch in the simulation * New method `MultiBunchPlot.check_bunch_list()` checks which bunches are valid and which are invalid * Only plot valid bunches when run as a script * Don't produce per-bunch plots when run as a script if there is only one bunch in the simulation
Sometimes an offset to the starting position is required to ensure no particles have negative starting position. In such cases, the z-location of particles should be adjusted to enable direct comparison of experiment and simulation. Specifying a z-offset makes the plots as if the particles had started at z=0 rather than at the offset location. Also changed titles for multi-bunch energy spectra plots, from e.g. "BPM 110" to "at z = 0.6 mm"
Previously assumed that v_z >> v_x and v_y
Previous code used the small-angle approximation tan x ~ x
Sometimes an IndexError is thrown when all particles are lost from a bunch. Also fixed some Matplotlib warnings about inefficient or deprecated practices.
Inadvertently changed in commit d3962a7
mattachu
force-pushed
the
feature/gui/multi-bunch
branch
from
January 28, 2021 12:05
c351b14
to
89807b0
Compare
Previous code had grown over time so that there was lots of duplication for the three sections for initial, final and BPM plots. This change moves that code into a new common method, `plot_phase_spaces_and_energies()`. It also adds some extra error handling to make sure the maximum amount of plots can be generated when run as a post-processing script.
mattachu
force-pushed
the
feature/gui/multi-bunch
branch
from
February 2, 2021 17:07
ba6bb70
to
b503484
Compare
When run as a script, the offset is loaded from file at the beginning of the `plot_all()` routine. When run as a GUI, the z-offset is loaded at draw time as part of the `create_offset_selector()` method, and the `get_offset()` method is also updated to check the input file if there is no value set in the GUI itself.
mattachu
force-pushed
the
feature/gui/multi-bunch
branch
from
February 3, 2021 11:05
69f3bfa
to
8c56b3e
Compare
Given a target range [min, max], the `plot_total_energy()` method will highlight this range in the energy spectrum, splitting the histogram into three sections for below, within and above the target range. The `plot_all()` script will also create a "target" phase space plot for each output step, including only the particles in the target energy range. A new method `select_by_energy()` is used to select the subset of data for a given energy range.
Now that energy range filter parameters have been added to the input file in branch `feature/filter-energy` (see commit 4781d70), the plot script can read these directly rather than needing them to be passed as a parameter to the plot function.
Total energy plot can highlight the target energy range, and the phase space plot can be filtered by energy range.
This allows plotting of the target range for cases when the integrator is run as usual but the target range values are still stored in the input file. This could be useful when running single-bunch simulations extracted from a larger multi-bunch simulation.
Previous code would treat a single bunch as one in a set, plotting with a dashed line and creating an unnecessary legend.
It's useful to save beam size plots against both z and t
need to resolve the conflict. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Adds six new plots with multiple bunches:
Can include all bunches or only a selected number of bunches.
Beam size, emittance and emittance growth are plotted against time t or location z.
Each bunch is plotted as a dotted line, and a combined value for all bunches as a solid line.
Also plots experimental data for beam size alongside the simulation results.
Energy spectra are plotted as histograms, including a combined plot for all bunches combined.
Phase space plots are generated using Matplotlib's
hist2d
function, which is much faster than the custom method use for the single-file phase space plots.Also added 1D histograms to the axes.
MultiBunchPlot.py can also be run as a script, outputting all files as PNG images, and can be run on a headless server.
The bunches to plot can be given as a command-line parameter.
Dependencies
This depends on a number of other pull requests:
These have already been merged into this branch, so this pull request should only be merged after the above have already been merged into the master branch. At that point, this current pull request should be rebased.
The commit with the actual multi-bunch plotting changes is fa6373b.
Example plots
Emittance
Energy
Phase space