Skip to content

Commit 425c73e

Browse files
SebastienJolySebastienJoly
andauthored
Change np.average to np.ma.average to properly handle cases with zero weights. (#60)
Co-authored-by: SebastienJoly <[email protected]>
1 parent 9e6407d commit 425c73e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

pySC/core/beam.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def bpm_reading(SC: SimulatedCommissioning, bpm_ords: ndarray = None, calculate_
4747
bpm_orbits_4d[:, :, :, shot_num], bpm_sums_4d[:, :, :, shot_num] = _real_bpm_reading(SC, tracking_4d, bpm_inds)
4848

4949
# mean_bpm_orbits_3d is 3D (dim, BPM, turn)
50-
mean_bpm_orbits_3d = np.average(np.ma.array(bpm_orbits_4d, mask=np.isnan(bpm_orbits_4d)),
51-
weights=np.ma.array(bpm_sums_4d, mask=np.isnan(bpm_sums_4d)), axis=3).filled(np.nan)
50+
mean_bpm_orbits_3d = np.ma.average(np.ma.array(bpm_orbits_4d, mask=np.isnan(bpm_orbits_4d)),
51+
weights=np.ma.array(bpm_sums_4d, mask=np.isnan(bpm_sums_4d)), axis=3).filled(np.nan)
5252
# averaging "charge" also when the beam did not reach the location
5353
mean_bpm_sums_3d = np.nansum(bpm_sums_4d, axis=3) / SC.INJ.nShots
5454

0 commit comments

Comments
 (0)