Skip to content

Commit bdaf026

Browse files
Merge pull request #872 from nabilbrice/fix_pdm_bincounting
Fix pdm bincounting
2 parents ff99646 + 689837a commit bdaf026

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

docs/changes/872.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed issue with counting ``0`` bin occupancy in ``fold_events`` with ``mode='pdm'``

stingray/pulse/pulsar.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@ def fold_events(times, *frequency_derivatives, **opts):
308308
if expocorr:
309309
expo_norm = phase_exposure(start_phase, stop_phase, 1, nbin, gti=gti_phases)
310310
simon("For exposure != 1, the uncertainty might be incorrect")
311-
312311
else:
313312
expo_norm = 1
314313

@@ -328,7 +327,10 @@ def fold_events(times, *frequency_derivatives, **opts):
328327

329328
# I need the variance uncorrected for the number of data points in each
330329
# bin, so I need to find that first, and then multiply
331-
_, bincounts = np.unique(bin_idx, return_counts=True)
330+
# bin_idx should be from the list [1, ..., nbin], although some might not appear
331+
# histogram bin-edges set as [0.5, 1.5, ..., nbin - 0.5, nbin + 0.5]
332+
# to include the bin_idx int values
333+
bincounts, _ = np.histogram(bin_idx, bins=np.arange(0.5, nbin + 1.5))
332334
raw_profile = raw_profile * bincounts
333335

334336
# dummy array for the error, which we don't have for the variance

stingray/pulse/tests/test_pulse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def test_pulse_profile_pdm(self):
212212
times = np.arange(0, 2 - dt, dt)
213213
counts = np.random.normal(3, 0.5, size=len(times))
214214
gti = np.array([[-0.5 * dt, 2 - dt]])
215-
bins, profile, prof_err = fold_events(times, 1, nbin=nbin, weights=counts, mode="pdm")
215+
bins, profile, prof_err = fold_events(times, 0.237, nbin=nbin, weights=counts, mode="pdm")
216216
assert np.all(prof_err == 0)
217217

218218
def test_mode_incorrect(self):

0 commit comments

Comments
 (0)