class _Event(tb.IsDescription): """ Description of the table /events/eventTable. """ # UIntAtom = uint32 array_row = tb.UIntCol(pos=0) # indicates the corresponding row in the event_start = tb.UIntCol(itemsize=8, pos=1) # start index of the event in the data event_length = tb.UIntCol(pos=2) n_levels = tb.UIntCol(pos=3) raw_points_per_side = tb.UIntCol(pos=4) baseline = tb.FloatCol(pos=5) current_blockage = tb.FloatCol(pos=6) area = tb.FloatCol(pos=7)
class Particle(tables.IsDescription): """This class defines a table record. """ lati = tables.IntCol(pos=0) # longi = IntCol(pos=1) Time = tables.Time64Col(pos=2) pressure = tables.FloatCol(pos=3) ID = tables.StringCol(itemsize=10, pos=4) Int16 = tables.UIntCol(itemsize=4, pos=5) Int64 = tables.IntCol(itemsize=8, pos=6) Bool = tables.BoolCol(pos=7)
class MsgTable(tables.IsDescription): ''' Pytables custom table atom type used for the HDF tables named *_msgs ''' time = tables.UIntCol() msg = tables.StringCol(256)
def calculate_additional_block_data(self): #----------------------------------------------------------------------- # get info from the original file #----------------------------------------------------------------------- block_info_table = self.file.root.block_info_table #----------------------------------------------------------------------- # get the new block data #----------------------------------------------------------------------- print 'Calculating new block data' start_time = time.time() das_ids = [] depth_ids = [] curr_das = None curr_sec = None for block in block_info_table: sec = block['section_id'] das = block['m_das_pt1'] if sec != curr_sec: #new sec curr_sec = sec das_id = -1 depth_id = -1 if das != curr_das: #new das curr_das = das das_id += 1 depth_id = -1 depth_id += 1 das_ids.append(das_id) depth_ids.append(depth_id) print 'Done! {} seconds'.format(time.time() - start_time) print 'Creating new tables' table_start_time = time.time() #----------------------------------------------------------------------- # create the new block_info_table #----------------------------------------------------------------------- #close the current file self.file.close() #reopen the file with the append flag set self.file = tables.open_file(self.file_path, 'a') block_info_table = self.file.root.block_info_table # get a description of table in dictionary format desc_orig = block_info_table.description._v_colObjects desc_new = desc_orig.copy() # add columns to description if self.do_das_id: desc_new['das_id'] = tables.UIntCol(dflt=0) if self.do_depth_id: desc_new['depth_id'] = tables.UIntCol(dflt=0) # create a new table with the new description block_info_table_new = self.file.create_table('/', 'tmp', desc_new, 'Block Info Table') # copy the user attributes block_info_table.attrs._f_copy(block_info_table_new) # fill the rows of new table with default values for i in xrange(block_info_table.nrows): block_info_table_new.row.append() # flush the rows to disk block_info_table_new.flush() # copy the columns of source table to destination for col in desc_orig: getattr(block_info_table_new.cols, col)[:] = getattr(block_info_table.cols, col)[:] # fill the new columns if self.do_das_id: block_info_table_new.cols.das_id[:] = das_ids if self.do_depth_id: block_info_table_new.cols.depth_id[:] = depth_ids # remove the original table block_info_table.remove() # move table2 to table block_info_table_new.move('/', 'block_info_table') print 'Done! {} seconds'.format(time.time() - table_start_time) #----------------------------------------------------------------------- # close the file and reopen it with the new tables #----------------------------------------------------------------------- self.file.close() self.file = tables.open_file(self.file_path) print 'Total time {} seconds'.format(time.time() - start_time)