Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0df034b
Start envelope 2D module
austin-hoover Jan 5, 2026
1ef0323
Envelope stores empty Bunch object
austin-hoover Jan 5, 2026
1b037fb
Add track method to Envelope2D
austin-hoover Jan 5, 2026
6b84711
Start test script for envelope2D tracker
austin-hoover Jan 5, 2026
13d36e9
Add empty spaceChargeMatrix method
austin-hoover Jan 5, 2026
86fd680
Merge branch 'PyORBIT-Collaboration:main' into env-tracker
austin-hoover Apr 24, 2026
75c133c
Add .idea to .gitignore
austin-hoover Apr 24, 2026
e6efd34
Merge branch 'env-tracker' of https://github.com/austin-hoover/PyORBI…
austin-hoover Apr 24, 2026
7aa7a47
Change Envelope2D to Envelope
austin-hoover Apr 24, 2026
3d0d65c
Update example
austin-hoover Apr 24, 2026
63eb825
Docstrings
austin-hoover Apr 24, 2026
dfeadbd
Add envelope/matrix.py
austin-hoover Apr 24, 2026
a1b32fa
Add MatrixFactory class
austin-hoover Apr 24, 2026
3003c0b
Add several classes to teapot __init__
austin-hoover Apr 24, 2026
e27c57a
Add node types to ignore in matrix factory
austin-hoover Apr 24, 2026
fe81902
Add envelope tracker
austin-hoover Apr 24, 2026
6fad0f7
Delete test script
austin-hoover Apr 24, 2026
d7586c7
Format
austin-hoover Apr 24, 2026
6982c2f
Format
austin-hoover Apr 24, 2026
bc002e1
Fix error in centroid coordinates in example
austin-hoover Apr 24, 2026
7c9abab
Add space charge calculation
austin-hoover Apr 24, 2026
2f67e2c
Add space charge in PIC test + visual comparison of distribution
austin-hoover Apr 24, 2026
7cbe59a
Plot dots
austin-hoover Apr 24, 2026
33b3f16
Fix factor of 2 in perveance calculation
austin-hoover Apr 24, 2026
38f884e
Add kv/waterbag/gauss dist
austin-hoover Apr 24, 2026
c37fc3a
Add tilt to 2D envelope space charge calculation
austin-hoover Apr 24, 2026
752bae3
Add corner plot and tilt test
austin-hoover Apr 24, 2026
e704cdc
Format
austin-hoover Apr 24, 2026
f8987bb
Format
austin-hoover Apr 24, 2026
b9fec41
Add comment on cholesky issue
austin-hoover Apr 24, 2026
09838f6
Delete commented line
austin-hoover Apr 24, 2026
271717a
Edit .gitignore
austin-hoover Apr 24, 2026
5fa7c2b
Docstrings
austin-hoover Apr 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.DS_Store
.idea
build
PyORBIT.egg-info
.vscode
Expand Down
132 changes: 132 additions & 0 deletions examples/Envelope/plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches


def calc_rms_ellipse_params(cov_matrix: np.ndarray) -> tuple[float, float, float]:
"""Return rms ellipse dimensions and orientation."""
(i, j) = (0, 1)

sii = cov_matrix[i, i]
sjj = cov_matrix[j, j]
sij = cov_matrix[i, j]

angle = -0.5 * np.arctan2(2.0 * sij, sii - sjj)

_sin = np.sin(angle)
_cos = np.cos(angle)
_sin2 = _sin**2
_cos2 = _cos**2

c1 = np.sqrt(abs(sii * _cos2 + sjj * _sin2 - 2 * sij * _sin * _cos))
c2 = np.sqrt(abs(sii * _sin2 + sjj * _cos2 + 2 * sij * _sin * _cos))

return (c1, c2, angle)


def plot_ellipse(
r1: float = 1.0,
r2: float = 1.0,
angle: float = 0.0,
center: tuple[float, float] = None,
ax=None,
**kws,
):
kws.setdefault("fill", False)
kws.setdefault("color", "black")
kws.setdefault("lw", 1.25)

center = (0.0, 0.0)

d1 = r1 * 2.0
d2 = r2 * 2.0
angle = -np.degrees(angle)

ax.add_patch(patches.Ellipse(center, d1, d2, angle=angle, **kws))
return ax


def plot_rms_ellipse(
cov_matrix: np.ndarray,
level: float = 1.0,
ax=None,
**ellipse_kws,
):
"""Plot rms ellipse from 2 x 2 covariance matrix."""
r1, r2, angle = calc_rms_ellipse_params(cov_matrix)
plot_ellipse(r1 * level, r2 * level, angle=angle, ax=ax, **ellipse_kws)
return ax


def plot_corner(
particles: np.ndarray,
limits: list[tuple[float, float]] = None,
bins: int = 64,
labels: list[str] = None,
blur: float = None,
) -> tuple:
"""Generate corner plot."""
ndim = particles.shape[1]

if limits is None:
xmax = np.max(particles, axis=0)
xmin = np.min(particles, axis=0)
limits = list(zip(xmin, xmax))

if labels is None:
labels = ndim * [""]

fig, axs = plt.subplots(
ncols=ndim, nrows=ndim, sharex=None, sharey=None, figsize=(8, 8)
)
for i in range(ndim):
for j in range(ndim):
axis = (j, i)
ax = axs[i, j]
if i > j:
values, edges = np.histogramdd(
particles[:, axis], bins=bins, range=[limits[k] for k in axis]
)
if blur:
values = scipy.ndimage.gaussian_filter(values, sigma=blur)
ax.pcolormesh(
edges[0],
edges[1],
values.T,
linewidth=0.0,
rasterized=True,
shading="auto",
)
elif i == j:
values, edges = np.histogram(
particles[:, i], bins=bins, range=limits[i]
)
if blur:
values = scipy.ndimage.gaussian_filter(values, sigma=blur)
ax.stairs(values, edges, lw=1.5, color="black")
else:
ax.axis("off")

for i in range(0, ndim - 1):
for j in range(0, ndim):
axs[i, j].set_xticklabels([])
for i in range(0, ndim):
for j in range(1, ndim):
axs[i, j].set_yticklabels([])

for ax in axs.flat:
for loc in ["top", "right"]:
ax.spines[loc].set_visible(False)

for i, label in enumerate(labels):
axs[-1, i].set_xlabel(label)
for i, label in enumerate(labels[1:], start=1):
axs[i, 0].set_ylabel(label)

axs[0, 0].set_yticklabels([])
axs[0, 0].set_ylabel(None)

fig.align_ylabels()
fig.align_xlabels()

return fig, axs
8 changes: 8 additions & 0 deletions examples/Envelope/style.mplstyle
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
axes.linewidth: 1.25
axes.titlesize: "medium"
image.cmap: "Greys"
figure.constrained_layout.use: True
savefig.dpi: 300
savefig.format: "png"
xtick.minor.visible: True
ytick.minor.visible: True
Loading
Loading