示例#1
0
def sanitize_all(input_folder, output_folder, nprocesses=1):
    '''Sanitize all morphologies in input_folder and its sub-directories.

    See :func:`~neuror.sanitize.sanitize` for more information on the sanitization process.

    Args:
        input_folder (str|pathlib.Path): input neuron
        output_folder (str|pathlib.Path): output name

    .. note:: the sub-directory structure is maintained.
    '''
    set_maximum_warnings(0)

    morphologies = list(iter_morphologies(Path(input_folder)))
    func = partial(_sanitize_one,
                   input_folder=input_folder,
                   output_folder=output_folder)
    if nprocesses == 1:
        results = map(func, morphologies)
    else:
        results = Pool(nprocesses).imap_unordered(func,
                                                  morphologies,
                                                  chunksize=100)
    errored_paths = list(filter(None, tqdm(results, total=len(morphologies))))
    if errored_paths:
        L.info('Files in error:')
        for path in errored_paths:
            L.info(path)
示例#2
0
def sanitize_all(input_folder, output_folder, nprocesses=1):
    '''Sanitize all morphologies in input_folder and its sub-directories.

    Note: the sub-directory structure is maintained.

    - fixes non zero segments
    - raises if the morphology has no soma
    - raises if the morphology has negative diameters

    Args:
        input_folder (str|pathlib.Path): input neuron
        output_folder (str|pathlib.Path): output name
    '''
    set_maximum_warnings(0)

    morphologies = list(iter_morphologies(Path(input_folder)))
    func = partial(_sanitize_one,
                   input_folder=input_folder,
                   output_folder=output_folder)
    if nprocesses == 1:
        results = map(func, morphologies)
    else:
        results = Pool(nprocesses).imap_unordered(func,
                                                  morphologies,
                                                  chunksize=100)
    errored_paths = list(filter(None, tqdm(results, total=len(morphologies))))
    if errored_paths:
        L.info('Files in error:')
        for path in errored_paths:
            L.info(path)
示例#3
0
def test_run_converter():
    for ext_in in ['asc', 'swc', 'h5']:
        assert_conversion_works(os.path.join(_path,
                                             'circle_contour.' + ext_in))

    # # real_neuron.asc prints a lot of warning that we do not care about
    set_maximum_warnings(0)
    assert_conversion_works(os.path.join(_path, 'real_neuron.asc'))
    assert_conversion_works(os.path.join(_path, 'real_neuron2.asc'))
示例#4
0
def test_convert_file(tmpdir):
    set_maximum_warnings(0)
    runner = CliRunner()
    filename = Path(DATA, 'simple.asc')
    output_name = Path(tmpdir, 'simple.h5')
    result = runner.invoke(
        cli,
        ['convert', 'file', str(filename),
         str(output_name)])
    assert result.exit_code == 0, result.exception
    assert output_name.exists()
示例#5
0
def test_convert():
    set_maximum_warnings(0)
    with setup_tempdir('test-convert-file') as tmp_dir:
        runner = CliRunner()
        filename = Path(DATA, 'simple.asc')
        output_name = Path(tmp_dir, 'simple.h5')
        result = runner.invoke(cli, ['convert', 'file', str(filename), str(output_name)])
        assert_equal(result.exit_code, 0, result.exception)
        ok_(output_name.exists())


    with setup_tempdir('test-convert-folder') as tmp_dir:
        runner = CliRunner()
        result = runner.invoke(cli, ['convert', 'folder', '-ext', 'swc',
                                     str(DATA / 'input-convert'), tmp_dir])
        assert_equal(result.exit_code, 0, result.exc_info)

        n_converted_files = len(list(Path(tmp_dir).rglob('**/*.swc')))

        assert_equal(n_converted_files, 2)