Ejemplo n.º 1
0
 def test_global_data_equal_op(self):
     from collections import defaultdict
     _global_data.data = defaultdict(dict)
     _global_data.add("NoOfProtons", 10)
     _global_data.add("det1", "TotalActivity", PQ.Activity(10., 2.))
     res = {"NoOfProtons": 10, "det1": {"TotalActivity": PQ.Activity(10., 2.)}}
     self.assertEqual(_global_data, res)
Ejemplo n.º 2
0
def _set_global_data(config):
    for k, v in config.iteritems():
        try:
            tmp = v.split(":")
            if len(tmp) == 2:
                v = __builtins__[tmp[0]](tmp[1])
        except AttributeError:
            pass
        _global_data.add(k, v)
Ejemplo n.º 3
0
def _set_global_data(config):
    for k, v in config.iteritems():
        try:
            tmp = v.split(":")
            if len(tmp) == 2:
                v = __builtins__[tmp[0]](tmp[1])
        except AttributeError:
            pass
        _global_data.add(k, v)
Ejemplo n.º 4
0
    def invoke(self, data):
        """
        Performing calculation

        :param dict data: data dictionary
        :return:
        """
        for det, values in data.items():
            if not values.values()[0].has_quantity(self.quantity):
                raise IllegalArgumentError("Request to sum " + self.quantity + " which is not stored.")
            _global_data.add(det, self.stored_quantity, sum(list(map(lambda e: e[self.quantity], values.values()))))
Ejemplo n.º 5
0
def _transform_det_info(config):
    """
    Transform parsed detector information
    :param config (dict): parsed configuration dictionary
    :return:
    """
    for det in config.keys():
        for quantity, val in config[det].items():
            if quantity.lower() == 'mass':
                info = val.split(' ')
                _global_data.add(det, quantity, PQ.Mass(float(info[0]), info[1]))
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
def _transform_det_info(config):
    """
    Transform parsed detector information
    :param config (dict): parsed configuration dictionary
    :return:
    """
    for det in config.keys():
        for quantity, val in config[det].items():
            if quantity.lower() == 'mass':
                info = val.split(' ')
                _global_data.add(det, quantity,
                                 PQ.Mass(float(info[0]), info[1]))
Ejemplo n.º 8
0
 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)
Ejemplo n.º 9
0
 def test_global_data_equal_op(self):
     from collections import defaultdict
     _global_data.data = defaultdict(dict)
     _global_data.add("NoOfProtons", 10)
     _global_data.add("det1", "TotalActivity", PQ.Activity(10., 2.))
     res = {
         "NoOfProtons": 10,
         "det1": {
             "TotalActivity": PQ.Activity(10., 2.)
         }
     }
     self.assertEqual(_global_data, res)
Ejemplo n.º 10
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()
Ejemplo n.º 11
0
    def invoke(self, data):
        """
        Performing calculation

        :param dict data: data dictionary
        :return:
        """
        for det, values in data.items():
            if not values.values()[0].has_quantity(self.quantity):
                raise IllegalArgumentError("Request to sum " + self.quantity +
                                           " which is not stored.")
            _global_data.add(
                det, self.stored_quantity,
                sum(list(map(lambda e: e[self.quantity], values.values()))))
Ejemplo n.º 12
0
 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)
Ejemplo n.º 13
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()
Ejemplo n.º 14
0
 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)
Ejemplo n.º 15
0
 def test_global_data_single_pair(self):
     _global_data.add("NoOfProtons", 10.)
     self.assertEqual(_global_data["NoOfProtons"], 10.)
Ejemplo n.º 16
0
 def test_global_data_nested(self):
     _global_data.add("det1", "Mass", PQ.Mass(10, ureg.kg))
     self.assertEqual(_global_data["det1"]["Mass"], PQ.Mass(10, ureg.kg))
Ejemplo n.º 17
0
 def invoke(self, data):
     for det in data.keys():
         total_activity = self._calc(data[det].values())
         _global_data.add(det, "TotalActivity", total_activity)
Ejemplo n.º 18
0
 def test_global_data_single_pair(self):
     _global_data.add("NoOfProtons", 10.)
     self.assertEqual(_global_data["NoOfProtons"], 10.)
Ejemplo n.º 19
0
 def test_global_data_nested(self):
     _global_data.add("det1", "Mass", PQ.Mass(10, ureg.kg))
     self.assertEqual(_global_data["det1"]["Mass"], PQ.Mass(10, ureg.kg))