navis 1.4.0
  • Install
  • Quickstart
  • Tutorials
  • API
  • Changelog
  • Github
  • Ecosystem
  • Site
    • Page
        • navis.write_nrrd
          • write_nrrd()

    navis.write_nrrd¶

    navis.write_nrrd(x, filepath, compression_level=3, attrs=None)[source]¶

    Write VoxelNeurons or Dotprops to NRRD file(s).

    Parameters:
    • x (VoxelNeuron | Dotprops | NeuronList) – If multiple neurons, will generate a NRRD file for each neuron (see also filepath).

    • filepath (str | pathlib.Path | list thereof) – Destination for the NRRD files. See examples for options. If x is multiple neurons, filepath must either be a folder, a “formattable” filename (see Examples) or a list of filenames (one for each neuron in x). Existing files will be overwritten!

    • compression_level (int 1-9) – Lower = faster writing but larger files. Higher = slower writing but smaller files.

    • attrs (dict) – Any additional attributes will be written to NRRD header.

    Return type:

    Nothing

    Examples

    Save a single neuron to a specific file:

    >>> import navis
    >>> n = navis.example_neurons(1, kind='skeleton')
    >>> vx = navis.voxelize(n, pitch='2 microns')
    >>> navis.write_nrrd(vx, tmp_dir / 'my_neuron.nrrd')
    

    Save multiple neurons to a folder (must exist). Filenames will be autogenerated as “{neuron.id}.nrrd”:

    >>> import navis
    >>> nl = navis.example_neurons(5, kind='skeleton')
    >>> dp = navis.make_dotprops(nl, k=5)
    >>> navis.write_nrrd(dp, tmp_dir)
    

    Save multiple neurons to a folder but modify the pattern for the autogenerated filenames:

    >>> import navis
    >>> nl = navis.example_neurons(5, kind='skeleton')
    >>> vx = navis.voxelize(nl, pitch='2 microns')
    >>> navis.write_nrrd(vx, tmp_dir / 'voxels-{neuron.name}.nrrd')
    

    Save multiple neurons to a zip file:

    >>> import navis
    >>> nl = navis.example_neurons(5, kind='skeleton')
    >>> vx = navis.voxelize(nl, pitch='2 microns')
    >>> navis.write_nrrd(vx, tmp_dir / 'neuronlist.zip')
    

    Save multiple neurons to a zip file but modify the filenames:

    >>> import navis
    >>> nl = navis.example_neurons(5, kind='skeleton')
    >>> vx = navis.voxelize(nl, pitch='2 microns')
    >>> navis.write_nrrd(vx, tmp_dir / 'voxels-{neuron.name}.nrrd@neuronlist.zip')
    

    See also

    navis.read_nrrd()

    Import VoxelNeuron from NRRD files.

    Back to top

    Source

    © Copyright 2018, Philipp Schlegel.
    Created using Sphinx 5.3.0.