neurom.io.utils¶
Utility functions and for loading neurons.
Functions
Get a file or set of files from a file path. |
|
Get a list of all morphology files in a directory. |
|
Build section trees from a neuron or a h5, swc or asc file. |
|
Create a population object. |
Classes
Class representing a simple neuron. |
|
Caching morphology loader. |
|
Neuron Population Class. |
Exceptions
Base class for NeuroM errors. |
-
class
neurom.io.utils.
Neuron
(filename, name=None)[source]¶ Bases:
morphio._morphio.mut.Morphology
Class representing a simple neuron.
-
class
neurom.io.utils.
NeuronLoader
(directory, file_ext=None, cache_size=None)[source]¶ Bases:
object
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)
-
class
neurom.io.utils.
Population
(neurons, name='Population')[source]¶ Bases:
object
Neuron Population Class.
- Features:
flattened collection of neurites.
collection of somas, neurons.
iterable-like iteration over neurons.
-
neurom.io.utils.
get_files_by_path
(path)[source]¶ Get a file or set of files from a file path.
Return list of files with path
-
neurom.io.utils.
get_morph_files
(directory)[source]¶ 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_neuron
(neuron, reader=None)[source]¶ Build section trees from a neuron or a h5, swc or asc file.
- Parameters
neuron (str|Path|Neuron|morphio.Morphology|morphio.mut.Morphology) –
A neuron 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 neuron is a stream to specify the file format (asc, swc, h5)
- Returns
A Neuron object
Examples:
neuron = neurom.load_neuron('my_neuron_file.h5') neuron = neurom.load_neuron(morphio.Morphology('my_neuron_file.h5')) neuron = nm.load_neuron(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')
-
neurom.io.utils.
load_neurons
(neurons, neuron_loader=<function load_neuron>, name=None, population_class=<class 'neurom.core.population.Population'>, ignored_exceptions=())[source]¶ Create a population object.
From all morphologies in a directory of from morphologies in a list of file names.
- Parameters
neurons – directory path or list of neuron file paths
neuron_loader – function taking a filename and returning a neuron
population_class – class representing populations
name (str) – optional name of population. By default ‘Population’ or filepath basename depending on whether neurons is list or directory path respectively.
ignored_exceptions (tuple) – NeuroM and MorphIO exceptions that you want to ignore when loading neurons.
- Returns
neuron population object