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 = getfloat(floatstr) self.dose = pf.first(datadump=substring, headertag=DOSE_RATE_HEADER, starttag='IS', endtag='Sieverts/hour', ignores=DOSE_RATE_IGNORES, asstring=False)
def test_first(self): self.assertEqual(pf.first(self.teststr, 'This', '', asstring=True), 'This is a line.') self.assertTrue(self._isnotfound(pf.first(self.teststr, 'This', '', asstring=False))) self.assertEqual(pf.first(self.teststr, 'This', 'This', asstring=True), 'is a line.') self.assertTrue(self._isnotfound(pf.first(self.teststr, 'This', 'This', asstring=False))) self.assertEqual(pf.first(self.teststr, 'This', 'This is ', asstring=True), 'a line.') self.assertTrue(self._isnotfound(pf.first(self.teststr, 'This', 'This is ', asstring=False))) self.assertEqual(pf.first(self.teststr, 'This', 'Here', asstring=True), 'are some values 3.4, 88.93e7 and -0.83324e-5 with some text. (738.9)') self.assertEqual(pf.first(self.teststr, 'This', 'Here', asstring=False), 3.4) self.assertEqual(pf.first(self.teststr, 'This', 'Here', ignores=['3.4,'], asstring=False), 88.93e7)
def get_value(starttag, endtag): return pf.first(datadump=substring, headertag=TIME_STEP_HEADER, starttag=starttag, endtag=endtag, ignores=TIME_STEP_IGNORES, asstring=False)
def nr_of_nuclides(): number = pf.first(datadump=substring, headertag=NUCLIDES_HEADER, starttag=nuclidetag, endtag='', ignores=NUCLIDES_IGNORES, asstring=False) return int(number)
def _process(self): for i in range(0, len(self)): t = self.lineindices[i] nt = -1 if i < len(self.lineindices) - 1: nt = self.lineindices[i + 1] interval = int( pf.first(datadump=self.cachedlines[t:nt], headertag=TIME_STEP_HEADER, starttag=TIME_STEP_HEADER, endtag='', ignores=[], asstring=False)) irrad_time = pf.first(datadump=self.cachedlines[t:nt], headertag=TIME_STEP_HEADER, starttag=IRRAD_TIME_TAG, endtag='SECS', ignores=[], asstring=False) cool_time = pf.first(datadump=self.cachedlines[t:nt], headertag=TIME_STEP_HEADER, starttag=COOLING_TIME_TAG, endtag='SECS', ignores=[], asstring=False) self.timesteps.append((interval, self.cachedlines[t:nt])) self.irradiation_times.append(irrad_time) self.cooling_times.append(cool_time) if irrad_time == 0.0: irrad_time = cool_time self.times.append(irrad_time) # turn them into cumulative values self.irradiation_times = list(accumulate(self.irradiation_times)) self.cooling_times = list(accumulate(self.cooling_times)) assert len(self.irradiation_times) == len(self.cooling_times)
def _process(self): for i in range(0, len(self)): t = self.lineindices[i] nt = -1 if i < len(self.lineindices) - 1: nt = self.lineindices[i+1] interval = int(pf.first(datadump=self.cachedlines[t:nt], headertag=TIME_STEP_HEADER, starttag=TIME_STEP_HEADER, endtag='', ignores=[], asstring=False)) irrad_time = pf.first(datadump=self.cachedlines[t:nt], headertag=TIME_STEP_HEADER, starttag=IRRAD_TIME_TAG, endtag='SECS', ignores=[], asstring=False) cool_time = pf.first(datadump=self.cachedlines[t:nt], headertag=TIME_STEP_HEADER, starttag=COOLING_TIME_TAG, endtag='SECS', ignores=[], asstring=False) self.timesteps.append((interval, self.cachedlines[t:nt])) self.irradiation_times.append(irrad_time) self.cooling_times.append(cool_time) if irrad_time == 0.0: irrad_time = cool_time self.times.append(irrad_time) # turn them into cumulative values self.irradiation_times = list(accumulate(self.irradiation_times)) self.cooling_times = list(accumulate(self.cooling_times)) assert len(self.irradiation_times) == len(self.cooling_times)
def fispact_deserialize(self, filerecord): self.__init__() self.timestamp = pf.first(datadump=filerecord.cachedlines, headertag='THIS RUN', starttag='timestamp:', endtag='', ignores=RUN_DATA_IGNORES, asstring=True) self.run_name = pf.first(datadump=filerecord.cachedlines, headertag='THIS RUN', starttag='FISPACT title:', endtag='', ignores=RUN_DATA_IGNORES, asstring=True) self.flux_name = pf.first(datadump=filerecord.cachedlines, headertag='INITIAL CROSS SECTION DATA', starttag='FLUX file label:', endtag='', ignores=RUN_DATA_IGNORES, asstring=True)
def fispact_deserialize(self, filerecord, interval): # reset to defaults before reading self.__init__(ignorenuclides=self.__ignorenuclides) substring = filerecord[interval] if substring: self.irradiation_time = filerecord.cumulirradiationtime(interval) self.cooling_time = filerecord.cumulcoolingtime(interval) def get_value(starttag, endtag): return pf.first(datadump=substring, headertag=TIME_STEP_HEADER, starttag=starttag, endtag=endtag, ignores=TIME_STEP_IGNORES, asstring=False) self.flux = get_value(starttag='* * * FLUX AMP IS', endtag='/cm^2/s') self.alpha_heat = get_value(starttag='TOTAL ALPHA HEAT PRODUCTION', endtag='kW') self.beta_heat = get_value(starttag='TOTAL BETA HEAT PRODUCTION', endtag='kW') self.gamma_heat = get_value(starttag='TOTAL GAMMA HEAT PRODUCTION', endtag='kW') self.total_heat = self.alpha_heat + self.beta_heat + self.gamma_heat self.initial_mass = get_value( starttag='0 INITIAL TOTAL MASS OF MATERIAL', endtag='kg') self.total_mass = get_value(starttag='0 TOTAL MASS OF MATERIAL', endtag='kg') self.number_of_fissions = get_value(starttag='NUMBER OF FISSIONS', endtag='BURN-UP') self.burnup = get_value(starttag='BURN-UP OF ACTINIDES', endtag='%') self.ingestion_dose = get_value( starttag='INGESTION HAZARD FOR ALL MATERIALS', endtag='Sv/kg') self.inhalation_dose = get_value( starttag='INHALATION HAZARD FOR ALL MATERIALS', endtag='Sv/kg') self.alpha_activity = get_value(starttag='ALPHA BECQUERELS =', endtag='BETA') self.beta_activity = get_value(starttag='BETA BECQUERELS =', endtag='GAMMA') self.gamma_activity = get_value(starttag='GAMMA BECQUERELS =', endtag='') self.total_activity = get_value( starttag='TOTAL ACTIVITY FOR ALL MATERIALS', endtag='Bq') self.total_activity_exclude_trit = get_value( starttag='TOTAL ACTIVITY EXCLUDING TRITIUM', endtag='Bq') self.dose_rate.fispact_deserialize(filerecord, interval) self.gamma_spectrum.fispact_deserialize(filerecord, interval) self.total_displacement_rate = pf.first( datadump=substring, headertag="Total Displacement Rate (n,Dtot ) =", starttag="Displacements/sec =", endtag="Displacements Per Atom/sec =", ignores=TIME_STEP_IGNORES, asstring=False) self.duration = filerecord.times[interval - 1] # for fission this can be very large and hence very slow # if you do not care about the nuclides then we can set # it to ignore nuclides if not self.__ignorenuclides: t = Nuclides() t.fispact_deserialize(filerecord, interval) self.nuclides = t.nuclides
def test_from_file(self): # test some values from the output file self.assertEqual(pf.first(datadump=self.file_as_string, headertag='THIS RUN', starttag='timestamp:', endtag='', ignores=['\n', '|'], asstring=True), '12:35:22 13 January 2018') self.assertEqual(pf.last(datadump=self.file_as_string, headertag='THIS RUN', starttag='timestamp:', endtag='', ignores=['\n', '|'], asstring=True), '12:35:22 13 January 2018') self.assertEqual(pf.first(datadump=self.file_as_string, headertag='INITIAL CROSS SECTION DATA', starttag='FLUX file label:', endtag='', ignores=['\n', '|'], asstring=True), 'FBR-Na End of Cycle heavy fuel s') self.assertEqual(pf.last(datadump=self.file_as_string, headertag='INITIAL CROSS SECTION DATA', starttag='FLUX file label:', endtag='', ignores=['\n', '|'], asstring=True), 'FBR-Na End of Cycle heavy fuel s') self.assertEqual(pf.first(datadump=self.file_as_string, headertag='* * * TIME INTERVAL', starttag='TOTAL ACTIVITY EXCLUDING TRITIUM', endtag='', ignores=['\n', '|'], asstring=True), '1.45396E+07 Bq') self.assertEqual(pf.first(datadump=self.file_as_string, headertag='* * * TIME INTERVAL', starttag='TOTAL ACTIVITY EXCLUDING TRITIUM', endtag='Bq', ignores=['\n', '|'], asstring=True), '1.45396E+07') self.assertEqual(pf.first(datadump=self.file_as_string, headertag='* * * TIME INTERVAL', starttag='TOTAL ACTIVITY EXCLUDING TRITIUM', endtag='', ignores=['\n', '|'], asstring=False), 1.45396E+07) self.assertEqual(pf.first(datadump=self.file_as_string, headertag='* * * TIME INTERVAL', starttag='TOTAL ACTIVITY EXCLUDING TRITIUM', endtag='Bq', ignores=['\n', '|'], asstring=False), 1.45396E+07) self.assertEqual(pf.last(datadump=self.file_as_string, headertag='* * * TIME INTERVAL', starttag='TOTAL ACTIVITY EXCLUDING TRITIUM', endtag='', ignores=['\n', '|'], asstring=True), '4.11578E+07 Bq') self.assertEqual(pf.last(datadump=self.file_as_string, headertag='* * * TIME INTERVAL', starttag='TOTAL ACTIVITY EXCLUDING TRITIUM', endtag='Bq', ignores=['\n', '|'], asstring=True), '4.11578E+07') self.assertEqual(pf.last(datadump=self.file_as_string, headertag='* * * TIME INTERVAL', starttag='TOTAL ACTIVITY EXCLUDING TRITIUM', endtag='', ignores=['\n', '|'], asstring=False), 4.11578E+07) self.assertEqual(pf.last(datadump=self.file_as_string, headertag='* * * TIME INTERVAL', starttag='TOTAL ACTIVITY EXCLUDING TRITIUM', endtag='Bq', ignores=['\n', '|'], asstring=False), 4.11578E+07) self.assertEqual(pf.first(datadump=self.file_as_string, headertag='DOSE RATE (', starttag='IS', endtag='', ignores=[], asstring=True), '2.94608E-05 Sieverts/hour ( 2.94608E-03 Rems/hour)') self.assertEqual(pf.first(datadump=self.file_as_string, headertag='DOSE RATE (', starttag='IS', endtag='Sieverts/hour', ignores=[], asstring=True), '2.94608E-05') self.assertEqual(pf.first(datadump=self.file_as_string, headertag='DOSE RATE (', starttag='IS', endtag='Sieverts/hour', ignores=[], asstring=False), 2.94608E-05) self.assertEqual(pf.first(datadump=self.file_as_string, headertag='DOSE RATE (', starttag='IS', endtag='', ignores=[], asstring=False), 2.94608E-05) self.assertEqual(pf.first(datadump=self.file_as_string, headertag='DOSE RATE (', starttag='DOSE RATE (', endtag='', ignores=[], asstring=False), 2.94608E-05) self.assertEqual(pf.first(datadump=self.file_as_string, headertag='DOSE RATE (', starttag='DOSE RATE (', endtag='', ignores=['2.94608E-05'], asstring=False), 2.94608E-03)