Skip to content

Commit 7f18252

Browse files
Merge pull request #6 from austin-hoover/dev
Add method to set individual particle macrosizes
2 parents 7ff0ddc + 834bfa5 commit 7f18252

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

orbit_tools/bunch.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
from .cov import normalization_matrix
1919

2020

21+
def set_particle_macrosizes(bunch: Bunch, macrosizes: Iterable) -> Bunch:
22+
bunch.addPartAttr("macrosize") # sets macrosize=0 for all particles
23+
attribute_array_index = 0
24+
for index in range(bunch.getSize()):
25+
bunch.partAttrValue("macrosize", index, attribute_array_index, macrosizes[index])
26+
return bunch
27+
28+
2129
def get_part_coords(bunch: Bunch, index: int) -> list[float]:
2230
x = bunch.x(index)
2331
y = bunch.y(index)

tests/test_bunch.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,12 @@ def sample():
126126
def test_get_bunch_twiss_containers():
127127
bunch = make_gaussian_bunch()
128128
twiss_x, twiss_y, twiss_z = ot.bunch.get_bunch_twiss_containers(bunch)
129+
130+
131+
def test_set_particle_macrosizes():
132+
bunch = make_gaussian_bunch()
133+
macrosizes = list(range(bunch.getSize()))
134+
bunch = ot.bunch.set_particle_macrosizes(bunch, macrosizes)
135+
for i, macrosize in enumerate(macrosizes):
136+
assert macrosize == bunch.partAttrValue("macrosize", i, 0)
137+

0 commit comments

Comments
 (0)