Ejemplo n.º 1
0
 def _validate_comparison_input(self, other):
     try:
         if not self.val.to_base_units().units == other.val.to_base_units(
         ).units:
             raise IllegalArgumentError(
                 "Request comparison for different quantities: " +
                 str(self.val) + " and " + str(other.val))
     except AttributeError:
         if self.val.units != ureg.dimensionless.units or not isinstance(
                 other, Number):
             raise IllegalArgumentError(
                 "Request comparison for different quantities: " +
                 str(self.val) + " and " + str(other))
Ejemplo n.º 2
0
 def __add__(self, other):
     if isinstance(other, Number):
         if other == 0.:
             return deepcopy(self)
         else:
             raise IllegalArgumentError("Invalid request for addition of " +
                                        str(self) + " and " + str(other))
     if not type(self) == type(other):
         raise IllegalArgumentError("Invalid request for addition of " +
                                    str(self) + " and " + str(other))
     val = self.val + other.val
     unc = sqrt(pow(self.unc, 2) + pow(other.unc, 2))
     assert (val.units == unc.units)
     return self.__class__(val, unc)
Ejemplo n.º 3
0
def _validate(config_dict):
    """
    Validates configuration w.r.t required information, i.e. plugins have to be defined, and checks for compliance
    of data structure
    :param config_dict (dict): parsed configuration dictionary
    :return:

    Raises:
        IllegealArgumentError: if any validation check fails
    """
    if 'plugins' not in config_dict:
        raise IllegalArgumentError("No plugins defined.")
    if not isinstance(config_dict['plugins'], OrderedDict):
        raise IllegalArgumentError(
            "Plugins are required to be dictionaries, but " +
            str(type(config_dict['plugins'])) + " given.")
Ejemplo n.º 4
0
 def __init__(self, **kwargs):
     if "irr_time" not in kwargs or "cool_time" not in kwargs:
         raise IllegalArgumentError(
             "Unable to instantiate TimeEvolution. Either irr_time or cool_time missing."
         )
     self.cool_time = self._parse_config(kwargs.pop('cool_time'))
     self.irr_time = self._parse_config(kwargs.pop('irr_time'))
Ejemplo n.º 5
0
 def __init__(self, config):
     if 'cols' not in config or not len(config['cols']):
         raise InvalidInputError(
             "No columns defined for table. Nothing to do, so giving up.")
     self.cols = config['cols']
     self.tables = OrderedDict()
     self.output_dir = "/afs/cern.ch/work/m/morgens/flair++/examples/"
     self.store_multiple_output_files = False
     if 'outputdir' in config:
         self.output_dir = config['outputdir']
         if not os.path.exists(self.output_dir):
             raise IllegalArgumentError("Output directory " +
                                        self.output_dir +
                                        " does not exist.")
     if 'multipleOutputFiles' in config:
         self.store_multiple_output_files = True
     self.format = 'latex'
     if 'format' in config:
         allowed_format_options = map(str, tabulate.tabulate_formats)
         if config['format'] not in allowed_format_options:
             print 'Invalid formatting option %s. Set to plain' % config[
                 'format']
             self.format = 'plain'
         else:
             self.format = config['format']
     self.__class__._patch_latex_escapes()
Ejemplo n.º 6
0
 def invoke(self, data):
     """
     Entry point for calculator
     :param data:
     :return:
     """
     for det in data.keys():
         try:
             mass = _global_data[det]["Mass"]
         except:
             raise IllegalArgumentError("Requested mass for detector " + det + ", but not available.")
         self._calc(data[det], mass)
Ejemplo n.º 7
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.º 8
0
 def find_builtin(self, builtin):
     from pyfluka.reader import _dh
     func = None
     try:
         func = getattr(_dh, builtin)
     except AttributeError:
         pass
     try:
         func = getattr(_dh, "_" + builtin)
     except AttributeError:
         pass
     if not func:
         raise IllegalArgumentError("Requested builtin " + builtin + " could not be found.")
     return func
Ejemplo n.º 9
0
 def load(self, files):
     if isinstance(files, list):
         merged_data = None
         for file_name in files:
             weight = 1.
             if self.weights:
                 weight = self.weights.pop(0)
             data = self._load(file_name, weight)
             if merged_data:
                 self.__class__._merge(merged_data, data)
             else:
                 merged_data = data
         return merged_data
     elif isinstance(files, str):
         weight = 1.
         if self.weights:
             weight = self.weights.pop(0)
         return self._load(files, weight)
     else:
         raise IllegalArgumentError(
             "Received unsupported type for input files: " +
             str(type(files)))