-
Notifications
You must be signed in to change notification settings - Fork 22
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
MPL: ImpactXParticleContainer.plot_phasespace()
#469
Conversation
999695d
to
0388828
Compare
42266eb
to
8c1c54a
Compare
4add576
to
e806869
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great. Two comments:
- We might consider the powers of ten used for the axes. I often see plots with x and y in units of [mm], and with px and py in units of [mrad] for non-LPA generated beams.
- It would be good to double-check whether the emittance values are normalized or unnormalized. The notation suggests that the values are normalized.
Ah yes, mm-mrad also makes sense for LPA beams actually. Yes, exactly, the data is normalized emittance. |
1e2f2f6
to
3bdaf64
Compare
The emittance notation looks good. For |
8079d69
to
9b0fcc1
Compare
Hmm, this still looks like a 2D histogram density to me, just with a higher resolution. Here's a little snippet that creates a scatter plot with point coloring according to the density # Creating a 2D histogram to calculate particle densities
hist, xedges, yedges = np.histogram2d(bunch.x, bunch.y, bins=250)
# hist: 2D array with density values for each bin
# xedges, yedges: bin edge values for x and y dimensions
# Function to get density values for each point from the histogram
def get_density_from_histogram(x, y, hist, xedges, yedges):
# Find the indices of the bins to which each x and y value belongs
x_idx = np.searchsorted(xedges, x, side='right') - 1
y_idx = np.searchsorted(yedges, y, side='right') - 1
# Ensure indices are within the valid range (0 to number of bins - 1)
# This prevents index out-of-bounds errors
x_idx = np.clip(x_idx, 0, hist.shape[0] - 1)
y_idx = np.clip(y_idx, 0, hist.shape[1] - 1)
# Return the density value for each (x, y) pair from the histogram
return hist[x_idx, y_idx]
# Get density values for each point in the scatter plot
colors = get_density_from_histogram(bunch.x, bunch.y, hist, xedges, yedges)
# Plotting the scatter plot with density-based coloring
fig,ax = plt.subplots(1,1)
scatter = ax.scatter(bunch.x, bunch.y, c=colors, cmap='viridis', rasterized=True, s=1) # Use 'viridis' colormap
plt.colorbar(scatter, ax=ax, label='Density in Bin') # Add a color bar for density values
ax.set_title('Scatter Plot with Histogram-based Density Coloring')
ax.set_xlabel(r'$x$ (m)')
ax.set_ylabel(r'$y$ (m)')
ax.grid(True) |
Thanks; I guess this is always the case. Scatterplot = histogram with values 0 (no particles per bin) and 1 (> 0 particles per bin). Maybe the important features to balance are:
|
Thank you both! I agree on the analysis. Thus, the binning is a user-facing parameter and I just showed the default (50x50). Note that doing a scatter plot is not as easily scalable to arbitrary particle numbers in the bunch as histogramming. (needs more thought to parallelize. We could add an option to scatter plot and let people opt-into the costs of serialization) For this test, 50x50100x100200x200 |
0997b90
to
b95b45e
Compare
Add an interactive plotter to quickly check the current phase space of the particle bunch. This is heavily inspired by Wake-T's `bunch.show()` functionality.
289bdab
to
7ac4225
Compare
Install `requirements.txt` Chain of `requirements.txt`: tests -> examples -> root
@cemitch99 @n01r shall we merge this for now? :) |
Yea, totally, let's merge :) |
Just FYI, because it is related. Through CAMPA, @s-sajid-ali is currently working to ensure that ImpactX and Synergia can use https://github.com/ChristopherMayes/openPMD-beamphysics soon :) |
@n01r if you like to contribute the scatter logic (e.g., via a |
@ax3l, what's the advantage of hexagons? Why not dots? You are referring to this here, I guess, https://github.com/ChristopherMayes/openPMD-beamphysics/blob/master/docs/examples/particle_examples.ipynb |
I was remembering this wrong - this is also a scatter plot (of dots) in openPMD-beamphysics. I thought for a hot minute that was a histogram plot using hexagon bins. |
Add an interactive plotter to quickly check the current phase space of the particle bunch.
This is heavily inspired by
Wake-T
'sbunch.show()
functionality from APTools 💖ImpactXParticleContainer.to_df()
#458s
or int
coordinates Particle Container: Track s or t #497