Skip to content

Commit 723a332

Browse files
test no root file case
1 parent 7f6fb1e commit 723a332

File tree

5 files changed

+63
-8
lines changed

5 files changed

+63
-8
lines changed

libra_toolbox/neutron_detection/activation_foils/compass.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,16 +246,19 @@ def from_directory(cls, source_dir: str, name: str) -> "Measurement":
246246
detectors = [Detector(channel_nb=nb) for nb in time_values.keys()]
247247

248248
# Get live and real count times
249-
root_filename = glob.glob(os.path.join(source_dir, "*.root"))[0]
250-
if not os.path.isfile(root_filename):
249+
all_root_filenames = glob.glob(os.path.join(source_dir, "*.root"))
250+
if len(all_root_filenames) == 1:
251+
root_filename = all_root_filenames[0]
252+
else:
253+
root_filename = None
251254
print("No root file found, assuming all counts are live")
252255

253256
for detector in detectors:
254257
detector.events = np.column_stack(
255258
(time_values[detector.channel_nb], energy_values[detector.channel_nb])
256259
)
257260

258-
if os.path.isfile(root_filename):
261+
if root_filename:
259262
live_count_time, real_count_time = get_live_time_from_root(
260263
root_filename, detector.channel_nb
261264
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
BOARD;CHANNEL;TIMETAG;ENERGY;ENERGYSHORT;FLAGS
2+
0;5;234859459;2;2;0x4000
3+
0;5;421999310;0;1;0x4000
4+
0;5;535148093;1237;810;0x4000
5+
0;5;1623550122;589;396;0x4000
6+
0;5;5997211248;375;251;0x4000
7+
0;5;6685836624;515;340;0x4000
8+
0;5;11116032249;568;380;0x4000
9+
0;5;11281099382;1;0;0x4000
10+
0;5;12783039350;5;0;0x4000
11+
0;5;18306299412;2;0;0x4000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
0;5;234859459;2;2;0x4000
2+
0;5;421999310;0;1;0x4000
3+
0;5;535148093;1237;810;0x4000
4+
0;5;1623550122;589;396;0x4000
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
id=Co60_0_872uCi_19Marc2014_250319_run3
2+
time.start=2025/03/19 09:47:46.724-0400
3+
time.stop=2025/03/19 09:53:05.651-0400
4+
time.real=00:05:18
5+
board.0-14-292.readout.rate=51.149 kb/s
6+
board.0-14-292.4.rejections.singles=0.0
7+
board.0-14-292.4.rejections.pileup=0.0
8+
board.0-14-292.4.rejections.saturation=1301.87
9+
board.0-14-292.4.rejections.energy=0.0
10+
board.0-14-292.4.rejections.psd=0.0
11+
board.0-14-292.4.rejections.timedistribution=0.0
12+
board.0-14-292.4.throughput=2627.31
13+
board.0-14-292.4.icr=3059.24
14+
board.0-14-292.4.ocr=1293.91
15+
board.0-14-292.4.calibration.energy.c0=0.0
16+
board.0-14-292.4.calibration.energy.c1=1.0
17+
board.0-14-292.4.calibration.energy.c2=0.0
18+
board.0-14-292.4.calibration.energy.uom=keV
19+
board.0-14-292.5.rejections.singles=0.0
20+
board.0-14-292.5.rejections.pileup=0.0
21+
board.0-14-292.5.rejections.saturation=717.247
22+
board.0-14-292.5.rejections.energy=0.0
23+
board.0-14-292.5.rejections.psd=0.0
24+
board.0-14-292.5.rejections.timedistribution=0.0
25+
board.0-14-292.5.throughput=1694.65
26+
board.0-14-292.5.icr=1703.71
27+
board.0-14-292.5.ocr=984.476
28+
board.0-14-292.5.calibration.energy.c0=0.0
29+
board.0-14-292.5.calibration.energy.c1=1.0
30+
board.0-14-292.5.calibration.energy.c2=0.0
31+
board.0-14-292.5.calibration.energy.uom=keV

test/neutron_detection/test_compass.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,20 @@ def test_get_live_time_from_root(root_filename, channel, live_time, real_time):
277277
assert real_time_out == real_time
278278

279279

280-
def test_measurement_object_from_directory():
280+
@pytest.mark.parametrize("no_root", [True, False])
281+
def test_measurement_object_from_directory(no_root):
281282
"""
282283
Test the Measurement object creation from a directory.
283284
"""
284-
285-
test_directory = (
286-
Path(__file__).parent / "compass_test_data/complete_measurement/data"
287-
)
285+
if no_root:
286+
test_directory = (
287+
Path(__file__).parent
288+
/ "compass_test_data/complete_measurement_no_root/data"
289+
)
290+
else:
291+
test_directory = (
292+
Path(__file__).parent / "compass_test_data/complete_measurement/data"
293+
)
288294

289295
measurement = compass.Measurement.from_directory(test_directory, name="test")
290296

0 commit comments

Comments
 (0)