def make_used_fuel_tables(hdf5_file, rx_list=None): # Open the HDF5 file opened_here = False if isinstance(hdf5_file, basestring): opened_here = True hdf5_file = tb.openFile(hdf5_file, 'a') h5r = hdf5_file.root # Grab reactor list if not specified if rx_list == None: rx_id_map = get_reactor_id_map(hdf5_file) rx_list = sorted(rx_id_map.values()) # Make new used fuel tables for rx in rx_list: rx_group = getattr(h5r, rx) # Remove pre-existing table if hasattr(rx_group, 'used_fuel'): hdf5_file.removeNode(rx_group, 'used_fuel') hdf5_file.createTable(rx_group, 'used_fuel', UsedFuel, title="Used Fuel for {0}".format(rx), expectedrows=len(rx_group.fresh_fuel_info), ) # Close the HDF5 file if opened_here: hdf5_file.close()
def calc_used_fuel_rows(hdf5_file, rx_list=None, slice=(0,-1, 1), fc_flag=0): # Open the HDF5 file opened_here = False if isinstance(hdf5_file, basestring): opened_here = True hdf5_file = tb.openFile(hdf5_file, 'a') h5r = hdf5_file.root # Grab reactor list if not specified if rx_list == None: rx_id_map = get_reactor_id_map(hdf5_file) rx_list = sorted(rx_id_map.values()) # Make new used fuel tables for rx in rx_list: rx_group = getattr(h5r, rx) rx_num = len(rx_group.fresh_fuel_info) sys.stdout.write(rx) sys.stdout.flush() # Determine slice for this reactor if len(slice) == 1: rx_slice = [slice[0], -1, 1] elif len(slice) == 2: rx_slice = [slice[0], slice[1], 1] elif len(slice) == 3: rx_slice = [slice[0], slice[1], slice[2]] if rx_slice[0] < 0: rx_slice[0] = len(rx_group.fresh_fuel_info) + rx_slice[0] if rx_slice[1] < 0: rx_slice[1] = len(rx_group.fresh_fuel_info) + rx_slice[1] + 1 # Run the calculations for the specified rows! t1 = time.time() for n in xrange(*rx_slice): calc_used_fuel_row(rx_group, n, fuel_cycles[fc_flag]) if n%100 == 0: t2 = time.time() sys.stdout.write( '\r{0}... n = {1}/{2}; rate = {3:.3f} n/s'.format(rx, n, rx_num, 100.0/(t2 - t1)) ) sys.stdout.flush() t1 = t2 t2 = time.time() sys.stdout.write( '\r{0}... n = {1}/{2}; rate = {3:.3f} n/s\n'.format(rx, n+1, rx_num, 100.0/(t2 - t1)) ) sys.stdout.flush() # Close the HDF5 file if opened_here: hdf5_file.close()
def make_fresh_fuel_info(hdf5_file, csv_file='raw/tblFuelFresh.csv'): # Open the HDF5 file opened_here = False if isinstance(hdf5_file, basestring): opened_here = True hdf5_file = tb.openFile(hdf5_file, 'a') h5r = hdf5_file.root rx_id_map = get_reactor_id_map(hdf5_file) # Make new fresh fuel tables for rx_id in rx_id_map.keys(): rx_group = getattr(h5r, rx_id_map[rx_id]) # Remove pre-existing table if hasattr(rx_group, 'fresh_fuel_info'): hdf5_file.removeNode(rx_group, 'fresh_fuel_info') hdf5_file.createTable(rx_group, 'fresh_fuel_info', FreshFuelInfo) # Read in the assembly data and write it to the HDF5 file fresh_fuel_file = csv.reader(open(csv_file, 'rb')) for ffrow in fresh_fuel_file: # Find the right group, table, and row rx_group = getattr(h5r, rx_id_map[int(ffrow[0])]) rx_table = rx_group.fresh_fuel_info rx_row = rx_table.row # Prepare the data rx_row['assembly_id'] = ffrow[2] rx_row['mass'] = float(ffrow[3]) rx_row['enrichment'] = float(ffrow[4]) / 100.0 rx_row['burnup'] = float(ffrow[5]) / 1000.0 rx_row['assembly_type'] = ffrow[6] rx_row['assembly_status'] = ffrow[7] rx_row['storage_id'] = ffrow[9] rx_row['discharge_cycle'] = ffrow[10] try: dd = time.mktime( time.strptime(ffrow[11], time_format) ) except ValueError: dd = 0.0 rx_row['discharge_date'] = dd # Append this row rx_row.append() rx_table.flush() # Close the HDF5 file if opened_here: hdf5_file.close()
def make_reactor_groups(hdf5_file): # Open the HDF5 file opened_here = False if isinstance(hdf5_file, basestring): opened_here = True hdf5_file = tb.openFile(hdf5_file, 'a') h5r = hdf5_file.root rx_id_map = get_reactor_id_map(hdf5_file) # Make the reactor groups for rx_id in rx_id_map.keys(): # Remove pre-existing group if hasattr(h5r, rx_id_map[rx_id]): hdf5_file.removeNode(h5r, rx_id_map[rx_id], recursive=True) hdf5_file.createGroup(h5r, rx_id_map[rx_id]) # Close the HDF5 file if opened_here: hdf5_file.close()