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)
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)
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)
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()))))
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]))
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 _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]))
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_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)
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()
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()))))
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 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()
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_global_data_single_pair(self): _global_data.add("NoOfProtons", 10.) self.assertEqual(_global_data["NoOfProtons"], 10.)
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))
def invoke(self, data): for det in data.keys(): total_activity = self._calc(data[det].values()) _global_data.add(det, "TotalActivity", total_activity)
def test_global_data_single_pair(self): _global_data.add("NoOfProtons", 10.) self.assertEqual(_global_data["NoOfProtons"], 10.)
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))