示例#1
0
 def testTabLisRead(self):
     res = {"AlBa-1s": OrderedDict([(PQ.Isotope(75, 32, 0),
                                     StoredData(PQ.Activity(2.0663E+05, unc=0.99 * 2.0663E+05))),
                                    (PQ.Isotope(26, 13, 1),
                                     StoredData(PQ.Activity(2.2300E+10, unc=0.001845 * 2.2300E+10)))])}
     data = self.reader.load(join(_basedir, "test_data/ResnucInputTest_tab.lis"))
     self.assertEqual(data, res)
示例#2
0
 def test_tab_lis_read_custom(self):
     reader = RR(quantity="DoseRate")
     res = {"AlBa-1s": OrderedDict([(PQ.Isotope(75, 32, 0),
                                     StoredData(PQ.DoseRate(2.0663E+05, unc=0.99 * 2.0663E+05))),
                                    (PQ.Isotope(26, 13, 1),
                                     StoredData(PQ.DoseRate(2.2300E+10, unc=0.001845 * 2.2300E+10)))])}
     data = reader.load(join(_basedir, join(_basedir, "test_data/ResnucInputTest_tab.lis")))
     self.assertEqual(data, res)
示例#3
0
 def setUp(self):
     self.sum_op = SummationOperator("Activity")
     self.single_det_data = {
         "det1": {
             PQ.Isotope(3, 1, 0): StoredData(PQ.Activity(10.)),
             PQ.Isotope(3, 2, 0): StoredData(PQ.Activity(15.))
         }
     }
示例#4
0
 def testMultiFileReadSingleDet(self):
     data = self.reader.load([join(_basedir, "test_data/ResnucInputTest_tab.lis"),
                              join(_basedir, "test_data/ResnucInputTest_tab.lis")])
     res = {"AlBa-1s": OrderedDict([(PQ.Isotope(75, 32, 0),
                                     StoredData(PQ.Activity(2. * 2.0663E+05, unc=0.99 * sqrt(2.) * 2.0663E+05))),
                                    (PQ.Isotope(26, 13, 1),
                                     StoredData(PQ.Activity(2. * 2.2300E+10,
                                                            unc=0.001845 * sqrt(2.) * 2.2300E+10)))])}
     self.assertEqual(data, res)
示例#5
0
 def testTotalActivityCalculationDiffUnits(self):
     calculator = TotalActivityCalculator()
     data = {
         "det1":
         OrderedDict([(PQ.Isotope(3, 1),
                       StoredData(PQ.Activity(10000., 10000., ureg.mBq))),
                      (PQ.Isotope(2, 1),
                       StoredData(PQ.Activity(30., 10., ureg.Bq)))])
     }
     calculator.invoke(data)
     self.assertEqual(_global_data["det1"]["TotalActivity"],
                      PQ.Activity(40., sqrt(200.)))
示例#6
0
 def test_multi_file_read_weighted(self):
     sf = 1.5
     self.reader.weights = [0.8, 0.7]
     data = self.reader.load([join(_basedir, "test_data/ResnucInputTest_tab.lis"),
                              join(_basedir, "test_data/ResnucInputTest_tab.lis")])
     res = {"AlBa-1s": OrderedDict([(PQ.Isotope(75, 32, 0),
                                     StoredData(PQ.Activity(sf * 2.0663E+05, unc= sqrt(pow(0.8, 2) + pow(0.7, 2)) *
                                                                                       0.99 * 2.0663E+05))),
                                    (PQ.Isotope(26, 13, 1),
                                     StoredData(PQ.Activity(sf * 2.2300E+10,
                                                            unc=sqrt(pow(0.8, 2) + pow(0.7, 2)) *
                                                                0.001845 * 2.2300E+10)))])}
     self.assertAlmostEqual(data["AlBa-1s"][PQ.Isotope(26, 13, 1)]["Activity"],
                            res["AlBa-1s"][PQ.Isotope(26, 13, 1)]["Activity"])
     self.assertAlmostEqual(data["AlBa-1s"][PQ.Isotope(75, 32, 0)]["Activity"],
                            res["AlBa-1s"][PQ.Isotope(75, 32, 0)]["Activity"])
示例#7
0
 def setUp(self):
     self.decorator = Decorator(["EInh"])
     self.data = {
         "det1":
         OrderedDict([(PQ.Isotope(3, 1, 0), StoredData(PQ.Activity(10.,
                                                                   2.)))])
     }
示例#8
0
 def test_comparison_unequal_different_unit(self):
     res = {
         "det1":
         OrderedDict([(PQ.Isotope(3, 1, 0),
                       StoredData(PQ.Activity(10., 2., ureg.kBq)))])
     }
     self.assertNotEqual(self.singleElementData, res)
示例#9
0
 def setUp(self):
     self.tabConfig = {"cols": ["Isotope", "Activity"]}
     self.data = {
         "det1":
         OrderedDict([(PQ.Isotope(3, "H"),
                       StoredData(PQ.Activity(10.00101010101)))])
     }
     self.dataMultiDet = {
         "det1":
         OrderedDict([(PQ.Isotope(3, "H"),
                       StoredData(PQ.Activity(10.00101010101)))]),
         "det2":
         OrderedDict([(PQ.Isotope(3, "H"),
                       StoredData(PQ.Activity(100.00101010101)))])
     }
     self.tm = TM(self.tabConfig)
示例#10
0
 def test_comparison(self):
     res = {
         "det1":
         OrderedDict([(PQ.Isotope(3, 1, 0), StoredData(PQ.Activity(10.,
                                                                   2.)))])
     }
     self.assertEqual(self.singleElementData, res)
示例#11
0
 def test_invoke(self):
     self.decorator.invoke(self.data)
     res = {
         "det1":
         OrderedDict([(PQ.Isotope(3, 1, 0),
                       StoredData(PQ.Activity(10., 2.),
                                  PQ.EInh(4.10E-011)))])
     }
     self.assertEqual(self.data, res)
示例#12
0
    def setUp(self):
        _global_data.add("det1", "Mass", PQ.Mass(10, ureg.kg))
        self.dataIsotopeSpecificAct = {
            "det1":
            OrderedDict([(PQ.Isotope(3, 1),
                          StoredData(PQ.SpecificActivity(10.)))])
        }
        self.dataIsotopeAct = {
            "det1":
            OrderedDict([(PQ.Isotope(3, 1), StoredData(PQ.Activity(10.)))])
        }
        self.dataIsotopeMultiAct = {
            "det1":
            OrderedDict([(PQ.Isotope(3, 1), StoredData(PQ.Activity(10.))),
                         (PQ.Isotope(2, 1), StoredData(PQ.Activity(30.)))])
        }

        self.AoverLECalculator = AoverLECalculator()
示例#13
0
 def test_add_multiple_elements_not_existing(self):
     res = {
         "det1":
         OrderedDict([(PQ.Isotope(3, 1, 0),
                       StoredData(PQ.Activity(10., 2.), PQ.AoverLE(10., 2.),
                                  PQ.DoseRate(20., 3.)))])
     }
     self.singleElementData["det1"][PQ.Isotope(3, 1, 0)].append(
         PQ.AoverLE(10., 2.), PQ.DoseRate(20., 3.))
     self.assertEqual(self.singleElementData, res)
示例#14
0
 def test_named_store_add(self):
     res = {
         "det1":
         OrderedDict([(PQ.Isotope(3, 1, 0),
                       StoredData(PQ.Activity(10., 2.),
                                  ScaledActivity=PQ.Activity(50., 2.)))])
     }
     self.singleElementData["det1"][PQ.Isotope(
         3, 1, 0)].append(ScaledActivity=PQ.Activity(50., 2.))
     self.assertEqual(self.singleElementData, res)
示例#15
0
 def test_add_single_element_to_existing(self):
     res = {
         "det1":
         OrderedDict([(PQ.Isotope(3, 1,
                                  0), StoredData(PQ.Activity(20.,
                                                             sqrt(8.))))])
     }
     self.singleElementData["det1"][PQ.Isotope(3, 1, 0)].append(
         PQ.Activity(10., 2.))
     self.assertEqual(self.singleElementData, res)
 def test_scalar_const_multiplication(self):
     mul_op = MultiplicationOperator(**self.config_scalar_const)
     mul_op.invoke(self.dataActivity)
     res = {
         "det1":
         OrderedDict([(PQ.Isotope(3, 1, 0),
                       StoredData(PQ.Activity(10., 2.),
                                  ScaledActivity=PQ.Activity(50., 2.)))])
     }
     self.assertEqual(self.dataActivity, res)
示例#17
0
 def test_time_evolution_non_negative(self):
     isotope = PQ.Isotope(29, "Si")
     data = {
         "det1":
         OrderedDict([(isotope, StoredData(PQ.ProductionYield(10., 2.)))])
     }
     config = {"irr_time": "1 m", "cool_time": "10 y"}
     time_evo = TimeEvolution(**config)
     time_evo.invoke(data)
     self.assertTrue(data["det1"][PQ.Isotope(29, "Si", 0)]
                     ["ProductionYield"] >= PQ.ProductionYield(0.))
示例#18
0
 def test_time_evolution_simple(self):
     isotope = PQ.Isotope(3, 1, 0)
     data = {
         "det1":
         OrderedDict([(isotope, StoredData(PQ.ProductionYield(10., 2.)))])
     }
     time_evo = TimeEvolution(**self.config)
     time_evo.invoke(data)
     res = (1 - exp(-log(2) * PQ.Time(1, unit=ureg.year) / _dh._hl[isotope])) \
           * exp(-log(2) * PQ.Time(1, unit=ureg.year)/ _dh._hl[isotope]) * PQ.ProductionYield(10., 2.)
     self.assertEqual(data["det1"][PQ.Isotope(3, 1, 0)]["ProductionYield"],
                      res)
 def test_dict_multiplication_global_data(self):
     d = {
         "type": "scalar",
         "multiplier": "ProductionYield",
         "multiplicand": "global:NoOfPrimaries",
         "product": "Activity"
     }
     _global_data.add("NoOfPrimaries", 10.)
     data = {
         "det1":
         OrderedDict([(PQ.Isotope(3, 1, 0),
                       StoredData(PQ.ProductionYield(10., 0.)))])
     }
     mul_op = MultiplicationOperator(**d)
     mul_op.invoke(data)
     res = {
         "det1":
         OrderedDict([(PQ.Isotope(3, 1, 0),
                       StoredData(PQ.ProductionYield(10., 0.),
                                  PQ.Activity(100., 0.)))])
     }
     self.assertEqual(data, res)
 def test_dict_builtin_dh_multiplication(self):
     mul_op = MultiplicationOperator(**self.config_dict_builtin)
     mul_op.invoke(self.dataActivity)
     res = {
         "det1":
         OrderedDict([
             (PQ.Isotope(3, 1, 0),
              StoredData(PQ.Activity(10., 2.),
                         InhalationDose=PQ.Dose(10. * 4.10E-011, -1.,
                                                ureg.Sv)))
         ])
     }
     self.assertEqual(self.dataActivity, res)
 def setUp(self):
     self.dataActivity = {
         "det1":
         OrderedDict([(PQ.Isotope(3, 1, 0), StoredData(PQ.Activity(10.,
                                                                   2.)))])
     }
     self.dataActivityEinh = {
         "det1":
         OrderedDict([(PQ.Isotope(3, 1, 0),
                       StoredData(PQ.Activity(10., 2.),
                                  inhalationcoeff=PQ.EInh(10.)))])
     }
     self.config_scalar_const = d = {
         "type": "scalar",
         "multiplier": "Activity",
         "multiplicand": "const:5",
         "product": "ScaledActivity:Activity"
     }
     self.config_dict_builtin = d = {
         "type": "dict",
         "multiplier": "Activity",
         "multiplicand": "builtin:einh",
         "product": "InhalationDose:Dose"
     }
 def test_dict_multiplication_det(self):
     d = {
         "type": "dict",
         "multiplier": "Activity",
         "multiplicand": "global:mass",
         "product": "SpecificActivity"
     }
     _global_data.add("det1", "mass", PQ.Mass(10., "kg"))
     mul_op = MultiplicationOperator(**d)
     data = {
         "det1":
         OrderedDict([(PQ.Isotope(3, 1,
                                  0), StoredData(PQ.Activity(100., 0.)))])
     }
     mul_op.invoke(data)
     res = PQ.SpecificActivity(10.)
     self.assertEqual(data["det1"][PQ.Isotope(3, 1, 0)]["SpecificActivity"],
                      res)
 def test_dict_multiplication_stored_quantity(self):
     d = {
         "type": "dict",
         "multiplier": "Activity",
         "multiplicand": "inhalationcoeff",
         "product": "InhalationDose:Dose"
     }
     mul_op = MultiplicationOperator(**d)
     mul_op.invoke(self.dataActivityEinh)
     res = {
         "det1":
         OrderedDict([
             (PQ.Isotope(3, 1, 0),
              StoredData(PQ.Activity(10., 2.),
                         inhalationcoeff=PQ.EInh(10.),
                         InhalationDose=PQ.Dose(100., -1., ureg.Sv)))
         ])
     }
     self.assertEqual(self.dataActivityEinh, res)
示例#24
0
 def test_named_store_constructor(self):
     inp = StoredData(PQ.Activity(10., 2.),
                      ScaledActivity=PQ.Activity(50., 2.))
     self.assertEqual(inp["ScaledActivity"], PQ.Activity(50., 2.))
示例#25
0
 def test_set_item(self):
     data = StoredData(PQ.Activity(10., 2.))
     data["Activity"] = PQ.Activity(20., 2.)
     res = PQ.Activity(20., 2.)
     self.assertEqual(data["Activity"], res)
示例#26
0
 def test_access_none(self):
     data = StoredData(PQ.Activity(10., 2.))
     self.assertEqual(data["foo"], None)
示例#27
0
 def test_AoverLE_wrong_input(self):
     self.assertRaises(ValueError, self.AoverLECalculator.invoke, {
         "det1":
         OrderedDict([(PQ.Isotope(3, 1), StoredData(PQ.Activity(1.)))])
     })
示例#28
0
 def setUp(self):
     self.singleElementData = {
         "det1":
         OrderedDict([(PQ.Isotope(3, 1, 0), StoredData(PQ.Activity(10.,
                                                                   2.)))])
     }
示例#29
0
    def _load(self, filename, weight):
        resnucl_data_dict = {}
        first_line_of_detector = False
        data_section = False
        isomere_section = False
        current_detector_name = None
        data = OrderedDict()

        for (i, line) in enumerate(file(filename)):
            if line.find("Detector n:") > 0:
                first_line_of_detector = True
                data_section = False
                isomere_section = False
            elif line.find("A/Z Isotopes:") > 0:
                first_line_of_detector = False
                data_section = True
                isomere_section = False
            elif line.find("A/Z/m Isomers:") > 0:
                first_line_of_detector = False
                data_section = False
                isomere_section = True
            elif first_line_of_detector:
                if current_detector_name is not None:
                    resnucl_data_dict[current_detector_name] = copy.copy(data)
                    current_detector_name = None
                    data = {}
                current_detector_name = line.strip()
                first_line_of_detector = False
            elif data_section:
                split_line = line.split()
                A = split_line[0]
                Z = int(split_line[1])
                value = weight * float(split_line[2])
                error_percent = float(split_line[3])
                if value > 0.:
                    try:
                        data[PQ.Isotope(A, Z, 0)].append(
                            self.pq(value, unc=value * error_percent / 100.))
                    except KeyError:
                        data[PQ.Isotope(A, Z, 0)] = StoredData(
                            self.pq(value, unc=value * error_percent / 100.))
            elif isomere_section:
                split_line = line.split()
                if not len(split_line):
                    continue
                A = split_line[0]
                Z = int(split_line[1])
                iso = int(split_line[2])
                value = weight * float(split_line[3])
                error_percent = float(split_line[4])
                if value > 0.:
                    try:
                        data[PQ.Isotope(A, Z, iso)].append(
                            self.pq(value, unc=value * error_percent / 100.))
                    except KeyError:
                        data[PQ.Isotope(A, Z, iso)] = StoredData(
                            self.pq(value, unc=value * error_percent / 100.))

        if current_detector_name is not None:
            resnucl_data_dict[current_detector_name] = copy.copy(data)

        return resnucl_data_dict
示例#30
0
 def setUp(self):
     self.config = {"quantity": "Activity", "threshold": 0.01}
     self.filter = Filter(**self.config)
     self.data = {"det1": {PQ.Isotope(3, 1, 0): StoredData(PQ.Activity(10.)),
                           PQ.Isotope(4, 2, 0): StoredData(PQ.Activity(2.)),
                           PQ.Isotope(22, 11, 0): StoredData(PQ.Activity(5.))}}