Skip to content

Commit d85cafa

Browse files
Merge pull request #84 from CHIMEFRB/ss/bugfix-2024-08
ss/bugfix-2024-08
2 parents 57a86a8 + dfbcf3b commit d85cafa

File tree

7 files changed

+587
-362
lines changed

7 files changed

+587
-362
lines changed

fitburst/analysis/fitter.py

+4
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,10 @@ def _compute_fit_statistics(self, spectrum_observed: float, fit_result: object)
484484
covariance = np.linalg.inv(0.5 * hessian)
485485
uncertainties = [float(x) for x in np.sqrt(np.diag(covariance)).tolist()]
486486

487+
if np.any(np.isnan(uncertainties)):
488+
print("WARNING: one or more NaNs in exact uncertainties, replacing with approximates...")
489+
uncertainties = [float(x) for x in np.sqrt(np.diag(covariance_approx)).tolist()]
490+
487491
self.covariance_approx = covariance_approx
488492
self.covariance = covariance
489493
self.covariance_labels = par_labels

fitburst/analysis/model.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -342,18 +342,15 @@ def compute_profile(self, times: float, arrival_time: float, sc_time_ref: float,
342342
# compute either Gaussian or pulse-broadening function, depending on inputs.
343343
profile = np.zeros(times_copy.shape, dtype=float)
344344
sc_time = sc_time_ref * (freqs / ref_freq) ** sc_index
345+
normalize = general["flags"]["normalize_pbf"]
345346

346-
if np.any(sc_time < np.fabs(0.15 * width)):
347-
profile = rt.profile.compute_profile_gaussian(times_copy, arrival_time, width)
348-
349-
else:
350-
# the following times array manipulates the times array so that we avoid a
351-
# floating-point overlow in the exp((-times - toa) / sc_time) term in the
352-
# PBF call. TODO: use a better, more transparent method for avoiding this.
347+
if np.any(sc_time > 0.0):
353348
times_copy[times_copy < -5 * width] = -5 * width
354349
profile = rt.profile.compute_profile_pbf(
355-
times_copy, arrival_time, width, freqs, ref_freq, sc_time_ref, sc_index=sc_index
350+
times_copy, arrival_time, width, freqs, ref_freq, sc_time_ref, sc_index=sc_index, normalize=normalize
356351
)
352+
else:
353+
profile = rt.profile.compute_profile_gaussian(times_copy, arrival_time, width)
357354

358355
# if data are folded and time/profile data contain two realizations, then
359356
# average along the appropriate axis to obtain a single realization.

fitburst/backend/general.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ constants:
77
dispersion: 4149.377593360996 # in units of MHz**2 * s * cm**3 / pc
88
index_dispersion: -2.0
99
index_scattering: -4.0
10+
11+
flags:
12+
normalize_pbf: False

fitburst/pipelines/fitburst_pipeline.py

+6
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,9 @@
540540
current_uncertainties = bestfit_uncertainties[current_parameter_label]
541541
print(f" * {current_parameter_label}: {current_list} +/- {current_uncertainties}")
542542

543+
print("INFO: ratio of hessian matrix (approximate / exact):")
544+
print(fitter.hessian / fitter.hessian_approx)
545+
543546
# now create plots.
544547
filename_elems = input_file.split(".")
545548
output_string = ".".join(filename_elems[:len(filename_elems)-1])
@@ -561,6 +564,9 @@
561564
"initial_time": data.times_bin0,
562565
"model_parameters": current_params,
563566
"fit_statistics": fitter.fit_statistics,
567+
"fit_logistics" : {
568+
"weight_range" : weight_range,
569+
}
564570
},
565571
out,
566572
indent=4

0 commit comments

Comments
 (0)