Ejemplo n.º 1
0
        def get_entry(header_name):
            column_index = index_containing_substring(column_headers, header_name)
            if column_index != -1:
                item = strings[column_index]
                if is_float(item):
                    return get_float(item)

            return 0.0
Ejemplo n.º 2
0
        def get_entry(header_name):
            column_index = index_containing_substring(column_headers,
                                                      header_name)
            if column_index != -1:
                item = strings[column_index]
                if is_float(item):
                    return get_float(item)

            return 0.0
Ejemplo n.º 3
0
    def _deserialize(self, f):
        """
            The deserialization method
            f: file object
            
            Format is:
            
            e1
            e2
            ...
            en+1
            
            v1
            v2
            ...
            vn
            1.0
            name
        """
        self.reset()

        lines = f.readlines()
        # last two lines are the normalisation and the name
        self.name = str(lines[-1])
        self.norm = get_float(lines[-2])

        found_values = False
        reversed_values = []
        reversed_bounds = []
        for l in lines[:-2]:
            # find the space seperator to indicate flux values not boundaries
            if not l.split():
                found_values = True
            for e in l.split():
                if is_float(e):
                    if found_values:
                        reversed_values.append(get_float(e))
                    else:
                        reversed_bounds.append(get_float(e))
                else:
                    raise PypactDeserializeException(
                        "Entry {} in line {} is not a float.".format(e, l))

        self.values = list(reversed(reversed_values))
        self._setFromReversedBoundaries(reversed_bounds)
Ejemplo n.º 4
0
    def _deserialize(self, f):
        """
            The deserialization method
            f: file object
            
            Format is:
            
            e1
            e2
            ...
            en+1
            
            v1
            v2
            ...
            vn
            1.0
            name
        """
        self.reset()
        
        lines = f.readlines()
        # last two lines are the normalisation and the name
        self.name = str(lines[-1])
        self.norm =  get_float(lines[-2])

        found_values = False
        reversed_values = []
        reversed_bounds = []
        for l in lines[:-2]:
            # find the space seperator to indicate flux values not boundaries
            if not l.split():
                found_values = True
            for e in l.split():
                if is_float(e):
                    if found_values:
                        reversed_values.append(get_float(e))
                    else:
                        reversed_bounds.append(get_float(e))
                else:
                    raise PypactDeserializeException("Entry {} in line {} is not a float.".format(e, l))

        self.values = list(reversed(reversed_values))
        self._setFromReversedBoundaries(reversed_bounds)
Ejemplo n.º 5
0
    def _deserialize(self, f):
        """
            The deserialization method
            f: file object
            
            NOTE: The values are in reverse order
            
            Format is:
            
            v1
            v2
            ...
            vn
            1.0
            name
        """
        self.reset()

        lines = f.readlines()
        # last two lines are the normalisation and the name
        self.name = str(lines[-1])
        self.norm = get_float(lines[-2])

        reversed_values = []
        for l in lines[:-2]:
            for e in l.split():
                if is_float(e):
                    reversed_values.append(get_float(e))
                else:
                    raise PypactDeserializeException(
                        "Entry {} in line {} is not a float.".format(e, l))

        group = len(reversed_values)
        if group not in ALL_GROUPS:
            raise PypactDeserializeException(
                "Group structure {} not known to pypact.".format(group))

        self.values = list(reversed(reversed_values))
        self._setFromReversedBoundaries(ALL_GROUPS[group])
Ejemplo n.º 6
0
def first_value_from_line(line, linetag, ignoretags=[]):
    """

    :param line: The string representing a line
    :param linetag: The tag to find in the line
    :param ignoretags: The list of strings to ignore
    :return: The first value, float, after the tag. Returns NaN if no value found.

    """
    strings = strings_from_line(line, linetag, ignoretags)

    nan = 0.0
    if not strings:
        return nan

    for s in strings:
        # strip off any common tags around numbers
        s = s.replace(',', '').replace('*', '')
        if is_float(s):
            return get_float(s)

    return nan
Ejemplo n.º 7
0
def first_value_from_line(line, linetag, ignoretags=[]):
    """

    :param line: The string representing a line
    :param linetag: The tag to find in the line
    :param ignoretags: The list of strings to ignore
    :return: The first value, float, after the tag. Returns NaN if no value found.

    """
    strings = strings_from_line(line, linetag, ignoretags)

    nan = 0.0
    if not strings:
        return nan

    for s in strings:
        # strip off any common tags around numbers
        s = s.replace(',', '').replace('*', '')
        if is_float(s):
            return get_float(s)

    return nan
Ejemplo n.º 8
0
    def _deserialize(self, f):
        """
            The deserialization method
            f: file object
            
            NOTE: The values are in reverse order
            
            Format is:
            
            v1
            v2
            ...
            vn
            1.0
            name
        """
        self.reset()
        
        lines = f.readlines()
        # last two lines are the normalisation and the name
        self.name = str(lines[-1])
        self.norm = get_float(lines[-2])

        reversed_values = []
        for l in lines[:-2]:
            for e in l.split():
                if is_float(e):
                    reversed_values.append(get_float(e))
                else:
                    raise PypactDeserializeException("Entry {} in line {} is not a float.".format(e, l))

        group = len(reversed_values)
        if group not in ALL_GROUPS:
            raise PypactDeserializeException("Group structure {} not known to pypact.".format(group))

        self.values = list(reversed(reversed_values))
        self._setFromReversedBoundaries(ALL_GROUPS[group])
Ejemplo n.º 9
0
 def test_is_float(self):
     self.assertEqual(is_float(""), False)
     self.assertEqual(is_float("-0.000E+00"), True)
     self.assertEqual(is_float("1234567"), True)
     self.assertEqual(is_float("NaN"), True)
     self.assertEqual(is_float("NaNananana BATMAN"), False)
     self.assertEqual(is_float("123.456"), True)
     self.assertEqual(is_float("123.E4"), True)
     self.assertEqual(is_float(".1"), True)
     self.assertEqual(is_float("1,234"), False)
     self.assertEqual(is_float("NULL"), False)
     self.assertEqual(is_float(",1"), False)
     self.assertEqual(is_float("123.EE4"), False)
     self.assertEqual(is_float("6.523537535629999e-07"), True)
     self.assertEqual(is_float("6e777777"), True)
     self.assertEqual(is_float("iNF"), True)
     self.assertEqual(is_float("-iNF"), True)
     self.assertEqual(is_float("infinity"), True)
     self.assertEqual(is_float("1.797693e+308"), True)
     self.assertEqual(is_float("2.65773-317"), True)
     self.assertEqual(is_float("-3.83922-308"), True)
     self.assertEqual(is_float("-4.10537-305"), True)
     self.assertEqual(is_float("1.0+9"), True)
     self.assertEqual(is_float("1.0+1.0"), False)
     self.assertEqual(is_float("1+1.0"), False)
     self.assertEqual(is_float("1+1"), False)
     self.assertEqual(is_float("1-1"), False)
     self.assertEqual(is_float("2.65773-+317"), False)
     self.assertEqual(is_float("2f-317"), False)
     self.assertEqual(is_float("2f-3d"), False)
     self.assertEqual(is_float("2-2+3d"), False)
     self.assertEqual(is_float("12.34.56"), False)
     self.assertEqual(is_float("#56"), False)
     self.assertEqual(is_float("56f"), False)
     self.assertEqual(is_float("56.4d"), False)
     self.assertEqual(is_float("56%"), False)
     self.assertEqual(is_float("0E0"), True)
     self.assertEqual(is_float("x86E0"), False)
     self.assertEqual(is_float(True), True)
     self.assertEqual(is_float("True"), False)
     self.assertEqual(is_float("86-5"), False)
     self.assertEqual(is_float("+1e1^5"), False)
     self.assertEqual(is_float("+1e1"), True)
     self.assertEqual(is_float("-+1"), False)
     self.assertEqual(is_float("-+"), False)
     self.assertEqual(is_float("+"), False)
     self.assertEqual(is_float("-"), False)
     self.assertEqual(is_float("0-0"), False)
     self.assertEqual(is_float("0.0-0"), True)
     self.assertEqual(is_float("(1)"), False)
Ejemplo n.º 10
0
 def test_is_float(self):
     self.assertEqual(is_float(""), False)
     self.assertEqual(is_float("-0.000E+00"), True)
     self.assertEqual(is_float("1234567"), True)
     self.assertEqual(is_float("NaN"), True)
     self.assertEqual(is_float("NaNananana BATMAN"), False)
     self.assertEqual(is_float("123.456"), True)
     self.assertEqual(is_float("123.E4"), True)
     self.assertEqual(is_float(".1"), True)
     self.assertEqual(is_float("1,234"), False)
     self.assertEqual(is_float("NULL"), False)
     self.assertEqual(is_float(",1"), False)
     self.assertEqual(is_float("123.EE4"), False)
     self.assertEqual(is_float("6.523537535629999e-07"), True)
     self.assertEqual(is_float("6e777777"), True)
     self.assertEqual(is_float("iNF"), True)
     self.assertEqual(is_float("-iNF"), True)
     self.assertEqual(is_float("infinity"), True)
     self.assertEqual(is_float("1.797693e+308"), True)
     self.assertEqual(is_float("2.65773-317"), True)
     self.assertEqual(is_float("-3.83922-308"), True)
     self.assertEqual(is_float("-4.10537-305"), True)
     self.assertEqual(is_float("1.0+9"), True)
     self.assertEqual(is_float("1.0+1.0"), False)
     self.assertEqual(is_float("1+1.0"), False)
     self.assertEqual(is_float("1+1"), False)
     self.assertEqual(is_float("1-1"), False)
     self.assertEqual(is_float("2.65773-+317"), False)
     self.assertEqual(is_float("2f-317"), False)
     self.assertEqual(is_float("2f-3d"), False)
     self.assertEqual(is_float("2-2+3d"), False)
     self.assertEqual(is_float("12.34.56"), False)
     self.assertEqual(is_float("#56"), False)
     self.assertEqual(is_float("56f"), False)
     self.assertEqual(is_float("56.4d"), False)
     self.assertEqual(is_float("56%"), False)
     self.assertEqual(is_float("0E0"), True)
     self.assertEqual(is_float("x86E0"), False)
     self.assertEqual(is_float(True), True)
     self.assertEqual(is_float("True"), False)
     self.assertEqual(is_float("86-5"), False)
     self.assertEqual(is_float("+1e1^5"), False)
     self.assertEqual(is_float("+1e1"), True)
     self.assertEqual(is_float("-+1"), False)
     self.assertEqual(is_float("-+"), False)
     self.assertEqual(is_float("+"), False)
     self.assertEqual(is_float("-"), False)
     self.assertEqual(is_float("0-0"), False)
     self.assertEqual(is_float("0.0-0"), True)
     self.assertEqual(is_float("(1)"), False)