Skip to content

neuromotion/calcium-roi-analysis

Repository files navigation

calcium-roi-analysis

Detection and analysis of rois in calcium imaging

Setting Up your Development Environment

This instructions are for MacOS, while they should roughly be the same for Windows and Linux, they are untested in those environments:

  1. Homebrew

Homebrew is a popular package manager for MacOS

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

  1. pyenv

Installation

pyenv allows you to run and manage multiple versions of Python, all in isolations from your system's Python. If this is your first time using pyenv you can learn more about isuing it in this blog post

brew install pyenv

Append pyenv init to bash's profile

$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile

And restart your SHELL

exec "$SHELL"

List versions of Python available to install

pyenv install --list

Install most recent stable version

A stable version means there is no -dev of -rc after the name. For instance run

pyenv install 3.8.1

Activate global environment to that

pyenv global 3.8.0

Listing available versions to the system

pyenv versions

Configuring a local environment

When you are in a folder, you can configure the version of the Python that is activated when you are calling Python within that folder by calling for instance pyenv local 3.8.0 within your directory.

This will create a hidden file .python-version in the current directory.

  1. pipx

PIPX allows you to install Python (and Ruby) CLI utilities in their own environment, without contaminating your global environment

Installation

python -m pip install pipx

  1. Jupyter -- Skip if using VSCode (highly recommended)

It is included as dev dependency of napari

  1. Poetry

Poetry handles dependency- and virtual-environment-management in a way that’s very intuitive (to me), and fits perfectly with my desired workflow.

pipx install poetry

Configure poetry to create virtual environments inside the project's root directory

poetry config virtualenvs.in-project true

Making sure that Poetry is using Pyenvs python

poetry env use $(pyenv which python)

Getting Started

Install the package dependencies using Poetry

Within the urrent directory of your package, run

poetry update

Then

poetry install

Install ipython kernel spec

poetry run python -m ipykernel install --user --name=calcium-roi-analysis

Open the sample notebook

If you are using vscode with the Python plugin, you should be able to connect to the kernel in the current virtual environment. Make sure that you select the python kernel we created, named calcium-roi-analysis

Alternatively, you can fireup Jupyter Lab

poetry run jupyter-lab

Version control

Git Overview

Git is a version control system that enables you to track changes to files. With Git, you are able to revert files back to previous versions, restore deleted files, remove added files and even track down where a particular line of code was introduced.

Git creates a hidden .git folder (in the current folder) to store the details of the file system - this folder contains all the data required to track your files and is known as a repository, or repo.

Git tracks file changes by the user creating a save point, or in Git terms a commit. Each commit takes a snapshot of the current file system. Commits are uniquely identified by a SHA–1 hash. This is a 40 character string which may along the lines of ded7a0db6422d59e9893e975e32275fc36f853daThis hash can be used to track a particular commit within the repository.

Nearly all operations that are performed by Git are in you local computing environment, for the exception of few used purly to synchronize with a remote. Some of the most common git operations are depicted below. In summary a typical flow consists of making changes to your files, staging them via git add, marking a save point via git commit, then finally syncing to your remote (e.g., GitHub) via git push. If you are pushing changes to your remote from multiple places, you can bring changes your most recent version usin git pull, which is the equivalent of doing git fetch followed by a git merge operation

Cheatsheet

Command Brief
git add <files> add a file to next commit (stage)
git commit -m <message> commit staged files
git push upload staged commit to repo
git pull get remote repo commits and download (try and resolve conflicts)
git clone <url> download entire repository

Working with Jupyter Notebooks

Jupyter Notebooks are inheritely messy to work with git. The reason is that the notebook format includes all the output cells and makes it defficult to view what has changed in the code.

This project includes nbdime a tool that facilitates seeing the difference in the changes. To do so call

poetry run nbdiff-web or poetry run nbdiff

If working within jupyter-lab, an extension is enabled to see the differences

Running find_roi.ipynb

Start by making sure you have an input image, and that your yaml file has the correct file path to that input image.

After selecting the calcium-roi-analysis kernel, you can hit run all to execute all of the code blocks sequentially. After a short while, a window should pop up with an output image. Click on the image and press the f key on your keyboard to save that image to your output file.

After the image has been saved, you can run the next block of code, which probably failed as it relies on that image being created.

About

Detection and analysis of rois in calcium imaging

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published