Pickling¶
All neuron types including navis.NeuronList
can be pickled. If you don’t know what that is: pickling is storing the actual Python object as a bytes stream. This is incredibly fast and works very well for short-term storage but has a few downsides:
Can only be re-opened in Python
Is (sort of) specific to the current version of
navis
- i.e. may not work with future versions of navis
With that in mind, pickling is incredibly easy:
import navis
import pickle
# Load some example neurons
nl = navis.example_neurons(3, kind='mesh')
# Pickle neurons to file
with open('/Users/philipps/Downloads//meshes.pkl', 'wb') as f:
pickle.dump(nl, f)
# Read neurons back from pickle file
with open('/Users/philipps/Downloads//meshes.pkl', 'rb') as f:
nl = pickle.load(f)
nl
type | name | id | units | n_vertices | n_faces | |
---|---|---|---|---|---|---|
0 | navis.MeshNeuron | DA1_lPN_R | 1734350788 | 8 nanometer | 6309 | 13054 |
1 | navis.MeshNeuron | DA1_lPN_R | 1734350908 | 8 nanometer | 7098 | 14620 |
2 | navis.MeshNeuron | DA1_lPN_R | 722817260 | 8 nanometer | 6582 | 13772 |
Hopefully the above has given you some entry points on how to load and save your data. See also the I/O API reference api_io>.