How to use tables - 10 common examples

To help you get started, we’ve selected a few tables examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github klusta-team / kwiklib / kwiklib / dataio / kwik.py View on Github external
file.createGroup('/channel_groups', 
                         '{0:d}'.format(ichannel_group))
                         
        
        # Determine a sensible chunk shape.
        chunkrows = 500 * 1024 // (nfeatures_ * 4 * (2 if has_masks else 1))
                         
        # Create the arrays.
        if has_masks:
            # Features + masks.
            file.createEArray(channel_group_path, 'features_masks',
                              tb.Float32Atom(), (0, nfeatures_, 2),
                              chunkshape=(chunkrows, nfeatures_, 2))
        else:
            file.createEArray(channel_group_path, 'features_masks',
                              tb.Float32Atom(), (0, nfeatures_),
                              chunkshape=(chunkrows, nfeatures_))
        
        
        # Determine a sensible chunk shape.
        chunkrows = 500 * 1024 // (waveforms_nsamples_ * nchannels_ * 2)
        
        file.createEArray(channel_group_path, 'waveforms_raw',
                          tb.Int16Atom(), (0, waveforms_nsamples_, nchannels_),
                          chunkshape=(chunkrows, waveforms_nsamples_, nchannels_))
        file.createEArray(channel_group_path, 'waveforms_filtered',
                          tb.Int16Atom(), (0, waveforms_nsamples_, nchannels_),
                          chunkshape=(chunkrows, waveforms_nsamples_, nchannels_))
                                                   
    file.close()
github sahg / PyTOPKAPI / tests / test_continuity / continuity_tests.py View on Github external
def compute_soil_drainage(result_fname, delta_t, cell_id):
    h5file = h5.openFile(result_fname)

    node = h5file.getNode('/'+'Soil', 'Qs_out')
    flows = node.read()[1:, cell_id]
    runoff_vol = flows.sum() * delta_t

    h5file.close()

    return runoff_vol
github CivicSpleen / ambry / test / dev_tests / test_pytables.py View on Github external
rows = [row() for i in range(N)]

        class PYT(tables.IsDescription):
            a = tables.Int32Col()
            b = tables.UInt8Col()
            c = tables.Float32Col()
            d = tables.StringCol(len(str(uuid4()))*4)
            e = tables.Time32Col()
            f = tables.Time32Col()

        h5file = tables.open_file('/tmp/hdf5/tutorial1.h5', mode='w', title='Test file')

        group = h5file.create_group('/', 'detector', 'Detector information')

        table = h5file.create_table(group, 'readout', PYT, 'Readout example',
                                    filters=tables.Filters(complevel=9, complib='zlib'))

        tr = table.row

        with Timer() as t:
            cache = []
            for i, row in enumerate(rows, 1):
                for i, h in enumerate(headers):
                    tr[h] = row[i]

                tr.append()
            table.flush()
            h5file.close()

        print('PyTables write ', float(N) / t.elapsed, N)

        h5file = tables.open_file('/tmp/hdf5/tutorial1.h5', mode='r', title='Test file')
github inasafe / inasafe / common / test_tables.py View on Github external
def test_table_with_colalign(self):
        """Table columns can be right justified"""

        # First with default alignment
        actual_result = Table(['12', '3000', '5'])

        expected_strings = ['12',
                            '3000',
                            '5']
        for s in expected_strings:
            message = ('Did not find expected string "%s" in result: %s'
                       % (s, actual_result))
            assert s in str(actual_result).strip(), message

        # Then using explicit alignment (all right justified)
        # FIXME (Ole): This does not work if e.g. col_align has
        # different strings: col_align = ['right', 'left', 'center']
        actual_result = Table(['12', '3000', '5'],
                              col_align=['right', 'right', 'right'])

        expected_strings = [
github inasafe / inasafe / common / test_tables.py View on Github external
def test_table_caption(self):
        """Test table caption"""
        self.html += '  <h2>Caption Top</h2>\n'
        expected_result = ('%s%s%s%s' % (self.html_table_start,
                                       self.html_caption,
                                       self.html_body,
                                       self.html_table_end))
        actual_result = Table(self.table_data, caption=self.table_caption)
        message = 'Expected: %s\n\nGot: %s' % (expected_result, actual_result)
        assert expected_result.strip() == str(actual_result).strip(), message
        self.html += str(actual_result)

        #also test bottom caption
        self.html += '  <h2>Caption Bottom</h2>\n'
        expected_result = ('%s%s%s%s' % (self.html_table_start,
                                       self.html_bottom_caption,
                                       self.html_body,
                                       self.html_table_end))
        actual_result = Table(self.table_data,
                              caption=self.table_caption,
                              caption_at_bottom=True)
        message = 'Expected: %s\n\nGot: %s' % (expected_result, actual_result)
        self.html += str(actual_result)
        self.writeHtml('table_caption')
github inasafe / inasafe / common / test_tables.py View on Github external
def test_table_cells(self):
        """Test table from individual cells"""
        self.html += '  <h2>Using Table Cells</h2>\n'
        expected_result = ('%s%s%s' % (self.html_table_start,
                                       self.html_body,
                                       self.html_table_end))
        actual_result = Table(self.table_cell_data)
        message = 'Expected: %s\n\nGot: %s' % (expected_result, actual_result)
        assert expected_result.strip() == str(actual_result).strip(), message
        self.html += str(actual_result)
        self.writeHtml('table_by_cell_objects')
github uvemas / ViTables / tests / create_samples.py View on Github external
import sys
import numpy
import tables

# The top level description of a sample table
class Particle(tables.IsDescription):
    name        = tables.StringCol(16, pos=1)   # 16-character String
    lati        = tables.IntCol(pos=2)        # integer
    longi       = tables.IntCol(pos=3)        # integer
    pressure    = tables.Float32Col(pos=4)    # float  (single precision)
    temperature = tables.FloatCol(pos=5)      # double (double precision)

# Define a nested field using a IsDescription descendant
class Info(tables.IsDescription):
    """A substructure of ComplexObject.
    """
    name    = tables.StringCol(16, pos=0)
    value   = tables.IntCol()
    
# Define a nested field using a dictionary
Coord = {
    "x": tables.FloatCol(pos=0),
    "y": tables.FloatCol(pos=1),
    "z": tables.FloatCol(pos=2)}
github uvemas / ViTables / tests / create_samples.py View on Github external
import tables

# The top level description of a sample table
class Particle(tables.IsDescription):
    name        = tables.StringCol(16, pos=1)   # 16-character String
    lati        = tables.IntCol(pos=2)        # integer
    longi       = tables.IntCol(pos=3)        # integer
    pressure    = tables.Float32Col(pos=4)    # float  (single precision)
    temperature = tables.FloatCol(pos=5)      # double (double precision)

# Define a nested field using a IsDescription descendant
class Info(tables.IsDescription):
    """A substructure of ComplexObject.
    """
    name    = tables.StringCol(16, pos=0)
    value   = tables.IntCol()
    
# Define a nested field using a dictionary
Coord = {
    "x": tables.FloatCol(pos=0),
    "y": tables.FloatCol(pos=1),
    "z": tables.FloatCol(pos=2)}

# The top level description of another sample table
# Dictionaries have an advantage over IsDescription: they allow for
# fields with blanks in their names
ComplexObject = {
    "ID": tables.StringCol(8, pos=0),   # 8-character String
    "long_ID": tables.StringCol(16, pos=1),   # 16-character String
    "position": tables.IntCol(shape=2, pos=2),        # integer
    "imag": tables.ComplexCol(16, pos=3), # complex (double precision)
    "info": Info(),
github HealthRex / CDSS / scripts / Archive / ClinicNet / clinicnet_model / utils / datagenerator.py View on Github external
def setup_batches(self, reset_cache=True):
        '''
        Setup batches to be used for the data generation pipeline
        Prepares the idx2batch and idx2file dicts that map batch number to the relevant data
        '''
        self.seed += 1
        if self.shuffle == True:
            np.random.RandomState(seed=self.seed).shuffle(self.files)
        if reset_cache:
            del self.cache
            self.cache = {} # Reset the cache
        idx = 0 
        self.idx2file = {} #reset the dictionaries
        self.idx2batch = {}
        for f in self.files:
            h5file = tables.open_file(self.path + "/" + f, mode="r")
            nrows = len(h5file.root.data_x.axis1)
            num_batches = int(np.ceil((nrows) / self.batch_size))
            indices = np.arange(nrows)
            if self.shuffle:
                np.random.RandomState(seed=(self.seed+idx)).shuffle(indices)
            num_rows_remaining = int(nrows % self.batch_size)
            padding = int(self.batch_size - num_rows_remaining) # The "padding" to add to make divisible by batch_size
            if num_rows_remaining > 0:
                batches = np.array_split(np.concatenate((indices, np.repeat(-1,padding))), num_batches) # Do batch assignments
                batches = [i[i != -1] for i in batches]
            else:
                batches = np.array_split(indices, num_batches)
            self.idx2batch.update(dict(list(zip(list(range(idx, idx+num_batches)), batches))))
            self.idx2file.update(dict.fromkeys(list(range(idx, idx+num_batches)), f))
            h5file.close()
            idx += num_batches
github bmvdgeijn / WASP / CHT / update_total_depth.py View on Github external
def load_data(inlist, seq_h5_filename, min_counts, skips):
    infiles = open_files(inlist, "rt")

    seq_h5 = tables.openFile(seq_h5_filename, "r")
    
    end_of_file = False
    count_table = []
    keep_list = []

    info_list = []
    for infile in infiles:
        line = infile.readline()
        line = infile.readline()
        if not line:
            end_of_file = True
        else:
            info_list.append(line.strip().split())
            
    while not end_of_file:        
        snp_info = info_list[0]