def main(sign, label):
    """
    show group sizes in h5files
    """
    files = h5files(os.getcwd())
    n_arti_total = 0
    for fname in files:
        man = Combinato(fname, sign, label)
        if not man.initialized:
            continue
        groups = man.get_groups(times=False, spikes=False)
        if 0 in groups.keys():
            n_unassigned = len(groups[0])
        if -1 in groups.keys():
            n_arti = len(groups[-1])
        else:
            n_arti = 0


        print('{} {} groups, {} artifacts'.
              format(os.path.basename(fname), len(groups), n_arti))

        n_arti_total += n_arti

    return n_arti_total
def parse_args():
    """
    standard command line parsing
    """
    from argparse import ArgumentParser

    parser = ArgumentParser()
    parser.add_argument('--label', required=True)
    parser.add_argument('--h5file')
    parser.add_argument('--neg', action='store_true', default=False)
    parser.add_argument('--no-info', action='store_true', default=False)
    parser.add_argument('--drop-artifacts', action='store_true', default=False)

    args = parser.parse_args()
    label = args.label
    sign = 'neg' if args.neg else 'pos'
    do_info = not args.no_info
    drop_artifacts = args.drop_artifacts

    if args.h5file is None:
        rel_h5files = h5files(os.getcwd())
    else:
        rel_h5files = [args.h5file]

    # for cluster_info.mat:
    all_info = [[None] * len(rel_h5files), [None] * len(rel_h5files)]

    if do_info:
        session_name = os.path.dirname(rel_h5files[0])
        date = time.strftime('%Y-%m-%d_%H:%M:%S')
        csvfile = open('cluster_info.csv', 'w')
        writer = csv.writer(csvfile)
        writer.writerow(
            ['# Session:  {}, Converted: {}'.format(session_name, date)])
        writer.writerow([
            '# For Artifacts, 0 means there are none, 1 means '
            'they are included as clusters (type -1), 2 means '
            'they are included as unassigned (type 0)'
        ])
        writer.writerow([
            '# For Unassigned, 1 means they exist, 0 means they '
            'do not exist.'
        ])
        writer.writerow([
            '# For Clusters, 1 means multi-unit, 2 means '
            'single-unit, -1 means artifact'
        ])
        writer.writerow([
            'ChannelNumber', 'ChannelName', 'Artifacts', 'Unassigned',
            'Cluster1', 'Cluster2', '...'
        ])

    for dfile in rel_h5files:
        basedir = os.path.dirname(dfile)
        basename = os.path.basename(dfile)
        sorting_path = os.path.join(basedir, label)
        outfname = basename[5:-3]
        info = main(dfile, sorting_path, sign, outfname, drop_artifacts)
        if do_info and (info is not None):
            writer.writerow(info)
            all_info[0][rel_h5files.index(dfile)] = info[4:]
            all_info[1][rel_h5files.index(dfile)] = info[1]

    if do_info:
        info_dict = {
            'cluster_info':
            all_info,
            'label_info':
            ' 1 = MU\n 2 = SU\n-1 = Artif.\nRefers to '
            '"cluster_class"-values 1 and up.\nIgnores Unassigned '
            '(value 0)'
        }
        info_fname = "cluster_info.mat"
        savemat(info_fname, info_dict)
Exemplo n.º 3
0
def parse_args():
    """
    standard command line parsing
    """
    from argparse import ArgumentParser

    parser = ArgumentParser()
    parser.add_argument('--label', required=True)
    parser.add_argument('--h5file' )
    parser.add_argument('--neg', action='store_true', default=False)
    parser.add_argument('--no-info', action='store_true', default=False)
    parser.add_argument('--drop-artifacts', action='store_true',
                        default=False)

    args = parser.parse_args()
    label = args.label
    sign = 'neg' if args.neg else 'pos'
    do_info = not args.no_info
    drop_artifacts = args.drop_artifacts

    if args.h5file is None:
        rel_h5files = h5files(os.getcwd())
    else:
        rel_h5files = [args.h5file]

    # for cluster_info.mat:
    all_info = [[None]*len(rel_h5files), [None]*len(rel_h5files)]

    if do_info:
        session_name = os.path.dirname(rel_h5files[0])
        date = time.strftime('%Y-%m-%d_%H:%M:%S')
        csvfile = open('cluster_info.csv', 'w')
        writer = csv.writer(csvfile)
        writer.writerow(['# Session:  {}, Converted: {}'.
            format(session_name, date)])
        writer.writerow(['# For Artifacts, 0 means there are none, 1 means '
                         'they are included as clusters (type -1), 2 means '
                         'they are included as unassigned (type 0)'])
        writer.writerow(['# For Unassigned, 1 means they exist, 0 means they '
                         'do not exist.'])
        writer.writerow(['# For Clusters, 1 means multi-unit, 2 means '
                         'single-unit, -1 means artifact'])
        writer.writerow(['ChannelNumber', 'ChannelName', 'Artifacts',
                         'Unassigned', 'Cluster1', 'Cluster2', '...'])

    for dfile in rel_h5files:
        basedir = os.path.dirname(dfile)
        basename = os.path.basename(dfile)
        sorting_path = os.path.join(basedir, label)
        outfname = basename[5:-3]
        info = main(dfile, sorting_path, sign, outfname, drop_artifacts)
        if do_info and (info is not None):
            writer.writerow(info)
            all_info[0][rel_h5files.index(dfile)] = info[4:]
            all_info[1][rel_h5files.index(dfile)] = info[1]

    if do_info:
        info_dict = {'cluster_info': all_info, 'label_info':
                     ' 1 = MU\n 2 = SU\n-1 = Artif.\nRefers to '
                     '"cluster_class"-values 1 and up.\nIgnores Unassigned '
                     '(value 0)'}
        info_fname = "cluster_info"
        savemat(info_fname, info_dict)