示例#1
0
文件: legacy.py 项目: gic888/gdblocks
def reduce(opts, args):
    '''
    Generates a document with a reduced representation of cell I/O properties,
    and save this to disk. Usage is:

    reduce [-d path] outfilename

    outfilename specifies where to save the output. The type of this file is
    inferred from its extension (if there is no "." in outfilename, ".gic" is
    used by default).

    If -d is specified, 'path' should be a file path to a document of the
    sort written by the "get" subcommand. Specifying this saves the time
    required to do the raw data extraction, and is also required if you
    wanted to pass non-default arguments to get. If -d is ommitted, the
    data document is constructed as though you called "get" with default
    options (but this document is not saved to a file)

    '''
    fname = args[0]
    if 'd' in opts:
        doc = gio.read(opts['d'])
    else:
        doc = getTests()
    doc = reducedDoc(doc)
    if not '.' in fname:
        fname = fname + ".gic"
    gio.write(doc, fname)
示例#2
0
def reduce(d, keep=('condition', 'cell', 'stim_type', 'stim_atten'), require=(), writefile='bicIC/reduced.gic'):
    #require e.g. (('stim_atten', 0.0),)
    d2 = gd.Doc()
    casenames = {}
    cname = 0
    for k in d.keys():
        if not type(d[k]) == gd.Doc:
            continue
        skip = False
        for c in require:
            if not c[1] == d[k + '.' + c[0]]:
                skip = True
                #print("%s fails condr=RasterGrid(1, len(rgrid[0]))itions that %s = %s (it is %s)" % (k, c[0], str(c[1]), str(d[k+'.'+c[0]])))
                break
        if skip:
            continue
        s = tuple([d[k + '.' + ke] for ke in keep])
        if s in casenames:
            nn = casenames[s]
        else:
            nn = 't%i' % cname
            cname += 1
            casenames[s] = nn
            for i in range(len(s)):
                d2.set(nn + '.' + keep[i], s[i])
        nn = nn + '.evts'
        if d2[nn]:
            d2[nn] = d2[nn] + d[k + '.evts']
        else:
            d2[nn] = d[k + '.evts']
    if writefile:
        gio.write(d, os.path.join(BASEDIR, writefile))
    return d2
示例#3
0
文件: legacy.py 项目: gic888/gdblocks
def get(opts, args):
    '''
    get loads all data specified in a data sheet from a set of PST files, and
    saves the resulting document to an output file. Usage is:

    get [-d path] [-s path] outfilename

    outfilename specifies where to save the output. The type of this file is
    inferred from its extension (if there is no "." in outfilename, ".gic" is
    used by default).

    -d path specifies to use a data directory of "path". The various "Mouse..."
    directory trees containing PST files should be children of path

    -s path specifies to use a datasheet (ods spreadsheet) that is stored at
    path.

    by default, -d and -s paths use the module level parameters basedir and
    dsheet_path (which currently assume that you have system with a HOME, the
    project directory is ~/project/christine, and the datasheet is in this
    directory, and is named DataSheet.ods) .

    '''
    bdir = opts.get('d') or basedir
    dsheet = opts.get('s') or dsheet_path
    fname = args[0]
    if not '.' in fname:
        fname = fname + ".gic"
    doc = getTests(dsheet, bdir)
    gio.write(doc, fname)
示例#4
0
def condition(dname='bicIC', sheet='datasheet.ods', tab='sheet1.table', cellid='cell', mouseid='data',
              testn='test', cond='condition', pstdirp='Mouse ', redundantdirs=True, writefile='conditioned.gic',
              condgroup=int, stimchan='stim.ch0'):
    '''
    Return a data document containing every test specified in the data sheet
    "sheet". "dname" indicates a directory (subdirectory of BASEDIR) to search for
    the data sheet and data files (or "mouse" directories).

    tab, cellid, mouseid, testn, and cond specify the layout of the sheet (which
    table is used and what the column labels for the relevant metadata are. These
    can be left as default values if using the sort of sheet Zach Mayko and I
    (Graham Cummins) have typically been using. Pstdirp and redundantdirs specify
    the layout of the data directory structure, and again can remain at default if
    your structure looks like Christine Portfor's typical layout. Writefile
    specifies a file name to store the new document in (or omit it to not save the
    doc).

    condgroup is a function that is applied to the value of the "condition" metadata
    The default (cast to int) is OK if condition labels are integers, and all distinctly
    labeled conditions should be treated differently (otherwise, use a function that
    makes similarity classes in some way, using the raw values of "condition").

    Stimchan specifies where the relevant stimulus data is stored by Batlab.
    This code assumes a single channel stimulus on channel 0. Although this
    parameter can be changed to deal with single channels on some other
    channel, any significant change to the stimulus will probably break
    most code in this module.

    '''
    dname = os.path.join(BASEDIR, dname)
    ds = gio.read(os.path.join(dname, sheet))[tab]
    l = list(ds[0, :])
    try:
        cellcol = [i for (i, s) in enumerate(l) if s.lower().startswith(cellid)][0]
        mousecol = [i for (i, s) in enumerate(l) if s.lower().startswith(mouseid)][0]
        testcol = [i for (i, s) in enumerate(l) if s.lower().startswith(testn)][0]
        condcol = [i for (i, s) in enumerate(l) if s.lower().startswith(cond)][0]
    except IndexError:
        raise KeyError('Data sheet doesnt contain the specified columns')
    d = gd.Doc()
    dfiles = {}
    for i in range(1, ds.shape[0]):
        l = ds[i, :]
        try:
            cid = int(l[cellcol])
            mid = l[mousecol]
            cond = l[condcol]
            if condgroup:
                cond = condgroup(cond)
            tests = _numOrRan(l[testcol])
        except:
            report('failed to parse data sheet line %i' % i)
            continue
        if not mid in dfiles:
            pstn = pstdirp + mid + '.pst'
            if redundantdirs:
                pstn = os.path.join(pstdirp + mid, pstn)
            pstn = os.path.join(dname, pstn)
            try:
                dfiles[mid] = gio.read(pstn)
                report('loading %s' % pstn)
            except:
                report('failed to open data file for %s (tried path %s)' % (mid, pstn))
                dfiles[mid] = 'BAD'
        if dfiles[mid] == 'BAD':
            continue
        metas = {'animal': mid, 'condition': cond, 'cell': cid}
        for it in tests:
            otn = 'test%i' % it
            try:
                trd = traces(dfiles[mid], otn, stimchan)
            except:
                report("Cant find a test %s for penetration %s" % (otn, mid))
                continue
            for trn in trd:
                tr = trd[trn]
                tr.update(metas)
                nn = "r%s_te%itr%i" % (mid, it, trn)
                d.set(nn, tr)
    if writefile:
        gio.write(d, os.path.join(dname, writefile))
    return d