Example #1
0
def test_get_morph_files():
    ref = set(['Neuron_h5v2.h5', 'Neuron_2_branch_h5v2.h5',
               'Neuron.swc', 'Neuron_h5v1.h5', 'Neuron_2_branch_h5v1.h5'])

    FILE_PATH = os.path.abspath(os.path.join(DATA_PATH, 'valid_set'))
    files = set(os.path.basename(f) for f in utils.get_morph_files(FILE_PATH))

    nt.assert_equal(ref, files)
Example #2
0
def test_get_morph_files():
    ref = set([
        'Neuron_slice.h5', 'Neuron.swc', 'Neuron_h5v1.h5',
        'Neuron_2_branch_h5v1.h5'
    ])

    files = set(f.name for f in utils.get_morph_files(VALID_DATA_PATH))
    nt.assert_equal(ref, files)
Example #3
0
def test_get_morph_files():
    ref = set(['Neuron_h5v2.h5', 'Neuron_2_branch_h5v2.h5', 'Neuron_slice.h5',
               'Neuron.swc', 'Neuron_h5v1.h5', 'Neuron_2_branch_h5v1.h5'])

    FILE_PATH = os.path.abspath(os.path.join(DATA_PATH, 'valid_set'))
    files = set(os.path.basename(f) for f in utils.get_morph_files(FILE_PATH))

    nt.assert_equal(ref, files)
Example #4
0
def test_get_morph_files():
    ref = {
        'Neuron_slice.h5', 'Neuron.swc', 'Neuron_h5v1.h5',
        'Neuron_2_branch_h5v1.h5'
    }

    files = set(f.name for f in utils.get_morph_files(VALID_DATA_PATH))
    assert ref == files
Example #5
0
 def _get_files():
     '''Get a file or set of files from a file path'''
     if os.path.isfile(file_path):
         return [file_path]
     elif os.path.isdir(file_path):
         L.info('Checking files in directory %s', file_path)
         return get_morph_files(file_path)
     else:
         msg = 'Invalid data path %s' % file_path
         L.error(msg)
         raise IOError(msg)
Example #6
0
 def _get_files():
     '''Get a file or set of files from a file path'''
     if os.path.isfile(file_path):
         return [file_path]
     elif os.path.isdir(file_path):
         L.info('Checking files in directory %s', file_path)
         return get_morph_files(file_path)
     else:
         msg = 'Invalid data path %s' % file_path
         L.error(msg)
         raise IOError(msg)
Example #7
0
        ]),
    Component(
        'axon',
        [
            Feature('number', Limits(0, None)),
            Feature('segment_length', Limits(0, None)),
            Feature('initial_radius', Limits(0, None)),
            # Feature('taper_rate', Limits(0, None))
        ]),
]

if __name__ == '__main__':
    args = parse_args()

    data_dirs = args.datapaths

    mtype_getter = MTYPE_GETTERS.get(args.mtype, lambda f: 'UNKNOWN')

    for d in data_dirs:
        mtype_files = defaultdict(list)
        for f in get_morph_files(d):
            mtype_files[mtype_getter(f)].append(f)

        _results = [
            transform_package(mtype_, files_, COMPONENTS)
            for mtype_, files_ in mtype_files.items()
        ]

        for res in _results:
            print(json.dumps(res, indent=2), '\n')
Example #8
0
def load_neurons(directory):
    '''Create a list of Neuron objects from each morphology file in directory'''
    return [load_neuron(m) for m in get_morph_files(directory)]
Example #9
0

def plot_feature(feature, cell):
    '''Plot a feature
    '''
    fig = pl.figure()
    ax = fig.add_subplot(111)

    if cell is not None:
        try:
            histogram(cell, feature, ax)
        except ValueError:
            pass
        stylize(ax, cell.name, feature)
    return fig


if __name__ == '__main__':
    import os

    args = parse_args()

    for morph_file in get_morph_files(args.datapath):
        nrn = nm.load_neuron(morph_file)

        for _feature in args.features:
            f = plot_feature(_feature, nrn)
            figname = "{0}_{1}.eps".format(_feature, nrn.name)
            f.savefig(os.path.join(args.odir, figname))
            pl.close(f)
Example #10
0
                  Feature('initial_radius', Limits(0, None)),
                  # Feature('taper_rate', Limits(0, None))
              ]),
    Component('axon',
              [
                  Feature('number', Limits(0, None)),
                  Feature('segment_length', Limits(0, None)),
                  Feature('initial_radius', Limits(0, None)),
                  # Feature('taper_rate', Limits(0, None))
              ]),
]


if __name__ == '__main__':
    args = parse_args()

    data_dirs = args.datapaths

    mtype_getter = MTYPE_GETTERS.get(args.mtype, lambda f: 'UNKNOWN')

    for d in data_dirs:
        mtype_files = defaultdict(list)
        for f in get_morph_files(d):
            mtype_files[mtype_getter(f)].append(f)

        _results = [transform_package(mtype_, files_, COMPONENTS)
                    for mtype_, files_ in mtype_files.items()]

        for res in _results:
            print(json.dumps(res, indent=2), '\n')
Example #11
0
        try:
            histogram(cell, feature, ax)
        except ValueError:
            pass
        stylize(ax, cell.name, feature)
    return fig


if __name__ == "__main__":
    import numpy as np
    import os

    args = parse_args()
    nrns = []

    for j, neuronFile in enumerate(get_morph_files(args.datapath)):
        _name = os.path.splitext(os.path.split(neuronFile)[-1])[0]
        nrn = None

        try:
            soma = make_soma([np.array([11, 22, 33, 44, 1, 1, -1])])
            trees = load_trees(neuronFile)
            cn = coreNeuron(soma, trees, name=_name)
            nrn = ezyNeuron(cn)
        except IDSequenceError:
            pass

        for i, _feature in enumerate(args.features):

            f = plot_feature(_feature, nrn)
            figname = "{0}_{1}_{2}.eps".format(i, j, _name)
Example #12
0

def plot_feature(feature, cell):
    '''Plot a feature
    '''
    fig = pl.figure()
    ax = fig.add_subplot(111)

    if cell is not None:
        try:
            histogram(cell, feature, ax)
        except ValueError:
            pass
        stylize(ax, cell.name, feature)
    return fig


if __name__ == '__main__':
    import os

    args = parse_args()

    for morph_file in get_morph_files(args.datapath):
        nrn = nm.load_neuron(morph_file)

        for _feature in args.features:
            f = plot_feature(_feature, nrn)
            figname = "{0}_{1}.eps".format(_feature, nrn.name)
            f.savefig(os.path.join(args.odir, figname))
            pl.close(f)