navis.read_mesh¶
- navis.read_mesh(f, include_subdirs=False, parallel='auto', output='neuron', errors='log', limit=None, **kwargs)[source]¶
Create Neuron/List from mesh.
This is a thin wrapper around trimesh.load_mesh which supports most common formats (obj, ply, stl, etc.).
- Parameters:
f (str | iterable) – Filename(s) or folder. If folder must include file extension (e.g. my/dir/*.ply).
include_subdirs (bool, optional) – If True and
f
is a folder, will also search subdirectories for meshes.parallel ("auto" | bool | int,) – Defaults to
auto
which means only use parallel processing if more than 100 mesh files are imported. Spawning and joining processes causes overhead and is considerably slower for imports of small numbers of neurons. Integer will be interpreted as the number of cores (otherwise defaults toos.cpu_count() - 2
).output ("neuron" | "volume" | "trimesh") – Determines function’s output. See Returns.
errors ("raise" | "log" | "ignore") – If “log” or “ignore”, errors will not be raised.
limit (int, optional) – If reading from a folder you can use this parameter to read only the first
limit
files. Useful when wanting to get a sample from a large library of meshes.**kwargs – Keyword arguments passed to
navis.MeshNeuron
ornavis.Volume
. You can use this to e.g. set the units on the neurons.
- Returns:
navis.MeshNeuron – If
output="neuron"
(default).navis.Volume – If
output="volume"
.trimesh.Trimesh – If
output='trimesh'
.navis.NeuronList – If
output="neuron"
and import has multiple meshes will return NeuronList of MeshNeurons.list – If
output!="neuron"
and import has multiple meshes will return list of Volumes or Trimesh.
Examples
Read a single file into
navis.MeshNeuron
:>>> m = navis.read_mesh('mesh.obj')
Read all e.g. .obj files in a directory:
>>> nl = navis.read_mesh('/some/directory/*.obj')
Sample first 50 files in folder:
>>> nl = navis.read_mesh('/some/directory/*.obj', limit=50)
Read single file into
navis.Volume
:>>> nl = navis.read_mesh('mesh.obj', output='volume')