lbl-anp / becquerel

Becquerel is a Python package for analyzing nuclear spectroscopic measurements.
Other
43 stars 16 forks source link

Calibration raises warning when values are outside its range #319

Closed markbandstra closed 2 years ago

markbandstra commented 2 years ago

Fixes #314. Now a warning is raised when a Calibration function yields values outside its specified range. For example:

import becquerel as bq
spec = bq.Spectrum.from_file("tests/samples/nai_detector.spe")
cal = bq.Calibration.from_linear([-10, 2.02], rng=[0, 1e2])
spec.apply_calibration(cal)

Yields:

SpeFile: Reading file tests/samples/nai_detector.spe
/Users/msbandstra/Dropbox/Projects/Becquerel/becquerel/becquerel/core/calibration.py:157: CalibrationWarning: Function values are below the lower range (0.0) and above the upper range (100.0)
  warnings.warn(msg, CalibrationWarning)

The warning is raised but no longer are the values themselves clipped to the range as this has led to various problems.

markbandstra commented 2 years ago

Also fixes #309. Ready for review.

jvavrek commented 2 years ago

I still kind of think that the default domain and range should be unbounded, especially given that the domain is really only used for validation and default plot x values. But that's maybe for another time.

markbandstra commented 2 years ago

Not sure how to clear the "changes requested" status of this PR given that I have resolved all of the issues flagged by @jvavrek ...

jvavrek commented 2 years ago

Not sure how to clear the "changes requested" status of this PR given that I have resolved all of the issues flagged by @jvavrek ...

I think I just had to hit Approve. Send it! 🚀