Skip to content
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

CNMF notebook update #1075

Merged
merged 65 commits into from
Jan 25, 2024

Conversation

EricThomson
Copy link
Contributor

@EricThomson EricThomson commented May 3, 2023

Description

Updating CNMF demo notebook. This isn't a fix, but part of roadmap to revitalize all the major notebooks to include more explanation and generally increasing accessibility to the code base. This is part of:

  • Changes in documentation or new examples for demos and/or use cases.

Aims

This is a work in progress, will add more here as I work through it, but main goals for now:

  • Update introduction to explain the general workflow a bit mor
  • Explain logging mechanism (and use `caiman.paths: it is a very useful mechanism)
  • Unpack cluster setup a bit more (this is already pretty good)
  • Explore the movie object works it is a powerful feature of caiman
  • File types, how to run with your own data.
  • Explain parameter object basic initialization/mechanics.
  • Saving/loading is a common sticking point. What if you stop in the middle and want to start later?
  • What is memmapping what is F-order and C-order? Filename conventions, and address errors if people run multiple times.
  • Explain motion correction a little bit more
  • Explain CNMF, background model, and residual calculation a bit more
  • Explain how to explore parameter space with CNMF (mention mesmerize here)
  • Explain the estimates object more this is the crucial output of the algorithm.
  • Explain why refit? Why is this useful how does it work why does it exist?
  • Explain component evaluation/removal of false positives
  • Deconvolution parameters and model (this would be too much: leave for another day 😢)
  • How to run deconvolution after running cnmf to explore parameters (running simultaneously is better, do not do)
  • New image for intro workflow
  • DFoF calculation explain
  • Explain how to save results as csv
  • The final visualization elements are really useful explain them more.

@@ -4,7 +4,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"<html><head><meta content=\"text/html; charset=UTF-8\" http-equiv=\"content-type\"><style type=\"text/css\">ol</style></head><body class=\"c5\"><p class=\"c0 c4\"><span class=\"c3\"></span></p><p class=\"c2 title\" id=\"h.rrbabt268i6e\"><h1>CaImAn&rsquo;s Demo pipeline</h1></p><p class=\"c0\"><span class=\"c3\">This notebook will help to demonstrate the process of CaImAn and how it uses different functions to denoise, deconvolve and demix neurons from a two-photon Calcium Imaging dataset. The demo shows how to construct the `params`, `MotionCorrect` and `cnmf` objects and call the relevant functions. You can also run a large part of the pipeline with a single method (`cnmf.fit_file`). See inside for details.\n",
"# CNMF demo pipeline\n",
"This notebook will help to demonstrate the process of CaImAn and how it uses different functions to denoise, deconvolve and demix neurons from a two-photon Calcium Imaging dataset. The demo shows how to construct the `params`, `MotionCorrect` and `cnmf` objects and call the relevant functions. You can also run a large part of the pipeline with a single method (`cnmf.fit_file`). See inside for details.\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably change the wording to avoid the potentially confusing future tense here.

"This notebook demonstrates the process of using Caiman and how it uses different functions..."

@EricThomson EricThomson marked this pull request as draft May 3, 2023 17:08
@kushalkolar
Copy link
Collaborator

Thoughts:

Explain component evaluation/removal of false positives

This might be better done in a different nb entirely. I will eventually make a visualization for this in the mesmerize demo nbs, but it just uses the Estimates so it's easy to adapt for a nb in the caiman repo if you want. There are quite a few features that can be exposed better, such as merging components.

Deconvolution parameters and model (I may need some help with this)
How to run deconvolution after running cnmf to explore parameters.

Might be more organized in a separate nb?

DFoF calculation explain

Also a dedicate notebook with a longer discussion on this would be really useful. We could use some of the ideas from Peter Rupretch too.

@EricThomson
Copy link
Contributor Author

EricThomson commented May 4, 2023

Thoughts:

Explain component evaluation/removal of false positives

This might be better done in a different nb entirely. I will eventually make a visualization for this in the mesmerize demo nbs, but it just uses the Estimates so it's easy to adapt for a nb in the caiman repo if you want. There are quite a few features that can be exposed better, such as merging components.

Thanks Kushal yes probably shouldn't go down the rabbit hole with this, but was just thinking of adding a tad more explanation for the component evaluation step than is already there. Should probably be a separate notebook for a deep dive (that could easily be a very long notebook).

Deconvolution parameters and model (I may need some help with this)
How to run deconvolution after running cnmf to explore parameters.

Might be more organized in a separate nb?

Yes definitely I shouldn't aim to go deep with any of this the nb would take too long to make.

DFoF calculation explain

Also a dedicate notebook with a longer discussion on this would be really useful. We could use some of the ideas from Peter Rupretch too.

Yes, as before I should clarify I don't want to go deep, just a bit more than is done now (which is effectively nothing). I just remember finishing the notebooks and being like...wait did deconvolution happen yet? I'd like it to give an accurate gloss that makes users feel like they've got the basic pipeline explained, but leave the details to "auxilliary" notebooks.

Copy link
Member

@pgunn pgunn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some phrasing/typo things

@@ -187,11 +187,9 @@
"metadata": {},
"source": [
"## Setting up parameters\n",
"While there are many parameters used in CaImAn for the different steps in the pipeline, you only have to think about a few of them in each step, which we will discuss below. \n",
"Parameters are defined in a standalone parameters object. We create this object by passing parameters as a single dictionary to the `CNMFParams` class below. The parameters *not* explicitly defined in the dictionary will assume default values. A paramter object (let's call it `parameters`) is effectively a collection of dictionaries that each contains parameters relevant to different settings. Some related to the dataset in general (`parameters.data`), while most are relaed to particular aspects of the workflow such as motion correction (`parameters.motion`), component extraction (`parameters.spatial` and `parameters.temporal`), quality evaluation (`parameters.quality`), and others. \n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: "A parameter object"

@@ -187,11 +187,9 @@
"metadata": {},
"source": [
"## Setting up parameters\n",
"While there are many parameters used in CaImAn for the different steps in the pipeline, you only have to think about a few of them in each step, which we will discuss below. \n",
"Parameters are defined in a standalone parameters object. We create this object by passing parameters as a single dictionary to the `CNMFParams` class below. The parameters *not* explicitly defined in the dictionary will assume default values. A paramter object (let's call it `parameters`) is effectively a collection of dictionaries that each contains parameters relevant to different settings. Some related to the dataset in general (`parameters.data`), while most are relaed to particular aspects of the workflow such as motion correction (`parameters.motion`), component extraction (`parameters.spatial` and `parameters.temporal`), quality evaluation (`parameters.quality`), and others. \n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"that each contains" -> "each containing"

@@ -187,11 +187,9 @@
"metadata": {},
"source": [
"## Setting up parameters\n",
"While there are many parameters used in CaImAn for the different steps in the pipeline, you only have to think about a few of them in each step, which we will discuss below. \n",
"Parameters are defined in a standalone parameters object. We create this object by passing parameters as a single dictionary to the `CNMFParams` class below. The parameters *not* explicitly defined in the dictionary will assume default values. A paramter object (let's call it `parameters`) is effectively a collection of dictionaries that each contains parameters relevant to different settings. Some related to the dataset in general (`parameters.data`), while most are relaed to particular aspects of the workflow such as motion correction (`parameters.motion`), component extraction (`parameters.spatial` and `parameters.temporal`), quality evaluation (`parameters.quality`), and others. \n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Some are related"

@@ -187,11 +187,9 @@
"metadata": {},
"source": [
"## Setting up parameters\n",
"While there are many parameters used in CaImAn for the different steps in the pipeline, you only have to think about a few of them in each step, which we will discuss below. \n",
"Parameters are defined in a standalone parameters object. We create this object by passing parameters as a single dictionary to the `CNMFParams` class below. The parameters *not* explicitly defined in the dictionary will assume default values. A paramter object (let's call it `parameters`) is effectively a collection of dictionaries that each contains parameters relevant to different settings. Some related to the dataset in general (`parameters.data`), while most are relaed to particular aspects of the workflow such as motion correction (`parameters.motion`), component extraction (`parameters.spatial` and `parameters.temporal`), quality evaluation (`parameters.quality`), and others. \n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: "while most are related"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Pat, changes made!

"## Select files for processing\n",
"Many acquisition systems break up data from a single session across multiple files. This demo shows how to work with lists of filepaths that represent multiple movies from the same recording session. While this demo works with `tif` files, Caiman can handle movies in multiple common formats such as:\n",
"\n",
" tiff, hdf5, nwb, avi, zarr, h5, npz, n5\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hdf5 and h5 should not both be in the list.

Copy link
Contributor Author

@EricThomson EricThomson Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to hdf5/h5

@EricThomson EricThomson force-pushed the cnmf_notebook_update branch from 99dd986 to a15d837 Compare May 17, 2023 15:36
@EricThomson
Copy link
Contributor Author

Realized I had branched from main not dev, so fixed that. No need for re-review all these commits they are repeats. :)

@EricThomson
Copy link
Contributor Author

Note not quite done -- need to update links (it still mentions appendices in a couple of places), and I want to decrease verbosity in a couple of places.

@EricThomson
Copy link
Contributor Author

Will look at the merge conflict. Not sure what is up with that.

@EricThomson
Copy link
Contributor Author

Merge conflicts handled, review comments absorbed.

@EricThomson EricThomson mentioned this pull request Jan 7, 2024
45 tasks
backend
One of:
'multiprocessing' - Use multiprocessing library
'ipyparallel' - Use ipyparallel instead (better on Windows?)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, is this related to the requirement to have an if __name__ == "__main__" on windows?

@EricThomson
Copy link
Contributor Author

EricThomson commented Jan 22, 2024

In interests of letting good be the enemy of the perfect, and letting user feedback guide development, I think we should merge into dev unless there are major problems. I see this as useful step forward for initial users over previous iteration. Could add stuff on deconvolution, but I don't understand it very well so I'm not going to try right now.

Plan to go through CNMFE this week with similar course-toothed comb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants