-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdata_tests.py
274 lines (261 loc) · 12.2 KB
/
data_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# Copyright 2021 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
# Under the terms of Contract DE-NA0003525 with NTESS,
# the U.S. Government retains certain rights in this software.
"""This module tests the data module."""
import os
import tempfile
import unittest
from riid import (SAMPLESET_HDF_FILE_EXTENSION, SampleSet, get_dummy_seeds,
read_hdf)
from riid.data.labeling import label_to_index_element
from riid.data.sampleset import _write_hdf
class TestData(unittest.TestCase):
"""Test class for Data module."""
def setUp(self):
"""Test setup."""
pass
def _get_temp_ss_path(self):
default_temp_dir = tempfile._get_default_tempdir()
temp_file_name = next(tempfile._get_candidate_names())
return os.path.join(default_temp_dir, temp_file_name + SAMPLESET_HDF_FILE_EXTENSION)
def test_to_hdf_and_read_hdf(self):
"""Tests loading of SampleSets saved in hdf format."""
file_path = self._get_temp_ss_path()
sampleset = get_dummy_seeds()
_write_hdf(sampleset, file_path)
sampleset_out = read_hdf(file_path)
compare_samplesets(self, sampleset, sampleset_out)
os.remove(file_path)
def test_label_to_index_element(self):
RAD_SOURCES = {
"K40,100uC": ("K40", "NORM"),
"K40inCargo1": ("K40", "NORM"),
"K40inCargo2": ("K40", "NORM"),
"K40inCargo3": ("K40", "NORM"),
"K40inCargo4": ("K40", "NORM"),
"Ra226,100uC": ("Ra226", "NORM"),
"Ra226inCargo1": ("Ra226", "NORM"),
"Ra226inCargo2": ("Ra226", "NORM"),
"Ra226inCargo3": ("Ra226", "NORM"),
"Ra226inSilica1": ("Ra226", "NORM"),
"Ra226inSilica2": ("Ra226", "NORM"),
"Ra226,100uC {60,100}": ("Ra226", "NORM"),
"Th232,100uC": ("Th232", "NORM"),
"Th232inCargo1": ("Th232", "NORM"),
"Th232inCargo2": ("Th232", "NORM"),
"Th232inCargo3": ("Th232", "NORM"),
"Th232inSilica1": ("Th232", "NORM"),
"Th232inSilica2": ("Th232", "NORM"),
"Th232,100uC {60,100}": ("Th232", "NORM"),
"ThPlate": ("Th232", "NORM"),
"ThPlate+Thxray,10uC": ("Th232", "NORM"),
"fiestaware": ("U238", "SNM"),
"U232,100uC": ("U232", "SNM"),
"U232,100uC {10,10}": ("U232", "SNM"),
"U232,100uC {10,30}": ("U232", "SNM"),
"U232,100uC {13,50}": ("U232", "SNM"),
"U232,100uC {26,30}": ("U232", "SNM"),
"U232,100uC {26,60}": ("U232", "SNM"),
"U232inLeadAndPine": ("U232", "SNM"),
"U232inLeadAndFe": ("U232", "SNM"),
"U232inPineAndFe": ("U232", "SNM"),
"U232,100uC {82,30}": ("U232", "SNM"),
"1kgU233At1yr": ("U233", "SNM"),
"1kgU233InFeAt1yr": ("U233", "SNM"),
"1kgU233At50yr": ("U233", "SNM"),
"1kgU233InFeAt50yr": ("U233", "SNM"),
"1kgU235": ("U235", "SNM"),
"1kgU235inFe": ("U235", "SNM"),
"1kgU235inPine": ("U235", "SNM"),
"1kgU235inPineAndFe": ("U235", "SNM"),
"1gNp237,1kC": ("Np237", "SNM"),
"1kgNp237": ("Np237", "SNM"),
"Np237inFe1": ("Np237", "SNM"),
"Np237inFe4": ("Np237", "SNM"),
"Np237Shielded2": ("Np237", "SNM"),
"1KGU238": ("U238", "SNM"),
"1KGU238Clad": ("U238", "SNM"),
"1KGU238inPine": ("U238", "SNM"),
"1KGU238inPine2": ("U238", "SNM"),
"1KGU238inPine3": ("U238", "SNM"),
"1KGU238inFe": ("U238", "SNM"),
"1KGU238inPineAndFe": ("U238", "SNM"),
"1KGU238inW": ("U238", "SNM"),
"U238Fiesta": ("U238", "SNM"),
"Uxray,100uC": ("U238", "SNM"),
"DUOxide": ("U238", "SNM"),
"1gPu239": ("Pu239", "SNM"),
"1kgPu239": ("Pu239", "SNM"),
"1kgPu239,1C {40,4}": ("Pu239", "SNM"),
"1kgPu239inFe": ("Pu239", "SNM"),
"1kgPu239inPine": ("Pu239", "SNM"),
"1kgPu239InFeAndPine": ("Pu239", "SNM"),
"1kgPu239inW": ("Pu239", "SNM"),
"Pu238,100uC": ("Pu238", "SNM"),
"Pu238,100uC {10,5}": ("Pu238", "SNM"),
"Pu238,100uC {26,10}": ("Pu238", "SNM"),
"Am241,100uC": ("Am241", "Industrial"),
"Am241,100UC {13,10}": ("Am241", "Industrial"),
"Am241,100UC {13,30}": ("Am241", "Industrial"),
"Am241,100UC {26,5}": ("Am241", "Industrial"),
"Am241,100UC {26,20}": ("Am241", "Industrial"),
"Am241,100UC {26,50}": ("Am241", "Industrial"),
"Am241,100UC {50,2}": ("Am241", "Industrial"),
"Na22,100uC {10,10}": ("Na22", "Industrial"),
"Na22,100uC": ("Na22", "Industrial"),
"Na22,100uC {10,30}": ("Na22", "Industrial"),
"Na22,100uC {74,20}": ("Na22", "Industrial"),
"Co57,100uC {13,10}": ("Co57", "Industrial"),
"Co57,100uC": ("Co57", "Industrial"),
"Co60,100uC": ("Co60", "Industrial"),
"Co60,100uC {10,10}": ("Co60", "Industrial"),
"Co60,100uC {10,30}": ("Co60", "Industrial"),
"Co60,100uC {26,20}": ("Co60", "Industrial"),
"Co60,100uC {26,40}": ("Co60", "Industrial"),
"Co60,100uC {82,30}": ("Co60", "Industrial"),
"Co60,100uC {82,60}": ("Co60", "Industrial"),
"Y88,100uC": ("Y88", "Industrial"),
"Y88,100uC {10,50}": ("Y88", "Industrial"),
"Y88,100uC {26,30}": ("Y88", "Industrial"),
"Y88,100uC {80,50}": ("Y88", "Industrial"),
"Ba133,100uC": ("Ba133", "Industrial"),
"Ba133,100uC {10,20}": ("Ba133", "Industrial"),
"Ba133,100uC {26,10}": ("Ba133", "Industrial"),
"Ba133,100uC {26,30}": ("Ba133", "Industrial"),
"Ba133,100uC {74,20}": ("Ba133", "Industrial"),
"Ba133,100uC {50,30}": ("Ba133", "Industrial"),
"Cs137,100uC": ("Cs137", "Industrial"),
"Cs137,100uC {6,2}": ("Cs137", "Industrial"),
"Cs137,100uC {26,10}": ("Cs137", "Industrial"),
"Cs137,100uC {82,10}": ("Cs137", "Industrial"),
"Cs137,100uC {13,240;26,,}": ("Cs137", "Industrial"),
"Cs137,100uC {13,240;26,1}": ("Cs137", "Industrial"),
"Cs137InPine": ("Cs137", "Industrial"),
"Cs137InLead": ("Cs137", "Industrial"),
"Cs137InGradedShield1": ("Cs137", "Industrial"),
"Cs137InGradedShield2": ("Cs137", "Industrial"),
"Eu152,100uC": ("Eu152", "Industrial"),
"Eu152,100uC {10,10}": ("Eu152", "Industrial"),
"Eu152,100uC {10,30}": ("Eu152", "Industrial"),
"Eu152,100uC {30,50}": ("Eu152", "Industrial"),
"Eu152,100uC {74,20}": ("Eu152", "Industrial"),
"Eu154,100uC": ("Eu154", "Industrial"),
"Eu154,100uC {10,10}": ("Eu154", "Industrial"),
"Eu154,100uC {74,20}": ("Eu154", "Industrial"),
"Ho166m,100uC": ("Ho166m", "Industrial"),
"Ho166m,100uC {10,20}": ("Ho166m", "Industrial"),
"Ho166m,100uC {26,20}": ("Ho166m", "Industrial"),
"Ho166m,100uC {74,30}": ("Ho166m", "Industrial"),
"Ir192,100uC": ("Ir192", "Industrial"),
"Ir192,100uC {10,20}": ("Ir192", "Industrial"),
"Ir192,100uC {26,40}": ("Ir192", "Industrial"),
"Ir192,100uC {26,100}": ("Ir192", "Industrial"),
"Ir192,100uC {82,30}": ("Ir192", "Industrial"),
"Ir192,100uC {82,160}": ("Ir192", "Industrial"),
"Ir192Shielded1": ("Ir192", "Industrial"),
"Ir192Shielded2": ("Ir192", "Industrial"),
"Ir192Shielded3": ("Ir192", "Industrial"),
"Bi207,100uC": ("Bi207", "Industrial"),
"Bi207,100uC {10,30}": ("Bi207", "Industrial"),
"Bi207,100uC {26,10}": ("Bi207", "Industrial"),
"Cf249,100uC": ("Cf249", "Industrial"),
"Cs137,1mC": ("Cs137", "Industrial"),
"F18,100uC": ("F18", "Medical"),
"F18,100uC {10,20}": ("F18", "Medical"),
"F18,100uC {10,50}": ("F18", "Medical"),
"F18,100uC {26,30}": ("F18", "Medical"),
"Ga67,100UC": ("Ga67", "Medical"),
"Ga67,100UC {6,10}": ("Ga67", "Medical"),
"Ga67,100UC {6,20}": ("Ga67", "Medical"),
"Ga67,100UC {10,30}": ("Ga67", "Medical"),
"Ga67,100UC {50,16}": ("Ga67", "Medical"),
"Ga67,100UC {82,20}": ("Ga67", "Medical"),
"Mo99,100uC": ("Mo99", "Medical"),
"Mo99,100uC {26,20}": ("Mo99", "Medical"),
"Mo99,100uC {50,40}": ("Mo99", "Medical"),
"Tc99m,100uC": ("Tc99m", "Medical"),
"Tc99m,100uC {7,10}": ("Tc99m", "Medical"),
"Tc99m,100uC {10,20}": ("Tc99m", "Medical"),
"Tc99m,100uC {13,30}": ("Tc99m", "Medical"),
"Tc99m,100uC {26,30}": ("Tc99m", "Medical"),
"In111,100uC": ("In111", "Medical"),
"In111,100uC {10,20}": ("In111", "Medical"),
"In111,100uC {50,20}": ("In111", "Medical"),
"I123,100uC": ("I123", "Medical"),
"I123,100uC {10,30}": ("I123", "Medical"),
"I125,100uC": ("I125", "Medical"),
"I131,100uC": ("I131", "Medical"),
"I131,100uC {10,10}": ("I131", "Medical"),
"I131,100uC {10,30}": ("I131", "Medical"),
"I131,100uC {16,50}": ("I131", "Medical"),
"I131,100uC {20,20}": ("I131", "Medical"),
"I131,100uC {82,10}": ("I131", "Medical"),
"I131,100uC {10,20;50,5}": ("I131", "Medical"),
"Tl201,100uC": ("Tl201", "Medical"),
"Tl201,100uC {8,40}": ("Tl201", "Medical"),
"Tl201,100uC {10,10}": ("Tl201", "Medical"),
"Tl201,100uC {10,30}": ("Tl201", "Medical"),
"Tl201,100uC {26,10}": ("Tl201", "Medical"),
"Sr90InPoly1,1C": ("Sr90", "Industrial"),
"Sr90InPoly10,1C": ("Sr90", "Industrial"),
"Sr90InFe,1C": ("Sr90", "Industrial"),
"Sr90InSn,1C": ("Sr90", "Industrial"),
"pu239_1yr": ("Pu239", "SNM"),
"modified_berpball": ("Pu239", "SNM"),
"pu239_5yr": ("Pu239", "SNM"),
"pu239_10yr": ("Pu239", "SNM"),
"pu239_25yr": ("Pu239", "SNM"),
"pu239_50yr": ("Pu239", "SNM"),
"1gPuWG_0.5yr,3{an=10,ad=5}": ("Pu239", "SNM"),
"1kg HEU + 800uCi Cs137": ("U235", "SNM"),
"WGPu + Cs137": ("Pu239", "SNM"),
"10 yr WGPu in Fe": ("Pu239", "SNM")
}
for seed, (isotope, category) in RAD_SOURCES.items():
actual_category, actual_isotope, _ = label_to_index_element(
seed,
label_level="Seed"
)
msg = f"{isotope} ({category}) != {actual_isotope} ({actual_category})"
self.assertEqual(isotope, actual_isotope, msg)
self.assertEqual(category, actual_category, msg)
def compare_samplesets(unit_test, ss1: SampleSet, ss2: SampleSet):
""" Compares two SampleSets.
Extra data, info, predictions, and even sources can all be lost
in the following conversion: SS -> PCF -> SS.
However, no information should be lost in the following
conversion: PCF -> SS -> PCF
"""
unit_test.assertEqual(
ss1.measured_or_synthetic,
ss2.measured_or_synthetic,
"Measured or synthetic not equal"
)
unit_test.assertEqual(
ss1.detector_info,
ss2.detector_info,
"Detector info not equal"
)
unit_test.assertEqual(
ss1.synthesis_info,
ss2.synthesis_info,
"Synthesis info not equal"
)
unit_test.assertTrue(
ss1.spectra.equals(ss2.spectra),
"Spectra are not equal"
)
unit_test.assertTrue(
ss1.sources.equals(ss2.sources),
"Sources are not equal"
)
unit_test.assertTrue(
ss1.info.equals(ss2.info),
"Sample info is not equal"
)
unit_test.assertTrue(
ss1.prediction_probas.equals(ss2.prediction_probas),
"Predictions are not equal"
)
if __name__ == "__main__":
unittest.main()