Esempio n. 1
0
    def fispact_deserialize(self, linedump):
        self.__init__()

        line = linedump[0].strip('\n')

        # fortran format is:
        # format(2x,a6,i8,i6,3x,a9,6x,i8,2x,es13.5,' +-',es12.5,es13.5,' +-',es12.5)
        self.name = line[2:8].strip()
        self.zai = int(line[8:16])
        self.number = int(line[16:22])

        # this is a really horrible hack, but the logic used to make the output file
        # is really bad - "no spectral data" is output if no data exists, but this has
        # length 16 but otherwise the length of type is 9 +6 whitespace = 15, so just 1 off
        # why did they do this???
        # Because of this stupid logic we have to hack here
        self.type = line[25:40].strip()

        # if no spectral data then skip
        if self.type == "no spectral dat":
            self.type = "no spectral data"
            return

        self.nr_of_lines = int(line[40:48])
        self.mean_energy = get_float(line[50:63])
        self.mean_energy_unc = get_float(line[66:78])
        self.mean_normalisation = get_float(line[78:91])
        self.mean_normalisation_unc = get_float(line[94:106])
Esempio n. 2
0
    def fispact_deserialize(self, linedump):
        self.__init__()

        line = linedump[0].strip('\n')

        # fortran format is:
        # format(2x,a6,i8,i6,3x,a9,6x,i8,2x,es13.5,' +-',es12.5,es13.5,' +-',es12.5)
        self.name = line[2:8].strip()
        self.zai = int(line[8:16])
        self.number = int(line[16:22])

        # this is a really horrible hack, but the logic used to make the output file
        # is really bad - "no spectral data" is output if no data exists, but this has
        # length 16 but otherwise the length of type is 9 +6 whitespace = 15, so just 1 off
        # why did they do this???
        # Because of this stupid logic we have to hack here
        self.type = line[25:40].strip()

        # if no spectral data then skip
        if self.type == "no spectral dat":
            self.type = "no spectral data"
            return

        self.nr_of_lines = int(line[40:48])
        self.mean_energy = get_float(line[50:63])
        self.mean_energy_unc = get_float(line[66:78])
        self.mean_normalisation = get_float(line[78:91])
        self.mean_normalisation_unc = get_float(line[94:106])
Esempio n. 3
0
 def test_are_values_the_same(self):
     self.assertEqual(are_values_the_same(float('nan'), float('nan'), 0.000), False)
     self.assertEqual(are_values_the_same(float('NaN'), float('NaN'), 0.000), False)
     self.assertEqual(are_values_the_same(float('NaN'), float('NaN'), 0.100), False)
     self.assertEqual(are_values_the_same(float('NaN'), float('NaN')*2.0, 0.000), False)
     self.assertEqual(are_values_the_same(float('NaN'), float('NaN')*2.0, 4.000), False)
     self.assertEqual(are_values_the_same(float('NaN'), float('NaN'), float('NaN')), False)
     self.assertEqual(are_values_the_same(0.0, float('NaN'), float('NaN')), False)
     self.assertEqual(are_values_the_same(0.0, float('NaN'), 1e9), False)
     self.assertEqual(are_values_the_same(2.3, 2.4, float('NaN')), False)
     self.assertEqual(are_values_the_same(2.3, 2.4, 1e-9), False)
     self.assertEqual(are_values_the_same(2.3, 2.4, 1e9), True)
     self.assertEqual(are_values_the_same(0.0, -0.0, 0.000), True)
     self.assertEqual(are_values_the_same(0.0, -0.0, 0.100), True)
     self.assertEqual(are_values_the_same(-0.0, -0.0, 0.000), True)
     self.assertEqual(are_values_the_same(-0.0, -0.0, 0.100), True)
     self.assertEqual(are_values_the_same(-0.0, 0.0, 0.000), True)
     self.assertEqual(are_values_the_same(-0.0, 0.0, 1e-6), True)
     self.assertEqual(are_values_the_same(-0.000E+00, 0.000E+00, 0.000), True)
     self.assertEqual(are_values_the_same(-0.000E+00, 0.000E+00, 0.000E+00), True)
     self.assertEqual(are_values_the_same(-0.000E+00, -0.000E+00, 0.000E+00), True)
     self.assertEqual(are_values_the_same(0.000E+00, -0.000E+00, 0.0), True)
     self.assertEqual(are_values_the_same(0.000E+00, -0.000E+00, 1.000E-06), True)
     self.assertEqual(are_values_the_same(0.0, 0.0, 0.000), True)
     self.assertEqual(are_values_the_same(0.0, 0.0, 0.100), True)
     self.assertEqual(are_values_the_same(0.0, 0.1, 0.000), False)
     self.assertEqual(are_values_the_same(0.0, 0.1, 0.999), False)
     self.assertEqual(are_values_the_same(0.0, 0.1, 1.000), True)
     self.assertEqual(are_values_the_same(1.0, 1.0, 0.000), True)
     self.assertEqual(are_values_the_same(1.0, 1.0, 0.010), True)
     self.assertEqual(are_values_the_same(1.0, 1.1, 0.010), False)
     self.assertEqual(are_values_the_same(1.0, 1.1, 0.091), True)
     self.assertEqual(are_values_the_same(1.0, 1.1, 0.090), False)
     self.assertEqual(are_values_the_same(1.1, 1.0, 0.090), False)
     self.assertEqual(are_values_the_same(-1.1, -1.0, 0.090), False)
     self.assertEqual(are_values_the_same(2.3, 2.3, float('NaN')), False)
     self.assertEqual(are_values_the_same(0.0, 0.0, float('NaN')), False)
     self.assertEqual(are_values_the_same(1.0, 0.0, 1.000), True)
     self.assertEqual(are_values_the_same(1.1, 1.0, 0.091), True)
     self.assertEqual(are_values_the_same(-1.1, -1.0, 0.091), True)
     self.assertEqual(are_values_the_same(0.0, 6.2e-32, 0.0), False)
     self.assertEqual(are_values_the_same(6.2e-32, 0.0, 0.0), False)
     self.assertEqual(are_values_the_same(0.0, -6.2e-32, 0.0), False)
     self.assertEqual(are_values_the_same(-6.2e-32, -6.2e-32, 0.0), True)
     self.assertEqual(are_values_the_same(8.67e-309, -6.2e-32, 0.0), False)
     self.assertEqual(are_values_the_same(8.67e-309, 6.2e-32, 8.67e-309), False)
     self.assertEqual(are_values_the_same(8.67e-309, 8.671e-309, 1e-3), True)
     self.assertEqual(are_values_the_same(get_float("2.65773+317"), 6.2e-32, 0.0), False)
     self.assertEqual(are_values_the_same(get_float("2.65773+317"), 0.0, 0.0), False)
     self.assertEqual(are_values_the_same(get_float("-2.65773-317"), 6.2e-305, 0.0, abs_tol=1e-300), True)
     self.assertEqual(are_values_the_same(get_float("-2.65773-317"), 6.2e-305, 0.0, abs_tol=1e-310), False)
     self.assertEqual(are_values_the_same(get_float("-2.65773-317"), get_float("-2.65773-308"), 0.0, abs_tol=1e-310), False)
     self.assertEqual(are_values_the_same(get_float("-2.65773-317"), get_float("-2.65773-318"), 0.0, abs_tol=1e-310), True)
     self.assertEqual(are_values_the_same(get_float("-2.65773+317"), 0.0, 0.0), False)
Esempio n. 4
0
    def fispact_deserialize(self, filerecord, interval):

        self.__init__()

        substring = filerecord[interval]

        dose_string = pf.first(datadump=substring,
                               headertag=DOSE_RATE_HEADER,
                               starttag=DOSE_RATE_HEADER,
                               endtag=')',
                               ignores=DOSE_RATE_IGNORES,
                               asstring=True)

        if 'PLANE' in dose_string:
            self.type = 'PLANE SOURCE'
        elif 'POINT' in dose_string:
            self.type = 'POINT SOURCE'

            # Mass is always in grams and is actually always 1 g
            # but read it in to verify
            self.mass = first_value_from_line(dose_string, '') * 1e-3

            # Distance is always in meters but is written without a space so
            # we must strip it off
            floatstr = strings_from_line(dose_string,
                                         'SOURCE')[-1].replace('m', '')
            self.distance = get_float(floatstr)

        self.dose = pf.first(datadump=substring,
                             headertag=DOSE_RATE_HEADER,
                             starttag='IS',
                             endtag='Sieverts/hour',
                             ignores=DOSE_RATE_IGNORES,
                             asstring=False)
Esempio n. 5
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
Esempio n. 6
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)
Esempio n. 7
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
Esempio n. 8
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)
Esempio n. 9
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])
Esempio n. 10
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])
Esempio n. 11
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
Esempio n. 12
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
Esempio n. 13
0
 def test_are_values_the_same(self):
     self.assertEqual(
         are_values_the_same(float('nan'), float('nan'), 0.000), False)
     self.assertEqual(
         are_values_the_same(float('NaN'), float('NaN'), 0.000), False)
     self.assertEqual(
         are_values_the_same(float('NaN'), float('NaN'), 0.100), False)
     self.assertEqual(
         are_values_the_same(float('NaN'),
                             float('NaN') * 2.0, 0.000), False)
     self.assertEqual(
         are_values_the_same(float('NaN'),
                             float('NaN') * 2.0, 4.000), False)
     self.assertEqual(
         are_values_the_same(float('NaN'), float('NaN'), float('NaN')),
         False)
     self.assertEqual(are_values_the_same(0.0, float('NaN'), float('NaN')),
                      False)
     self.assertEqual(are_values_the_same(0.0, float('NaN'), 1e9), False)
     self.assertEqual(are_values_the_same(2.3, 2.4, float('NaN')), False)
     self.assertEqual(are_values_the_same(2.3, 2.4, 1e-9), False)
     self.assertEqual(are_values_the_same(2.3, 2.4, 1e9), True)
     self.assertEqual(are_values_the_same(0.0, -0.0, 0.000), True)
     self.assertEqual(are_values_the_same(0.0, -0.0, 0.100), True)
     self.assertEqual(are_values_the_same(-0.0, -0.0, 0.000), True)
     self.assertEqual(are_values_the_same(-0.0, -0.0, 0.100), True)
     self.assertEqual(are_values_the_same(-0.0, 0.0, 0.000), True)
     self.assertEqual(are_values_the_same(-0.0, 0.0, 1e-6), True)
     self.assertEqual(are_values_the_same(-0.000E+00, 0.000E+00, 0.000),
                      True)
     self.assertEqual(are_values_the_same(-0.000E+00, 0.000E+00, 0.000E+00),
                      True)
     self.assertEqual(
         are_values_the_same(-0.000E+00, -0.000E+00, 0.000E+00), True)
     self.assertEqual(are_values_the_same(0.000E+00, -0.000E+00, 0.0), True)
     self.assertEqual(are_values_the_same(0.000E+00, -0.000E+00, 1.000E-06),
                      True)
     self.assertEqual(are_values_the_same(0.0, 0.0, 0.000), True)
     self.assertEqual(are_values_the_same(0.0, 0.0, 0.100), True)
     self.assertEqual(are_values_the_same(0.0, 0.1, 0.000), False)
     self.assertEqual(are_values_the_same(0.0, 0.1, 0.999), False)
     self.assertEqual(are_values_the_same(0.0, 0.1, 1.000), True)
     self.assertEqual(are_values_the_same(1.0, 1.0, 0.000), True)
     self.assertEqual(are_values_the_same(1.0, 1.0, 0.010), True)
     self.assertEqual(are_values_the_same(1.0, 1.1, 0.010), False)
     self.assertEqual(are_values_the_same(1.0, 1.1, 0.091), True)
     self.assertEqual(are_values_the_same(1.0, 1.1, 0.090), False)
     self.assertEqual(are_values_the_same(1.1, 1.0, 0.090), False)
     self.assertEqual(are_values_the_same(-1.1, -1.0, 0.090), False)
     self.assertEqual(are_values_the_same(2.3, 2.3, float('NaN')), False)
     self.assertEqual(are_values_the_same(0.0, 0.0, float('NaN')), False)
     self.assertEqual(are_values_the_same(1.0, 0.0, 1.000), True)
     self.assertEqual(are_values_the_same(1.1, 1.0, 0.091), True)
     self.assertEqual(are_values_the_same(-1.1, -1.0, 0.091), True)
     self.assertEqual(are_values_the_same(0.0, 6.2e-32, 0.0), False)
     self.assertEqual(are_values_the_same(6.2e-32, 0.0, 0.0), False)
     self.assertEqual(are_values_the_same(0.0, -6.2e-32, 0.0), False)
     self.assertEqual(are_values_the_same(-6.2e-32, -6.2e-32, 0.0), True)
     self.assertEqual(are_values_the_same(8.67e-309, -6.2e-32, 0.0), False)
     self.assertEqual(are_values_the_same(8.67e-309, 6.2e-32, 8.67e-309),
                      False)
     self.assertEqual(are_values_the_same(8.67e-309, 8.671e-309, 1e-3),
                      True)
     self.assertEqual(
         are_values_the_same(get_float("2.65773+317"), 6.2e-32, 0.0), False)
     self.assertEqual(
         are_values_the_same(get_float("2.65773+317"), 0.0, 0.0), False)
     self.assertEqual(
         are_values_the_same(get_float("-2.65773-317"),
                             6.2e-305,
                             0.0,
                             abs_tol=1e-300), True)
     self.assertEqual(
         are_values_the_same(get_float("-2.65773-317"),
                             6.2e-305,
                             0.0,
                             abs_tol=1e-310), False)
     self.assertEqual(
         are_values_the_same(get_float("-2.65773-317"),
                             get_float("-2.65773-308"),
                             0.0,
                             abs_tol=1e-310), False)
     self.assertEqual(
         are_values_the_same(get_float("-2.65773-317"),
                             get_float("-2.65773-318"),
                             0.0,
                             abs_tol=1e-310), True)
     self.assertEqual(
         are_values_the_same(get_float("-2.65773+317"), 0.0, 0.0), False)
Esempio n. 14
0
 def test_get_float(self):
     self.assertEqual(get_float("1234567"), 1234567)
     self.assertEqual(math.isnan(get_float("NaN")), True)
     self.assertEqual(get_float("123.456"), 123.456)
     self.assertEqual(get_float("123.E4"), 123.E4)
     self.assertEqual(get_float(".1"), 0.1)
     self.assertEqual(get_float("6.523537535629999e-07"),
                      6.523537535629999e-07)
     self.assertEqual(get_float("6e777777"), 6e777777)
     self.assertEqual(math.isinf(get_float("iNF")), True)
     self.assertEqual(math.isinf(get_float("-iNF")), True)
     self.assertEqual(math.isinf(get_float("infinity")), True)
     self.assertEqual(get_float("1.797693e+308"), 1.797693e+308)
     self.assertEqual(get_float("2.65773-317"), 2.65773e-317)
     self.assertEqual(get_float("2.65773+317"), 2.65773e+317)
     self.assertEqual(get_float("2.65773-300"), 2.65773e-300)
     self.assertEqual(get_float("2.65773-31"), 2.65773e-31)
     self.assertEqual(get_float("-3.83922-308"), -3.83922e-308)
     self.assertEqual(get_float("-4.10537-305"), -4.10537e-305)
     self.assertEqual(get_float("1.0+9"), 1.0e+9)
     self.assertEqual(get_float("0E0"), 0.0)
     self.assertEqual(get_float("0.0-0"), 0.0)
     self.assertEqual(get_float("-0.000E+00"), 0.0)
     self.assertEqual(get_float("+1e1"), 10)
     self.assertEqual(get_float("-1e1"), -10)
     self.assertEqual(get_float("-1.1e1"), -11)
Esempio n. 15
0
 def test_get_float(self):
     self.assertEqual(get_float("1234567"), 1234567)
     self.assertEqual(math.isnan(get_float("NaN")), True)
     self.assertEqual(get_float("123.456"), 123.456)
     self.assertEqual(get_float("123.E4"), 123.E4)
     self.assertEqual(get_float(".1"), 0.1)
     self.assertEqual(get_float("6.523537535629999e-07"), 6.523537535629999e-07)
     self.assertEqual(get_float("6e777777"), 6e777777)
     self.assertEqual(math.isinf(get_float("iNF")), True)
     self.assertEqual(math.isinf(get_float("-iNF")), True)
     self.assertEqual(math.isinf(get_float("infinity")), True)
     self.assertEqual(get_float("1.797693e+308"), 1.797693e+308)
     self.assertEqual(get_float("2.65773-317"), 2.65773e-317)
     self.assertEqual(get_float("2.65773+317"), 2.65773e+317)
     self.assertEqual(get_float("2.65773-300"), 2.65773e-300)
     self.assertEqual(get_float("2.65773-31"), 2.65773e-31)
     self.assertEqual(get_float("-3.83922-308"), -3.83922e-308)
     self.assertEqual(get_float("-4.10537-305"), -4.10537e-305)
     self.assertEqual(get_float("1.0+9"), 1.0e+9)
     self.assertEqual(get_float("0E0"), 0.0)
     self.assertEqual(get_float("0.0-0"), 0.0)
     self.assertEqual(get_float("-0.000E+00"), 0.0)
     self.assertEqual(get_float("+1e1"), 10)
     self.assertEqual(get_float("-1e1"), -10)
     self.assertEqual(get_float("-1.1e1"), -11)