Skip to content

Commit d516388

Browse files
authored
Merge pull request #73 from AdaptiveParticles/particle_dtypes
- Add IntParticles (Note: these are not yet supported in most pyapr processing functionality) - Add astype and __array__ methods to APRSlicer - Remove unsafe math optimizations from default CMake build - Update CI and deployment workflows
2 parents e3fc6fa + 5a0cc79 commit d516388

File tree

22 files changed

+123
-50
lines changed

22 files changed

+123
-50
lines changed

.github/workflows/build-deploy.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,20 @@ jobs:
4545
# Indicates the location of the vcpkg as a Git submodule of the project repository.
4646
VCPKG_ROOT: ${{ github.workspace }}/external/LibAPR/vcpkg
4747
CIBW_ENVIRONMENT_WINDOWS: EXTRA_CMAKE_ARGS="-DCMAKE_TOOLCHAIN_FILE=D:\\a\\pyapr\\pyapr\\external\\LibAPR\\vcpkg\\scripts\\buildsystems\\vcpkg.cmake -DVCPKG_MANIFEST_DIR=D:\\a\\pyapr\\pyapr\\external\\LibAPR\\"
48-
CIBW_BUILD: "cp36-* cp37-* cp38-* cp39-* cp310-*"
48+
CIBW_BUILD: "cp38-* cp39-* cp310-* cp311-*"
4949
CIBW_SKIP: "*musllinux*"
5050
CIBW_ARCHS: "auto64"
51-
CIBW_MANYLINUX_X86_64_IMAGE: "manylinux_2_24"
5251
CIBW_BUILD_VERBOSITY: 1
53-
CIBW_REPAIR_WHEEL_COMMAND_MACOS: "pip uninstall -y delocate && pip install git+https://github.com/Chia-Network/delocate.git && delocate-listdeps {wheel} && delocate-wheel -w {dest_dir} -v {wheel}"
52+
CIBW_REPAIR_WHEEL_COMMAND_MACOS: "pip install -U delocate && delocate-listdeps {wheel} && delocate-wheel -w {dest_dir} -v {wheel}"
5453
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: "pip install -U wheel delvewheel && python fix_windows_wheel.py {wheel} {dest_dir}"
5554
CIBW_TEST_REQUIRES: "pytest pytest-qt pytest-xvfb"
5655
CIBW_TEST_COMMAND: "python3 -m pytest -vv {project}/pyapr/tests"
5756
CIBW_TEST_SKIP: "*-win_amd64" # windows tests are run separately
58-
CIBW_BEFORE_BUILD_LINUX: "apt update && apt install -y libtiff5-dev libhdf5-dev"
57+
CIBW_BEFORE_BUILD_LINUX: "yum makecache && yum install -y libtiff-devel hdf5-devel"
5958
CIBW_ENVIRONMENT_MACOS: CPPFLAGS="-I/usr/local/opt/llvm/include" LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib" CXX="/usr/local/opt/llvm/bin/clang++" CC="/usr/local/opt/llvm/bin/clang"
6059

6160
steps:
62-
- uses: actions/checkout@v3
61+
- uses: actions/checkout@v4
6362
with:
6463
fetch-depth: 0
6564
submodules: true
@@ -109,7 +108,7 @@ jobs:
109108

110109
- name: Install cibuildwheel
111110
run: |
112-
python3 -m pip install cibuildwheel==2.5.0
111+
python3 -m pip install cibuildwheel
113112
114113
- name: Install OpenMP dependencies with brew for OSX
115114
if: contains(matrix.os,'macos')
@@ -139,11 +138,11 @@ jobs:
139138
fail-fast: false
140139
matrix:
141140
os: [ windows-latest ]
142-
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
141+
python-version: ['3.8', '3.9', '3.10', '3.11']
143142

144143
steps:
145144
- name: Checkout
146-
uses: actions/checkout@v3
145+
uses: actions/checkout@v4
147146
with:
148147
submodules: false
149148

.github/workflows/deploy-docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
VCPKG_ROOT: ${{ github.workspace }}/external/LibAPR/vcpkg
3333
EXTRA_CMAKE_ARGS: "-DCMAKE_TOOLCHAIN_FILE='${{ github.workspace }}/external/LibAPR/vcpkg/scripts/buildsystems/vcpkg.cmake'"
3434
steps:
35-
- uses: actions/checkout@v3
35+
- uses: actions/checkout@v4
3636
with:
3737
fetch-depth: 0
3838
submodules: true
@@ -75,7 +75,7 @@ jobs:
7575

7676
- name: Check file existence
7777
id: check_files
78-
uses: andstor/file-existence-action@v1
78+
uses: andstor/file-existence-action@v2
7979
with:
8080
files: "${{ env.VCPKG_ROOT }}/vcpkg"
8181

.github/workflows/quick-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
VCPKG_ROOT: ${{ github.workspace }}/external/LibAPR/vcpkg
3838
EXTRA_CMAKE_ARGS: "-DCMAKE_TOOLCHAIN_FILE='${{ github.workspace }}/external/LibAPR/vcpkg/scripts/buildsystems/vcpkg.cmake'"
3939
steps:
40-
- uses: actions/checkout@v3
40+
- uses: actions/checkout@v4
4141
with:
4242
fetch-depth: 0
4343
submodules: true
@@ -80,7 +80,7 @@ jobs:
8080

8181
- name: Check file existence
8282
id: check_files
83-
uses: andstor/file-existence-action@v1
83+
uses: andstor/file-existence-action@v2
8484
with:
8585
files: "${{ env.VCPKG_ROOT }}/vcpkg"
8686

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,25 @@ if(WIN32)
101101
message(STATUS "Compiling on windows with CLANG!")
102102
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xclang -fcxx-exceptions")
103103
set(CMAKE_CXX_FLAGS_DEBUG "/MD /Z7")
104-
set(CMAKE_CXX_FLAGS_RELEASE "/MD /EHsc /std:c++17 /arch:AVX2 -Xclang -O3 /nologo /fp:fast") #-flto=thin -march=native /O2 /Ob2
104+
set(CMAKE_CXX_FLAGS_RELEASE "/MD /EHsc /std:c++17 /arch:AVX2 -Xclang -O3 /nologo") #-flto=thin -march=native /O2 /Ob2
105105
endif()
106106

107107
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
108108
message(STATUS "Compiling on windows with MSVC!")
109-
set(CMAKE_CXX_FLAGS_RELEASE "/MD /EHsc /std:c++17 /arch:AVX2 /O2 /Ob2 /nologo /fp:fast")
109+
set(CMAKE_CXX_FLAGS_RELEASE "/MD /EHsc /std:c++17 /arch:AVX2 /O2 /Ob2 /nologo")
110110
set(CMAKE_CXX_FLAGS_DEBUG "/MD /Z7")
111111
endif()
112112

113113
else()
114114
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -pedantic ")
115115
if(CMAKE_COMPILER_IS_GNUCC)
116-
set(CMAKE_CXX_FLAGS_RELEASE "-O4 -ffast-math")
116+
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
117117
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
118118
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Bdynamic")
119119
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -ldl -lz")
120120

121121
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
122-
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -ffast-math")
122+
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
123123
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
124124
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lz")
125125
endif()

README.md

Lines changed: 64 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,89 @@
55
[![License](https://img.shields.io/pypi/l/pyapr.svg?color=green)](https://raw.githubusercontent.com/AdaptiveParticles/pyapr/master/LICENSE)
66
[![Python Version](https://img.shields.io/pypi/pyversions/pyapr.svg?color=blue)]((https://python.org))
77
[![PyPI](https://img.shields.io/pypi/v/pyapr.svg?color=green)](https://pypi.org/project/pyapr/)
8-
![PowerShell Gallery](https://img.shields.io/powershellgallery/p/DNS.1.1.1.1)
9-
[![DOI](https://zenodo.org/badge/184399854.svg)](https://zenodo.org/badge/latestdoi/184399854)
8+
[![Downloads](https://static.pepy.tech/badge/pyapr)](https://pepy.tech/project/pyapr)
9+
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.7304045.svg)](https://doi.org/10.5281/zenodo.7304045)
1010

1111
Documentation can be found [here](https://adaptiveparticles.github.io/pyapr/index.html).
1212

13-
Content-adaptive storage and processing of large volumetric microscopy data using
14-
the Adaptive Particle Representation (APR).
13+
Content-adaptive storage and processing of large volumetric microscopy data using the Adaptive Particle Representation (APR).
14+
15+
The APR is an adaptive image representation designed primarily for large 3D fluorescence microscopy datasets. By replacing pixels with particles positioned according to the image content, it enables orders-of-magnitude compression of sparse image data while maintaining image quality. However, unlike most compression formats, the APR can be used directly in a wide range of processing tasks - even on the GPU!
16+
17+
| Pixels | APR |
18+
| :--: | :--: |
19+
| ![img.png](./docs/images/pix_joined.png) | ![img.png](./docs/images/apr_joined.png) |
20+
| Uniform sampling | Adaptive sampling |
21+
22+
*[image source](https://bbbc.broadinstitute.org/bbbc/BBBC032),
23+
[illustration source](https://ieeexplore.ieee.org/abstract/document/9796006)*
1524

16-
The APR is an adaptive image representation designed primarily for large 3D fluorescence
17-
microscopy datasets. By replacing pixels with particles positioned according to the
18-
image content, it enables orders-of-magnitude compression of sparse image data
19-
while maintaining image quality. However, unlike most compression formats, the APR
20-
can be used directly in a wide range of processing tasks - even on the GPU!
2125

2226
For more detailed information about the APR and its use, see:
2327
- [Adaptive particle representation of fluorescence microscopy images](https://www.nature.com/articles/s41467-018-07390-9) (nature communications)
2428
- [Parallel Discrete Convolutions on Adaptive Particle Representations of Images](https://ieeexplore.ieee.org/abstract/document/9796006) (IEEE Transactions on Image Processing)
2529

2630
**pyapr** is built on top of the C++ library [LibAPR] using [pybind11].
2731

28-
## Installation
29-
For Windows 10, OSX, and Linux and Python versions 3.7-3.9 direct installation with OpenMP support should work via [pip]:
32+
## Quick start guide
33+
34+
Convert images to APR using minimal amounts of code (*see [get_apr_demo](demo/get_apr_demo.py) and [get_apr_interactive_demo](demo/get_apr_interactive_demo.py) for additional options*).
35+
36+
```python
37+
import pyapr
38+
from skimage import io
39+
40+
# read image into numpy array
41+
img = io.imread('my_image.tif')
42+
43+
# convert to APR using default settings
44+
apr, parts = pyapr.converter.get_apr(img)
45+
46+
# write APR to file
47+
pyapr.io.write('my_image.apr', apr, parts)
3048
```
31-
pip install pyapr
49+
50+
![img.png](./docs/images/apr_file.png)
51+
52+
To return to the pixel representation:
53+
```python
54+
# reconstruct pixel image
55+
img = pyapr.reconstruction.reconstruct_constant(apr, parts)
3256
```
33-
Note: Due to the use of OpenMP, it is encouraged to install as part of a virtualenv.
3457

35-
See [INSTALL] for manual build instructions.
3658

37-
## Exclusive features
59+
Inspect APRs using our makeshift image viewers (*see [napari-apr-viewer] for less experimental visualization options*).
60+
61+
```python
62+
# read APR from file
63+
apr, parts = pyapr.io.read('my_image.apr')
3864

39-
In addition to providing wrappers for most of the functionality of LibAPR, we provide a number of
40-
new features that simplify the generation and handling of the APR. For example:
65+
# launch viewer
66+
pyapr.viewer.parts_viewer(apr, parts)
67+
```
68+
![img.png](./docs/images/view_apr.png)
4169

42-
* Interactive APR conversion (see [get_apr_interactive_demo](demo/get_apr_interactive_demo.py) and
43-
[get_apr_by_block_interactive_demo](demo/get_apr_by_block_interactive_demo.py))
44-
* Interactive APR z-slice viewer (see [viewer_demo](demo/viewer_demo.py))
45-
* Interactive APR raycast (maximum intensity projection) viewer (see [raycast_demo](demo/raycast_demo.py))
46-
* Interactive lossy compression of particle intensities (see [compress_particles_demo](demo/compress_particles_demo.py))
70+
The `View Level` toggle allows you to see the adaptation (brighter = higher resolution).
4771

48-
For further examples see the [demo scripts].
72+
![img.png](./docs/images/view_level.png)
4973

50-
Also be sure to check out our (experimental) [napari] plugin: [napari-apr-viewer].
74+
Or view the result in 3D using APR-native maximum intensity projection raycast (cpu).
75+
```python
76+
# launch raycast viewer
77+
pyapr.viewer.raycast_viewer(apr, parts)
78+
```
79+
![img.png](./docs/images/raycast.png)
80+
81+
See the [demo scripts] for more examples.
82+
83+
## Installation
84+
For Windows 10, OSX, and Linux direct installation with OpenMP support should work via [pip]:
85+
```
86+
pip install pyapr
87+
```
88+
Note: Due to the use of OpenMP, it is encouraged to install as part of a virtualenv.
89+
90+
See [INSTALL] for manual build instructions.
5191

5292

5393
## License

docs/images/apr_file.png

7.8 KB
Loading

docs/images/apr_joined.png

171 KB
Loading

docs/images/pix_joined.png

150 KB
Loading

docs/images/raycast.png

132 KB
Loading

docs/images/view_apr.png

70.5 KB
Loading

0 commit comments

Comments
 (0)