Skip to content

Commit

Permalink
Merge branch 'LMAP'
Browse files Browse the repository at this point in the history
  • Loading branch information
perdigao1 committed Nov 18, 2021
2 parents ae5d556 + 4b898a4 commit b17702d
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ RedLionfish.egg-info/
*.py[cod]
.cache/

test/test_and_benchm.spec
*.spec
47 changes: 37 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,55 @@
# Red lionfish (RL) deconvolution

Deconvolution algorithms for busy scientists who would like to do Richardson-Lucy (also RL) deconvolution.
Richardson-Lucy deconvolution for fishes, scientists and engineers.

It has a version that runs on CPU (scikit) and another that runs on GPU using OpenCL through Reikna library.
Richardson-Lucy is an iterative deconvolution algorithm that is useful for removing
point spread function (PSF) or optical transfer function artifacts in experimental images.

By default it uses the GPU OpenCL version.
The method was originally developed for astronomy, to remove optical effects and simultaneously reduce poisson noise in 2D images.

[Lucy, L. B. An iterative technique for the rectification of observed distributions. The Astronomical Journal 79, 745 (1974). DOI: 10.1086/111605](https://ui.adsabs.harvard.edu/abs/1974AJ.....79..745L/abstract)

TODO: More description

If data is too big, it will split into blocks and will run deconvolution in
It has a version that runs on CPU (scikit) and another that runs on GPU using OpenCL through Reikna library.
By default it uses the GPU OpenCL version.
If data is too big for doing GPU deconvolution, it will do the calculation in blocks, therefore preventing memory issues.

If you wish to do RL using GPU openCL on large data, then the 'block' version is automatically done to prevent memory errors.

## Installation

### Install using conda package, under conda environment (recommended)
It is strongly recommended to install this package under a python anaconda or miniconda environment.
This is because some calculations use PyOpenCL, and this is best installed using `conda install` rather than `pip install`.

It is also possible to install using *pip* and it can still do deconvolution, however the code may fail to use GPU.

It also has a napari plugin. It can be installed by using the napari plugin installer, however this will not enable GPU acceleration.
As above, to best exploit GPU acceleration, it is recommended to install using Anaconda/conda.

### Anaconda/miniconda installation

TODO
`
conda install RedLionfish
`

and it should be ready to use.

If you have installed napari in this conda environment and launch it, the napari-redlionfish plugin should be available in the plugin menu.


#### Manual installation using the conda package.

Download the appropriate conda package .bz2

In the command line, successively run:
```
conda install <filename.bz2>
conda update --all
conda update --all -c conda-forge
```
The second line is needed because you are installing from a local file, conda installer will not install dependencies. Right after this you should run the update command given.


### Manual installation (advanced and for developers)

Please note that in order to use OpenCL GPU accelerations, PyopenCL must be installed.
Expand All @@ -47,21 +74,21 @@ If you want to test and modify the code then you should probably install instead

Please feel free to browse /test folder for examples.

Don't forget to add
In your code, add the import.

`import RedLionfishDeconv`

in order to use the functions.

The most useful is perhaps the following.
The most useful function is perhaps the following.

`def doRLDeconvolutionFromNpArrays(data_np , psf_np ,*, niter=10, method='gpu', useBlockAlgorithm=False, callbkTickFunc=None, resAsUint8 = False) `

This will do the Richardson-Lucy deconvolution on the data_np (numpy, 3 dimensional data volume) using the provided PSF data volume, for 10 iterations. GPU method is generally faster but it may fail. If it does fail, the program will automatically use the CPU version from scipy.imaging.



## Manually building conda package
## Manually building the conda package

You may need to ensure all packages are installed. For this installation, ensure that the conda-build package is installed

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
'Natural Language :: English',
'Programming Language :: Python :: 3.8',
'Operating System :: Windows :: POSIX :: Linux :: MacOS',
'Framework :: napari'
],
license='Apache License, Version 2.0',
zip_safe=False,
Expand Down
11 changes: 11 additions & 0 deletions test/create_testbenchm_exe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Ensure that RedLionfish and pyinstaller are installed before running the command below

> pyinstaller test_and_benchm.py --onefile
Does not work, executable fails to find Reikna

Check with
> pyinstaller test_and_benchm.py --debug=imports
No success, program runs but cannot find .mako files.

Run
> create_testbenchm_exe_script.bat
18 changes: 18 additions & 0 deletions test/create_testbenchm_exe_script.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Rem Get the output for a simple python code

rem test
rem for /f "tokens=*" %%i in ('python --version') do set REIKNAPATH=%%i

rem tokens=* processes line by line

FOR /F "tokens=*" %%i IN ('python -c "import importlib; print(importlib.util.find_spec('reikna').submodule_search_locations[0])" ') do set REIKNAPATH=%%i

echo REIKNAPATH = %REIKNAPATH%

rem Create correct pyinstaller spec file
rem pyi-makespec test_and_benchm.py --add-data "%REIKNAPATH%;reikna"
rem pyi-makespec test_and_benchm.py --add-data "%REIKNAPATH%;reikna" --exclude-module matplotlib

pyi-makespec test_and_benchm.py --onefile --add-data "%REIKNAPATH%;reikna" --exclude-module matplotlib --exclude-module PyQt5

pyinstaller --clean --noconfirm test_and_benchm.spec

0 comments on commit b17702d

Please sign in to comment.