schnitzer-lab / EXTRACT-public

EXTRACT is a tractable and robust automated cell extraction tool for calcium imaging, which extracts the activities of cells as time series from both one-photon and two-photon calcium imaging movies.
MIT License
62 stars 16 forks source link

sudden change in baseline/variance for individual footprints at file stitch boundaries #38

Closed abahle closed 1 year ago

abahle commented 1 year ago

I am using EXTRACT on several movies of the same neurons collected throughout one day in which a bird may be performing different actions. this seems to work pretty while despite the instantaneous jumps in files which can cause discontinuities. However, it seems like many "good" units (by good i mean appear to be well segmented high snr etc) seem to have occasionally very different statistics for one or many of the files (see below). Do you have any suggestions about possible parameters that my ameliorate this problem? Thanks

Screen Shot 2023-01-27 at 2 17 46 PM Screen Shot 2023-01-27 at 2 16 56 PM Screen Shot 2023-01-27 at 2 16 15 PM
fatihdinc commented 1 year ago

Oh wow, this is the first time someone tried EXTRACT on birds. Thank you so much for reaching out!

Could you let me know whether you are concatenating the movies?

abahle commented 1 year ago

yep thats exactly what i am doing, the sudden changes here correspond to some but not all of the file junctions

fatihdinc commented 1 year ago

Ok, so here is one test I will propose: Let's assume M is the 3D movie and S= output.spatial_weights.

M = reshape(M,size(M,1)*size(M,2),[]); X = mean(M,2); M_new = (M-X) ./ X;

S = reshape(S,size(S,1)*size(S,2),[]);

T = (S^T S)^{-1} S^T M

Could you show some examples from T? I think that will be illuminating as to why you are observing this. Then, I can make some suggestions!

abahle commented 1 year ago

ok see four random examples attached

Screen Shot 2023-01-27 at 3 57 42 PM
fatihdinc commented 1 year ago

I would preprocess the movies individually and concatenate; and check if this helps you. Say your configs are in struct config. Then, you can preprocess the movie via

[M_proc,a] = preprocess_movie(M,config); M_proc = M_proc ./ a.F_per_pixel;

Then you concatenate these processed (dF/Fed and baseline corrected) movies. Hopefully this should help, it not please feel free to send over some example movies!

abahle commented 1 year ago

ok awesome thanks for you help! ill try this out and get back to you.

abahle commented 1 year ago

ok so that seems to have helped. Just a heads-up in the process i discovered that config.remove_baseline has a default value of false contrary to the readme. so setting that to true may have helped me a lot too. thanks for your help!

fatihdinc commented 1 year ago

Cool! I tend to not use it unless absolutely necessary, which was going to be my next suggestion. Glad it all worked out and good luck!