Skip to content

Commit

Permalink
Merge pull request #21 from LIBRA-project/negative-activity
Browse files Browse the repository at this point in the history
activity set to zero if negative
  • Loading branch information
RemDelaporteMathurin authored Dec 2, 2024
2 parents ea94769 + 995fb52 commit eef7af6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libra_toolbox/tritium/lsc_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ def substract_background(self, background_sample: "LSCSample"):
if self.background_substracted:
raise ValueError("Background already substracted")
self.activity -= background_sample.activity
if self.activity.magnitude < 0:
warnings.warn(
f"Activity of {self.name} is negative after substracting background. Setting to zero."
)
self.activity = 0 * ureg.Bq
self.background_substracted = True

@staticmethod
Expand Down
12 changes: 12 additions & 0 deletions test/tritium/test_lsc_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ def test_lscsample_substract_background():
sample.substract_background(background_sample)


def test_lscsample_substract_background_when_negative():
sample = LSCSample(0.5 * ureg.Bq, "Sample1")
background_sample = LSCSample(1.0 * ureg.Bq, "Background")
with pytest.warns(
UserWarning,
match=f"Activity of {sample.name} is negative after substracting background. Setting to zero.",
):
sample.substract_background(background_sample)
assert sample.activity == 0 * ureg.Bq
assert sample.background_substracted


def test_lscsample_from_file():
file_reader = LSCFileReader(
Path(__file__).parent / "TEST_CSV.csv",
Expand Down

0 comments on commit eef7af6

Please sign in to comment.