Skip to content

Commit

Permalink
add: figure showing best fit in edd.MCAEnergyCalibrationProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
keara-soloway committed Feb 7, 2024
1 parent cd0b1c8 commit 4da0621
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion CHAP/edd/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,12 +1210,34 @@ def calibrate(self, calibration_config, detector, peak_energies,
peak_energies, 'linear', x=fit_peak_energies, nan_policy='omit')
slope = energy_fit.best_values['slope']
intercept = energy_fit.best_values['intercept']

# If we want to rescale slope so results are a linear
# correction from channel indices -> calibrated energies, not
# uncalibrated energies -> calibrated energies, then uncooment
# the following line.
# slope = (detector.max_energy_kev / detector.num_bins) * slope

# Reference plot to see fit results:
if interactive or save_figures:
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1,1)
ax.set_title(f'Detector {detector.detector_name} '
+ 'Energy Calibration Peak Fit')
ax.set_xlabel('Energy (keV)')
ax.set_ylabel('Intensity (a.u)')
ax.plot(uncalibrated_energies[mask], spectrum[mask],
label='MCA data')
ax.plot(uncalibrated_energies[mask], spectrum_fit.best_fit,
label='Best fit')
ax.legend()
fig.tight_layout()

if save_figures:
figfile = os.path.join(outputdir, 'energy_calibration_fit.png')
plt.savefig(figfile)
self.logger.info(f'Saved figure to {figfile}')
if interactive:
plt.show()

return float(slope), float(intercept)


Expand Down

0 comments on commit 4da0621

Please sign in to comment.