示例#1
0
文件: tests.py 项目: jdcourcol/NeuroM
def test_get_config():
    #get the default
    default = {'default': 'config'}
    config = get_config(None, default)
    nt.eq_(config, default)

    #load valid yaml
    test_yaml = os.path.abspath(os.path.join(os.path.dirname(__file__),
                                '../../../apps/config/morph_stats.yaml'))
    config = get_config(test_yaml, default)
示例#2
0
文件: tests.py 项目: yamagatm/NeuroM
def test_get_config():
    #get the default
    default = {'default': 'config'}
    config = get_config(None, default)
    nt.eq_(config, default)

    #load valid yaml
    test_yaml = os.path.abspath(
        os.path.join(os.path.dirname(__file__),
                     '../../../apps/config/morph_stats.yaml'))
    config = get_config(test_yaml, default)
示例#3
0
def test_get_config():
    # get the default

    test_yaml = os.path.abspath(os.path.join(os.path.dirname(__file__),
                                             '../../config/morph_stats.yaml'))

    expected = {'neurite': {'section_lengths': ['max', 'total'], 'section_volumes': ['total'], 'section_branch_orders': ['max']}, 'neurite_type': ['AXON', 'APICAL_DENDRITE', 'BASAL_DENDRITE', 'ALL'], 'neuron': {'soma_radii': ['mean']}}

    config = get_config(None, test_yaml)
    nt.assert_equal(config, expected)

    config = get_config(test_yaml, '')
    nt.assert_equal(config, expected)
示例#4
0
def main(datapath, config, output_file, is_full_config, as_population,
         ignored_exceptions):
    """Main function that get statistics for morphologies.

    Args:
        datapath (str|Path): path to a morphology file or folder
        config (str|Path): path to a statistics config file
        output_file (str|Path): path to output the resulted statistics file
        is_full_config (bool): should be statistics made over all possible features, modes, neurites
        as_population (bool): treat ``datapath`` as directory of morphologies population
        ignored_exceptions (list|tuple|None): exceptions to ignore when loading a morphology
    """
    if is_full_config:
        config = full_config()
    else:
        try:
            config = get_config(config, EXAMPLE_CONFIG)
            config = sanitize_config(config)
        except ConfigError as e:
            L.error(e)
            raise

    if ignored_exceptions is None:
        ignored_exceptions = ()
    ignored_exceptions = tuple(IGNORABLE_EXCEPTIONS[k]
                               for k in ignored_exceptions)
    neurons = nm.load_neurons(get_files_by_path(datapath),
                              ignored_exceptions=ignored_exceptions)

    results = {}
    if as_population:
        results[datapath] = extract_stats(neurons, config)
    else:
        for neuron in tqdm(neurons):
            results[neuron.name] = extract_stats(neuron, config)

    if not output_file:
        print(
            json.dumps(results,
                       indent=2,
                       separators=(',', ':'),
                       cls=NeuromJSON))
    elif output_file.endswith('.json'):
        with open(output_file, 'w') as f:
            json.dump(results, f, cls=NeuromJSON)
    else:
        with open(output_file, 'w') as f:
            csvwriter = csv.writer(f)
            header = get_header(results)
            csvwriter.writerow(header)
            for line in generate_flattened_dict(header, dict(results)):
                csvwriter.writerow(line)
示例#5
0
def main(datapath, config, output):
    """Main function that checks morphologies.

    Args:
        datapath (str|Path): path to a morphology file or folder
        config (str|Path): path to a statistics config file
        output (str|Path): path to output the resulted checks file
    """
    config = get_config(config, EXAMPLE_CONFIG)
    checker = CheckRunner(config)
    summary = checker.run(datapath)
    with open(output, 'w') as json_output:
        json.dump(summary, json_output, indent=4)
示例#6
0
def test_get_config():
    # get the default

    test_yaml = Path(
        __file__).parent.parent.parent / 'neurom/apps/config/morph_stats.yaml'

    expected = {
        'neurite': {
            'section_lengths': ['max', 'total'],
            'section_volumes': ['total'],
            'section_branch_orders': ['max']
        },
        'neurite_type': ['AXON', 'APICAL_DENDRITE', 'BASAL_DENDRITE', 'ALL'],
        'neuron': {
            'soma_radii': ['mean']
        }
    }

    config = get_config(None, test_yaml)
    assert config == expected

    config = get_config(test_yaml, '')
    assert config == expected
示例#7
0
文件: tests.py 项目: yamagatm/NeuroM
def test_get_config_exception():
    #current python file isn't a yaml file
    get_config(__file__, {})
示例#8
0
文件: tests.py 项目: jdcourcol/NeuroM
def test_get_config_exception():
    #current python file isn't a yaml file
    get_config(__file__, {})
示例#9
0
def test_get_config_exception():
    """current python file isn't a yaml file."""
    with pytest.raises(ConfigError):
        get_config(__file__, {})