Skip to content

Commit 1c969ce

Browse files
removed double
1 parent 0923cb9 commit 1c969ce

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

libra_toolbox/neutron_detection/activation_foils/compass.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,13 @@ def __init__(self, channel_nb) -> None:
178178
self.real_count_time = None
179179

180180
def get_energy_hist(
181-
self, bins: Union[int, str, NDArray[np.float64]]
181+
self, bins: Union[int, NDArray[np.float64], None] = None
182182
) -> Tuple[np.ndarray, np.ndarray]:
183183
"""
184184
Get the energy histogram of the detector events.
185185
Args:
186-
bins: number of bins or "double" to use half the max energy as bin size
186+
bins: number of bins, can be a numpy array, if None, it will be set to the
187+
maximum energy value in the events (one bin per energy value)
187188
Returns:
188189
Tuple of histogram values and bin edges
189190
"""
@@ -198,12 +199,10 @@ def get_energy_hist(
198199

199200
energy_values = np.nan_to_num(energy_values, nan=0)
200201

201-
if isinstance(bins, (np.ndarray, int)):
202-
real_bins = bins
203-
elif bins == "double":
204-
real_bins = int(np.nanmax(energy_values) / 2)
202+
if bins is None:
203+
bins = int(np.nanmax(energy_values))
205204

206-
return np.histogram(energy_values, bins=real_bins)
205+
return np.histogram(energy_values, bins=bins)
207206

208207

209208
class Measurement:

test/neutron_detection/test_compass.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ def test_measurement_object_from_directory(no_root):
300300

301301
assert measurement.detectors[0].events.shape[1] == 2
302302

303-
measurement.detectors[0].get_energy_hist(bins="double")
303+
measurement.detectors[0].get_energy_hist(bins=None)
304304

305305

306306
@pytest.mark.parametrize(
@@ -310,7 +310,7 @@ def test_measurement_object_from_directory(no_root):
310310
20,
311311
50,
312312
100,
313-
"double",
313+
None,
314314
np.arange(0, 10, 1),
315315
np.linspace(0, 10, num=100),
316316
],

0 commit comments

Comments
 (0)