Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ fly2p/sample/*.*
fly2p/sample/img/*.*
*.pdf
*.pyc
*.tif
30 changes: 30 additions & 0 deletions README_pypi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<img src="https://user-images.githubusercontent.com/10639803/126242184-65bc84c4-3fa2-4034-be51-3e8c2e4d9f8c.png" align="middle" width="3000"/>

# fly2p

Tools for analyzing imaging data collected with [Vidrio Scanimage software](https://vidriotechnologies.com/scanimage/) or [micromanger](https://micro-manager.org/). Loading ScanImage data relies on [scanimageReader](https://pypi.org/project/scanimage-tiff-reader/), which can be installed via 'pip install scanimage-tiff-reader'. Other dependencies are tracked using poetry.

### Organization
The fly2p package contains the following submodules:
* **preproc**: Some file-format specific functions that extract metadata and load the imaging data. imgPreproc.py defines a data object to hold metadata and imaging data as well as basic proporcessing functions.
* **viz**: A collection of utility functions related to plotting flourescence traces and images.

In addition, the **scripts** folder contains notebooks that illustrate how to use functions in this module based on example files in **sample** (sample files are not currently pushed to repo).

### Installation
I recommend using poetry to setup a custom conda environment. A helpful introduction can be found [here](https://ealizadeh.com/blog/guide-to-python-env-pkg-dependency-using-conda-poetry).

0. Clone repo, navigate into folder
1. If you don't already have poetry, [install poetry](https://python-poetry.org/docs/#installation). You may need to close command window and open a new one.
2. Create conda environment:
`conda create --name fly2p python=3.8`
4. Activate environment:
`conda activate fly2p`
6. Make sure you are in the top folder of the cloned repo, then install dependencies:
`poetry install`
8. Setup the new environment as an ipython kernel:
`conda install -c anaconda ipykernel`
then
`python -m ipykernel install --user --name=fly2p`

Now you should be able to run the example notebooks in the **scripts** folder without problems.
Binary file added dist/fly2p-0.2.0-py3-none-any.whl
Binary file not shown.
Binary file added dist/fly2p-0.2.0.tar.gz
Binary file not shown.
Binary file added dist/fly2p-0.2.2-py3-none-any.whl
Binary file not shown.
Binary file added dist/fly2p-0.2.2.tar.gz
Binary file not shown.
18 changes: 13 additions & 5 deletions fly2p/preproc/imgPreproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ class imagingTimeseries:
refImage: xr.DataArray # image used for motion correction (MC)
dffStack: xr.DataArray # image or stack, maximum intensity projection of DFF over time after MC
F0stack: xr.DataArray # image or stack of F0 (baseline flourescences)
rawStack: xr.DataArray # raw image stack

# roi data
roitype: str #polygons ("poly") or correlation-based ("corr")?
roitype: str #polygons ("poly") or correlation-based ("corr") or manual?
roiMask: np.ndarray
roiDFF: pd.DataFrame

Expand All @@ -48,6 +49,7 @@ def saveData(self, saveDir, saveName):
self.refImage.to_netcdf(sep.join([savepath,'refImg.nc']), mode='w')
self.dffStack.to_netcdf(sep.join([savepath,'dffStack.nc']), mode='w')
self.F0stack.to_netcdf(sep.join([savepath,'F0stack.nc']), mode='w')
self.rawStack.to_netcdf(sep.join([savepath,'rawStack.nc']), mode='w')

# save roi data
np.save(sep.join([savepath,'roiMask']),self.roiMask)
Expand Down Expand Up @@ -126,7 +128,7 @@ def loadImagingTimeseries(path2imgdat):
return imgTS

## CONVERT TO XARRAY
def stack2xarray(stack, basicMetadat, data4D = True):
def stack2xarray(stack, basicMetadat, data4D = True, clipping = False):
volcoords = [i/basicMetadat['scanVolumeRate'] for i in range(stack.shape[0])]
if data4D:
slices = [i*basicMetadat['stackZStepSize'] for i in range(stack.shape[1])]
Expand All @@ -141,9 +143,15 @@ def stack2xarray(stack, basicMetadat, data4D = True):
imgStack = xr.DataArray(stack, coords = [volcoords, xpx, ypx],
dims = ['volumes [s]', 'xpix [µm]', 'ypix [µm]'])

minval = np.min(imgStack)
if minval < 0: imgStack = imgStack - minval

# forcing all values to be above 0 by subtracting the minimum value is prone to biases from single pixel noise. A more ideal conversion to +ve values would clip negative values to 0
# see: https://docs.scanimage.org/Windows+Reference+Guide/Channels.html
if (clipping==False):
minval = np.min(imgStack)
if minval < 0: imgStack = imgStack - minval
elif (clipping==True):
imgStack = xr.where(imgStack<0,0,imgStack)
else:
print('no +ve conversion applied when converting to xarray')
return imgStack

## CONVERT TO XARRAY when no time dimension
Expand Down
519 changes: 361 additions & 158 deletions fly2p/scripts/preprocessImaging3D.ipynb

Large diffs are not rendered by default.

1,284 changes: 1,284 additions & 0 deletions fly2p/scripts/preprocessImaging3D_AS.ipynb

Large diffs are not rendered by default.

100 changes: 94 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[tool.poetry]
name = "fly2p"
version = "0.1.0"
version = "0.2.2"
description = "Tools for analyzing 2p (calcium) imaging data collected in flies (or other insects)."
readme = "README_pypi.md"
authors = ["hjmh <hjmhaberkern@gmail.com>"]
license = "MIT"

Expand Down Expand Up @@ -40,4 +41,4 @@ ipykernel = "^6.25.2"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
build-backend = "poetry.core.masonry.api"