neurom.io.utils

Utility functions and for loading morphs.

Functions

get_files_by_path(path)

Get a file or set of files from a file path.

get_morph_files(directory)

Get a list of all morphology files in a directory.

load_morphologies(morphs[, name, ...])

Create a population object.

load_morphology(morph[, reader, mutable, ...])

Build section trees from a morphology or a h5, swc or asc file.

Classes

MorphLoader(directory[, file_ext, cache_size])

Caching morphology loader.

class neurom.io.utils.MorphLoader(directory, file_ext=None, cache_size=None)

Caching morphology loader.

Parameters:
  • directory – path to directory with morphology files

  • file_ext – file extension to look for (if not set, will pick any of .swc|.h5|.asc)

  • cache_size – size of LRU cache (if not set, no caching done)

Initialize a MorphLoader object.

get(name)

Get name morphology data.

neurom.io.utils.get_files_by_path(path)

Get a file or set of files from a file path.

Return list of files with path

neurom.io.utils.get_morph_files(directory)

Get a list of all morphology files in a directory.

Returns:

list with all files with extensions ‘.swc’ , ‘h5’ or ‘.asc’ (case insensitive)

neurom.io.utils.load_morphologies(morphs, name=None, ignored_exceptions=(), *, cache=False, process_subtrees=False)

Create a population object.

From all morphologies in a directory of from morphologies in a list of file names.

Parameters:
  • morphs (str|Path|Iterable[Path]) – path to a folder or list of paths to morphology files

  • name (str) – optional name of population. By default ‘Population’ or filepath basename depending on whether morphologies is list or directory path respectively.

  • ignored_exceptions (tuple) – NeuroM and MorphIO exceptions that you want to ignore when loading morphologies

  • cache (bool) – whether to cache the loaded morphologies in memory

  • process_subtrees (bool) – enable mixed tree processing if set to True

Returns:

population object

Return type:

Population

neurom.io.utils.load_morphology(morph, reader=None, *, mutable=None, process_subtrees=False)

Build section trees from a morphology or a h5, swc or asc file.

Parameters:
  • morph (str|Path|Morphology|morphio.Morphology|morphio.mut.Morphology) –

    a morphology representation. It can be:

    • a filename with the h5, swc or asc extension

    • a NeuroM Neuron object

    • a morphio mutable or immutable Morphology object

    • a stream that can be put into a io.StreamIO object. In this case, the READER argument must be passed with the corresponding file format (asc, swc and h5)

  • reader (str) – Optional, must be provided if morphology is a stream to specify the file format (asc, swc, h5)

  • mutable (bool|None) – Whether to enforce mutability. If None and a morphio/neurom object is passed, the initial mutability will be maintained. If None and the morphology is loaded, then it will be immutable by default.

  • process_subtrees (bool) – enable mixed tree processing if set to True

Returns:

A Morphology object

Examples:

morphology = neurom.load_morphology('my_morphology_file.h5')
morphology = neurom.load_morphology(morphio.Morphology('my_morphology_file.h5'))
morphology = nm.load_morphology(io.StringIO('''((Dendrite)
                                       (3 -4 0 2)
                                       (3 -6 0 2)
                                       (3 -8 0 2)
                                       (3 -10 0 2)
                                       (
                                         (0 -10 0 2)
                                         (-3 -10 0 2)
                                         |
                                         (6 -10 0 2)
                                         (9 -10 0 2)
                                       )
                                       )'''), reader='asc')