@@ -209,14 +209,17 @@ def phase_exposure(start_time, stop_time, period, nbin=16, gti=None):
209209 return expo / np .max (expo )
210210
211211
212- def fold_events (times , * frequency_derivatives ,
213- mode = "ef" ,
214- nbin = 16 ,
215- weights = 1 ,
216- gti = None ,
217- ref_time = 0 ,
218- expocorr = False ,
219- variances = None ):
212+ def fold_events (
213+ times ,
214+ * frequency_derivatives ,
215+ mode = "ef" ,
216+ nbin = 16 ,
217+ weights = 1 ,
218+ gti = None ,
219+ ref_time = 0 ,
220+ expocorr = False ,
221+ variances = None ,
222+ ):
220223 """Epoch folding with exposure correction.
221224
222225 By default, the keyword `times` accepts a list of
@@ -321,7 +324,9 @@ def fold_events(times, *frequency_derivatives,
321324
322325 # For weighted pdm, the measured uncertainties (variances) for each event are required
323326 # set the event_weights as 1/variances or else 1s if variances=None
324- event_weights = (1.0 / np .asarray (variances )) if variances is not None else np .ones_like (weights )
327+ event_weights = (
328+ (1.0 / np .asarray (variances )) if variances is not None else np .ones_like (weights )
329+ )
325330
326331 bins = np .linspace (0 , 1 , nbin + 1 )
327332 # phases are already fractional values in [0, 1]
@@ -331,19 +336,16 @@ def fold_events(times, *frequency_derivatives,
331336 bin_indices = np .clip (bin_indices , 0 , nbin - 1 )
332337
333338 # for efficiency, the sum-of-squared deviations for each bin is split
334- # ss_dev = sum_in_bin( (values_in_bin - mean_in_bin)**2 )
339+ # sosdev = sum_in_bin( (values_in_bin - mean_in_bin)**2 )
335340 # mean_in_bin = sum_in_bin(values_in_bin) / n_in_bin
336- # so need n_in_bin, sum_in_bin, sumofsquares_in_bin
341+ # so need n_in_bin, sum_in_bin, sos_in_bin (sum-of-squares)
337342 # now compute the stats for each bin using bincount
338343 # minlength=nbin prevents array shortening when a bin index is not represented in bin_indices
339- n_in_bin = np .bincount (bin_indices , weights = event_weights ,
340- minlength = nbin )
341- sum_in_bin = np .bincount (bin_indices , weights = weights * event_weights ,
342- minlength = nbin )
343- sumofsquares_in_bin = np .bincount (bin_indices , weights = weights ** 2 * event_weights ,
344- minlength = nbin )
345- # put it together; avoid division by zero
346- raw_profile = sumofsquares_in_bin - sum_in_bin ** 2 / np .maximum (n_in_bin , 1 )
344+ n_in_bin = np .bincount (bin_indices , weights = event_weights , minlength = nbin )
345+ sum_in_bin = np .bincount (bin_indices , weights = weights * event_weights , minlength = nbin )
346+ sos_in_bin = np .bincount (bin_indices , weights = weights ** 2 * event_weights , minlength = nbin )
347+ # put it together to make sum-of-squared deviations: sosdev; avoid division by zero
348+ raw_profile = sos_in_bin - sum_in_bin ** 2 / np .maximum (n_in_bin , 1 )
347349
348350 # dummy array for the error, which we don't have for the variance
349351 raw_profile_err = np .zeros_like (raw_profile )
0 commit comments