Skip to main content

Efficient parallelizable algorithms for multidimensional arrays to speed up your data pipelines

Project description

codecov pypi License PyPI - Downloads

Imops

Efficient parallelizable algorithms for multidimensional arrays to speed up your data pipelines

Install

pip install imops  # default install with Cython backend
pip install imops[numba]  # additionally install Numba backend

Features

Fast Radon transform

from imops import radon, inverse_radon

Fast linear/bilinear/trilinear zoom

from imops import zoom, zoom_to_shape

# fast zoom with optional fallback to scipy's implementation
y = zoom(x, 2, axis=[0, 1])
# a handy function to zoom the array to a given shape 
# without the need to compute the scale factor
z = zoom_to_shape(x, (4, 120, 67))

Works faster only for ndim<=3, dtype=float32 or float64, output=None, order=1, mode='constant', grid_mode=False

Fast 1d linear interpolation

from imops import interp1d  # same as `scipy.interpolate.interp1d`

Works faster only for ndim<=3, dtype=float32 or float64, order=1 or 'linear'

Fast binary morphology

from imops import binary_dilation, binary_erosion, binary_opening, binary_closing

These functions mimic scikit-image counterparts

Padding

from imops import pad, pad_to_shape

y = pad(x, 10, axis=[0, 1])
# `ratio` controls how much padding is applied to left side:
# 0 - pad from right
# 1 - pad from left
# 0.5 - distribute the padding equally
z = pad_to_shape(x, (4, 120, 67), ratio=0.25)

Cropping

from imops import crop_to_shape

# `ratio` controls the position of the crop
# 0 - crop from right
# 1 - crop from left
# 0.5 - crop from the middle
z = crop_to_shape(x, (4, 120, 67), ratio=0.25)

Labeling

from imops import label

# same as `skimage.measure.label`
labeled, num_components = label(x, background=1, return_num=True)

Backends

For zoom, zoom_to_shape, interp1d, radon, inverse_radon you can specify which backend to use. Backend can be specified by a string or by an instance of Backend class. The latter allows you to customize some backend options:

from imops import Cython, Numba, Scipy, zoom

y = zoom(x, 2, backend='Cython')
y = zoom(x, 2, backend=Cython(fast=False))  # same as previous
y = zoom(x, 2, backend=Cython(fast=True))  # -ffast-math compiled cython backend
y = zoom(x, 2, backend=Scipy())  # use scipy original implementation
y = zoom(x, 2, backend='Numba')
y = zoom(x, 2, backend=Numba(parallel=True, nogil=True, cache=True))  # same as previous

Also backend can be specified globally or locally:

from imops import imops_backend, set_backend, zoom

set_backend('Numba')  # sets Numba as default backend
with imops_backend('Cython'):  # sets Cython backend via context manager
    zoom(x, 2)

Note that for Numba backend setting num_threads argument has no effect for now and you should use NUMBA_NUM_THREADS environment variable. Available backends:

Scipy Cython Numba
zoom
zoom_to_shape
interp1d
radon
inverse_radon
binary_dilation
binary_erosion
binary_closing
binary_opening

Acknowledgements

Some parts of our code for radon/inverse radon transform as well as the code for linear interpolation are inspired by the implementations from scikit-image and scipy. Also we used fastremap and cc3d out of the box.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

imops-0.7.0.tar.gz (21.8 kB view hashes)

Uploaded Source

Built Distributions

imops-0.7.0-cp310-cp310-win_amd64.whl (629.0 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

imops-0.7.0-cp310-cp310-win32.whl (539.0 kB view hashes)

Uploaded CPython 3.10 Windows x86

imops-0.7.0-cp310-cp310-musllinux_1_1_x86_64.whl (4.2 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

imops-0.7.0-cp310-cp310-musllinux_1_1_i686.whl (4.0 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

imops-0.7.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

imops-0.7.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl (4.0 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686

imops-0.7.0-cp310-cp310-macosx_10_9_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

imops-0.7.0-cp39-cp39-win_amd64.whl (637.8 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

imops-0.7.0-cp39-cp39-win32.whl (546.2 kB view hashes)

Uploaded CPython 3.9 Windows x86

imops-0.7.0-cp39-cp39-musllinux_1_1_x86_64.whl (4.3 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

imops-0.7.0-cp39-cp39-musllinux_1_1_i686.whl (4.0 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

imops-0.7.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.3 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

imops-0.7.0-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl (4.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686

imops-0.7.0-cp39-cp39-macosx_10_9_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

imops-0.7.0-cp38-cp38-win_amd64.whl (636.6 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

imops-0.7.0-cp38-cp38-win32.whl (545.3 kB view hashes)

Uploaded CPython 3.8 Windows x86

imops-0.7.0-cp38-cp38-musllinux_1_1_x86_64.whl (4.5 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

imops-0.7.0-cp38-cp38-musllinux_1_1_i686.whl (4.3 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ i686

imops-0.7.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.3 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

imops-0.7.0-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl (4.2 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686

imops-0.7.0-cp38-cp38-macosx_10_9_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

imops-0.7.0-cp37-cp37m-win_amd64.whl (624.3 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

imops-0.7.0-cp37-cp37m-win32.whl (532.2 kB view hashes)

Uploaded CPython 3.7m Windows x86

imops-0.7.0-cp37-cp37m-musllinux_1_1_x86_64.whl (4.0 MB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

imops-0.7.0-cp37-cp37m-musllinux_1_1_i686.whl (3.8 MB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ i686

imops-0.7.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.9 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

imops-0.7.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl (3.8 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ i686

imops-0.7.0-cp37-cp37m-macosx_10_9_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

imops-0.7.0-cp36-cp36m-win_amd64.whl (711.7 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

imops-0.7.0-cp36-cp36m-win32.whl (585.1 kB view hashes)

Uploaded CPython 3.6m Windows x86

imops-0.7.0-cp36-cp36m-musllinux_1_1_x86_64.whl (4.0 MB view hashes)

Uploaded CPython 3.6m musllinux: musl 1.1+ x86-64

imops-0.7.0-cp36-cp36m-musllinux_1_1_i686.whl (3.8 MB view hashes)

Uploaded CPython 3.6m musllinux: musl 1.1+ i686

imops-0.7.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.9 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64

imops-0.7.0-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl (3.8 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ i686

imops-0.7.0-cp36-cp36m-macosx_10_9_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page