Include background component indices when removing empty/nan components in spatial.py #1422
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.
Description
This fixes an indexing error in the "Eliminating empty and nan components" step that occurs when using seeded CNMF. The error I was getting is as follows:
It looks like this is happening because when
A_in
is provided and has type bool, the following lines add indices corresponding to the spatial components (>=nr
) to non-empty entries ofind2_
:CaImAn/caiman/source_extraction/cnmf/spatial.py
Lines 1066 to 1067 in ce2cb17
However, the code to remove empty components assumes that the highest original component number is
nr-1
:CaImAn/caiman/source_extraction/cnmf/spatial.py
Lines 183 to 187 in ce2cb17
To fix this, I changed this to use
nr + nb
. However, I'm not 100% sure that the behavior of adding indices for background components is correct in the first place, since it seems inconsistent with what happens with no masks passed in.Type of change
Please delete options that are not relevant.
Has your PR been tested?
The CNMF run I that was failing for me before now succeeds. Since there wasn't a failing test before, I'm guessing this part of the code (under the condition of seeded CNMF) wasn't being tested, which could be changed.