Beispiel #1
0
def check_orth(seq, tol=1.0e-04, verbose=True):
    """Check the orthogonality of the basis sequence *seq*."""
    orth = True
    if verbose: iprint('[I] Orthonormality check:')
    i = 0
    rowvec = np.zeros(len(seq))
    for s1 in seq:
        if verbose:
            with ui.context(ui.colors.OKGREEN) as c:
                print('[I] row {}:'.format(i), end="")
        j = 0
        for s2 in seq:
            v = np.dot(s1, s2)
            rowvec[j] = v
            if i == j and abs(v - 1.0) > tol:
                orth = False
            if i != j and abs(v) > tol:
                orth = False
            j += 1
        if verbose:
            with ui.context(ui.colors.OKGREEN) as c:
                for v in rowvec:
                    print("{0:5.2f} ".format(v), end="")
                print(' ')
        i += 1
    if verbose:
        if orth: iprint("Basis is orthonormal.")
        else: eprint("Basis is NOT orthonormal")
    return orth
Beispiel #2
0
 def create_feature(c, name, units=None):
     """Experimental:  Creates a new feature table that can be used to store user-defined features."""
     try:
         c.execute('CREATE TABLE ' + name +
                   ' (timestamp integer primary key, value real)')
     except s3.OperationalError as e:
         eprint("{}".format(e))
     finally:
         return True
Beispiel #3
0
 def get_spike_basisid(self, spike_id):
     """Returns the basis_id associated with the given spike_id."""
     self.cur.execute(
         'SELECT basisID FROM spikebasis where spikeID == {};'.format(
             spike_id))
     result = self.cur.fetchone()
     if result is None:
         eprint('Spike id {} has no basis!'.format(spike_id))
     return result[0]
Beispiel #4
0
    def get_functions(self, basis_id, nfuncs=None, width=None):
        if nfuncs is None:
            self.cur.execute(
                'select max(component) from functions where basisID={};'.
                format(basis_id))
            result = self.fetchone()
            if result is not None:
                nfuncs = result[0] + 1
            else:
                eprint("Error: Could not infer nfuncs from functions table!")
                return None
        if width is None:
            self.cur.execute(
                'select max(k) from functions where basisID={};'.format(
                    basis_id))
            result = self.fetchone()
            if result is not None:
                width = result[0] + 1
            else:
                eprint("Error: Could not infer width from functions table!")
                return None
        width = int(width)
        basis = []
        for i in range(nfuncs):
            ker = numpy.zeros(width)
            basis.append(ker)

        # Now fill in the vectors from the functions table - these
        # have to be rectangular (i.e., same number of samples for
        # each function):
        self.cur.execute(
            'select component,k,value from functions where basisID={};'.format(
                basis_id))
        result = self.fetchall()
        for i in range(len(result)):
            r = result[i]
            c = r[0]
            k = r[1]
            v = r[2]
            vec = basis[c]
            vec[k] = v
        return basis
Beispiel #5
0
 def get_db_coefs(self, which, into=None):
     """Deprecated."""
     meta = self.get_metadata()
     nchannels = meta[1]
     eprint("get_db_coefs has been DEPRECATED!")
     if into != None:
         r = into
     else:
         self.execute('select count(*) from spikecoefs where channel == 0;')
         result = self.fetchone()
         nspikes = result[0]
         r = numpy.zeros((nspikes, nchannels))
     for k in range(nchannels):
         self.execute(
             'SELECT coef from spikecoefs where cindex={} and channel=={} order by spikeID;'
             .format(which, k))
         result = self.fetchall()
         for j in range(nspikes):
             r[j][k] = result[j][0]
     return r
Beispiel #6
0
 def make_meta_table(self, samprate, nchannels, fname, verbose=False):
     """Make the metadata table for this event store, specifying the sampling rate, number of channels, and full name of the raw data source."""
     ret = True
     self.sample_rate = samprate
     self.nchannels = nchannels
     self.recording = fname
     self.schema.create_table(self, 'meta')
     self.execute('SELECT * from meta;')
     result = self.fetchone()
     iprint("{}".format(result))
     if result is None:
         self.execute('INSERT INTO meta values ({}, {}, "{}");'.format(
             samprate, nchannels, fname))
         ret = True
     else:
         if result[0] != samprate or result[1] != nchannels or result[
                 2] != fname:
             eprint(
                 "You supplied arguments that are inconsistent with this db file!"
             )
             eprint("db file says: {}".format(result))
             eprint("args say: {} {} {}".format(samprate, nchannels, fname))
             ret = False
         else:
             if verbose:
                 iprint("Valid db file for these arguments.")
                 ret = True
     return ret