-
Notifications
You must be signed in to change notification settings - Fork 390
Include background component indices when removing empty/nan components in spatial.py #1422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Include background component indices when removing empty/nan components in spatial.py #1422
Conversation
|
We're likely to merge this after the next release; if you can test this the best you can with a variety of settings in the meantime that'd be great. Sorry for the delay. |
I'm pretty sure now that this is correct and the code works as designed with this fix. It's pretty clearly intentional later in CaImAn/caiman/source_extraction/cnmf/spatial.py Lines 171 to 173 in 4a22789
And this makes sense based on the problem statement in CaImAn/caiman/source_extraction/cnmf/spatial.py Lines 285 to 288 in 4a22789
Furthermore, in the case where A_in is not boolean, the input background spatial components CaImAn/caiman/source_extraction/cnmf/spatial.py Lines 1023 to 1029 in 4a22789
I usually don't supply By the way, in #1539, @zyyk78 you state that this line in ind2_ = [iid_ if (np.size(iid_) > 0) and (np.min(iid_) < nr) else [] for iid_ in ind2_]However, this isn't true. Note that the condition is |
To be honest, this ind2_ may include background components, and this may cause errors like it . But i don't understand why i didn't meet this while using without binary masks (maybe removing empty component is very rare in that case ?) |
I think because if you pass if b is None:
dist_indicator = determine_search_location(
A_in, dims, method=method, min_size=min_size, max_size=max_size, dist=dist, expandCore=expandCore, dview=dview) which just looks at the spatial components and doesn't try to add any indices for the background components. But as I said above, this doesn't seem correct to me. |
|
FYI, I'll keep an eye on the discussion and most likely will merge this after Manuel's current PR lands, before the next release, unless the discussion moves towards a conclusion to fix it a different way. |
|
I think what I would like to do at some point is add tests for both the boolean and non-boolean seed cases, confirm that it currently fails for the boolean case, and see whether the results are also weird (or erroring) for the non-boolean case due to not starting with the background components included. I suspect the code for that case can be simplified to make it more like the boolean case, aside from binarizing the masks, but I want to see whether it's actually currently broken first. |
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_inis 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.