Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds an interface for masking neurons for analyses/processing:
NeuronMask
context managerThe interface currently looks like this:
A few additional notes:
mask
can be a boolean array, a neuron property (e.g. a column in the node table), or a function that takes a neuron and returns one of the first twoNeuronMask
context manager is the primary interface but people can also mess around with.mask()
+.unmask()
if they need more control.apply_mask()
method that makes the mask permanent.Modifying masked neurons
By default, unmasking will reset the neuron to its original state. Users can use e.g.
.unmask(reset=False)
orNeuronMask(..., reset=False)
to instead re-combine the masked and unmasked data. That works well for non-destructive operations such as e.g. smoothing or downsampling where the boundary vertices/nodes are not modified:Destructive operations (e.g.
navis.prune_twigs
) are more tricky and I think we may end up having to adjust those functions to deal with masked neurons as special cases. To give you an example: skeletonization of neurons often leaves ugly spikes where the soma is. These could be removed by masking the neuron to within a given radius of the soma and removing all twigs below a given threshold. However, with the current implementation the actual neurites coming off the soma would also look awfully like twigs and might incorrectly get pruned off - which in turn will break the connectivity of the skeleton. Perfectly solvable problem but I'm still thinking about a generalizable approach that would minimize maintenance burden.Comments/thoughts, @ceesem @bdpedigo?