Skip to content

Commit

Permalink
Merge pull request #49 from LIBRA-project/fix-count-rate
Browse files Browse the repository at this point in the history
Fix count rate bug
  • Loading branch information
RemDelaporteMathurin authored Feb 5, 2025
2 parents d3e0694 + c179353 commit 981e592
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libra_toolbox/neutron_detection/diamond/process_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def get_count_rate(self, bin_time: float, energy_window: tuple = None):
time_values = self.time_values.copy()
energy_values = self.energy_values.copy()

time_bins = np.arange(0, time_values[-2], bin_time)
time_bins = np.arange(time_values.min(), time_values[-2], bin_time)

if energy_window is not None:
peak_mask = (energy_values > energy_window[0]) & (
Expand Down
15 changes: 15 additions & 0 deletions test/neutron_detection/test_diamond.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,18 @@ def test_get_count_rate(tmpdir):
assert np.allclose(count_rates_peak2, expected_count_rate_peak2, rtol=0.1)

assert len(count_rate_bins_total) == total_time_s / bin_time


def test_count_rate_doesnt_ignore_data():
"""Test to catch the bug in #48"""

# create a processor with time from -100 to 100 and energy values from -100 to 100
processor = DataProcessor()
processor.time_values = np.linspace(-100, 100, 1000)
processor.energy_values = np.linspace(-100, 100, 1000)

# calculate the count rates
count_rates, time_bins = processor.get_count_rate(bin_time=1)

# the first time bin should be -100
assert np.isclose(time_bins[0], -100)

0 comments on commit 981e592

Please sign in to comment.