Beispiel #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)
Beispiel #2
0
 def testMultiFileReadMultiDetWeighted(self):
     data = self.reader.load(["test_data/ResnucInputTest_tab.lis", "test_data/ResnucInputTest2_tab.lis"])
     res = {"AlBa-1s": {"Isotope": [PQ.Isotope(75, 32, 0),
                                    PQ.Isotope(26, 13, 1)],
                        "Activity": [PQ.Activity(2.0663E+05, unc=0.99 * 2.0663E+05),
                                     PQ.Activity(2.2300E+10, unc=0.001845 * 2.2300E+10)]}}
     self.assertFalse(True, "To be implemented")
Beispiel #3
0
    def setUp(self):
        fH10 = open(
            join(_basedir, "../pyfluka/data/Activity_H10_conversion.p"), "r")
        self.H10 = pickle.load(fH10)
        fH10.close()

        fHp007 = open(
            join(_basedir, "../pyfluka/data/Activity_Hp007_conversion.p"), "r")
        self.Hp007 = pickle.load(fHp007)
        fHp007.close()

        fLE = open(join(_basedir, "../pyfluka/data/LEDB.p"), "r")
        self.LE = pickle.load(fLE)
        fLE.close()

        self.isotopeList = [
            PQ.Isotope(3, "H"),
            PQ.Isotope(44, "Sc", 1),
            PQ.Isotope(46, "Sc")
        ]
        self.H10Vals = [
            PQ.H10(1.000000E+12),
            PQ.H10(2.222222E+10),
            PQ.H10(3.344482E+09)
        ]
        self.Hp007Vals = [
            PQ.Hp007(1.000000E+09),
            PQ.Hp007(5.000000E+06),
            PQ.Hp007(1.000000E+06)
        ]
        self.LEVals = [
            PQ.ExemptionLimit(2.00E+005),
            PQ.ExemptionLimit(4.00E+003),
            PQ.ExemptionLimit(7.00E+003)
        ]
Beispiel #4
0
    def setUp(self):
        fLE = open(join(_basedir, "../pyfluka/data/LEDB.p"), "r")
        self.dLE = pickle.load(fLE)
        fLE.close()

        fH10 = open(
            join(_basedir, "../pyfluka/data/Activity_H10_conversion.p"), "r")
        self.dH10 = pickle.load(fH10)
        fH10.close()

        fHp007 = open(
            join(_basedir, "../pyfluka/data/Activity_Hp007_conversion.p"), "r")
        self.dHp007 = pickle.load(fHp007)
        fHp007.close()

        f_einh = open(join(_basedir, "../pyfluka/data/inhalation.p"), "r")
        self.d_einh = pickle.load(f_einh)
        f_einh.close()

        f_eing = open(join(_basedir, "../pyfluka/data/ingestion.p"), "r")
        self.d_eing = pickle.load(f_eing)
        f_eing.close()

        f_hl = open(join(_basedir, "../pyfluka/data/half_lifes.p"), "r")
        self.d_hl = pickle.load(f_hl)
        f_hl.close()

        self.test_isotopes = [
            PQ.Isotope(3, 1),
            PQ.Isotope(60, "Co"),
            PQ.Isotope(40, "K"),
            PQ.Isotope(137, "Cs")
        ]
 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.))
         }
     }
Beispiel #6
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)
Beispiel #7
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)
Beispiel #8
0
 def test_multi_file_merge_diff_isotopes(self):
     data = self.reader.load(["test_data/ResnucInputTest_tab.lis", "test_data/ResnucInputTest2_tab.lis"])
     res = {"AlBa-1s": {"Isotope": [PQ.Isotope(75, 32, 0),
                                    PQ.Isotope(-1, -1, -1),
                                    PQ.Isotope(26, 13, 1)],
                        "Activity": [PQ.Activity(2.0663E+05, unc=0.99 * 2.0663E+05),
                                     PQ.Activity(-1, unc= -1),
                                     PQ.Activity(2.2300E+10, unc=0.001845 * 2.2300E+10)]}}
     self.assertEqual(data, res)
Beispiel #9
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)
Beispiel #10
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)
Beispiel #11
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)
Beispiel #12
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.))
Beispiel #13
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)
Beispiel #14
0
 def setUp(self):
     self.decorator = Decorator(["EInh"])
     self.data = {
         "det1":
         OrderedDict([(PQ.Isotope(3, 1, 0), StoredData(PQ.Activity(10.,
                                                                   2.)))])
     }
Beispiel #15
0
 def test_comparison(self):
     res = {
         "det1":
         OrderedDict([(PQ.Isotope(3, 1, 0), StoredData(PQ.Activity(10.,
                                                                   2.)))])
     }
     self.assertEqual(self.singleElementData, res)
Beispiel #16
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)
Beispiel #17
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)
Beispiel #18
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)
 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_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)
 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_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)
Beispiel #25
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"])
Beispiel #26
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
Beispiel #27
0
__author__ = 'marcusmorgenstern'
__mail__ = ''

import pickle
import re

from pyfluka.utils import ureg

from pyfluka.utils import PhysicsQuantities as PQ

fIn = open("../data/StSV_Annex3.csv", "r")
eing_vals = {}

for line in fIn.readlines()[3:]:
    if not re.match("^[A-Z]", line):
        continue
    line = line.replace('\n', '')
    sl = line.split(',')
    eing_vals[PQ.Isotope(int(re.findall(r'\d+',
                                        sl[0])[0]), sl[0].split('-')[0],
                         1 if sl[0].endswith("m") else 0)] = PQ.EIng(
                             float(sl[2]), ureg.Sv / ureg.Bq)

fIn.close()
fOut = open("../data/ingestion.p", 'w')
pickle.dump(eing_vals, fOut)
fOut.close()
Beispiel #28
0
half_life_vals = {}

str_to_unit = {
    "s": ureg.second,
    "h": ureg.hour,
    "d": ureg.day,
    "m": ureg.minute,
    "y": ureg.year
}
rg = re.compile("\d+\.?\d*[eE]?[+-]?\d*")
for line in f_raw.readlines()[3:]:
    if not re.match("^[A-Z]", line):
        continue
    line = line.replace('\n', '')
    sl = line.split(' ')
    if "None" not in sl[-1]:
        time = PQ.Time(
            map(float, rg.findall(sl[-1]))[0], 0., str_to_unit[sl[-1][-1]])
    else:
        #stable isotope
        time = PQ.Time(-1., -1., ureg.year)
    half_life_vals[PQ.Isotope(int(re.findall(r'\d+',
                                             sl[0])[0]), sl[0].split('-')[0],
                              1 if sl[0].endswith("M") else 0)] = time

f_raw.close()

f_pickle = open("../data/half_lifes.p", 'w')
pickle.dump(half_life_vals, f_pickle)
f_pickle.close()
Beispiel #29
0
 def test_check_multiple_element_is_exisiting(self):
     self.singleElementData["det1"][PQ.Isotope(3, 1, 0)].append(
         PQ.AoverLE(10., 2.))
     self.assertTrue(self.singleElementData["det1"][PQ.Isotope(
         3, 1, 0)].has_quantity(["Activity", "AoverLE"]))
Beispiel #30
0
 def test_check_single_element_is_exisiting(self):
     self.assertTrue(self.singleElementData["det1"][PQ.Isotope(
         3, 1, 0)].has_quantity("Activity"))