Skip to main content

meta plugin to ease processing timelapse image data

Project description

napari-timelapse-processor

License BSD-3 PyPI Python Version tests codecov napari hub

meta plugin to ease processing timelapse image data

API

This plugin exposes two principal funcionalities:

TimelapseConverter

The TimelapseConverter class allows you to stack or unstack any of the supported napari layers from 4D data into a list of 3D layers or vice versa. Currently supported layers are:

  • napari.layers.Image
  • napari.layers.Labels
  • napari.layers.Points
  • napari.layers.Vectors
  • napari.layers.Surface

napari.layers.Tracks are intrinsically 4D and thus not supported.

Unstacking example usage:

from napari_timelapse_processor import TimelapseConverter
import numpy as np

image_4d = np.random.rand(10, 32, 32, 32)  # 10 timepoints of 32x32x32 data
converter = TimelapseConverter()
list_of_images = converter.unstack(image_4d, layertype='napari.types.ImageData')

Stacking example usage:

from napari_timelapse_processor import TimelapseConverter
import numpy as np

random_points = [np.random.rand(10, 3)  for _ in range(10)]  # 10 timepoints of 10 random 3D points
converter = TimelapseConverter()

# stack the points into a single 4D layer
stacked_points = converter.stack(random_points, layertype='napari.types.PointsData')

The TimeLapseConverter class also supports (un)stacking the napari.layers.Layer type (and its above-listed subclasses). Importantly, features that are associated with the respective layer are also (un)stacked.

Layer example usage

from napari_timelapse_processor import TimelapseConverter
import numpy as np
from napari.layers import Points
import pandas as pd

random_points = [np.random.rand(10, 3)  for _ in range(10)]  # 10 timepoints of 10 random 3D points
random_features = [pd.DataFrame(np.random.rand(10)) for _ in range(10)]  # 10 timepoints of 10 random feature values

# create a list of 10 Points layers
points = [Points(random_points[i], properties=random_features[i]) for i in range(10)]

converter = TimelapseConverter()
stacked_points = converter.stack(points, layertype='napari.layers.Points')

frame_by_frame

The frame-by-frame functionality provides a decorator that will inspect the decorated function for TimelapseConverter-compatible arguments and, if a 4D value is passed as argument, will automatically (un)stack the data before and after the function call. This allows for a more intuitive API when working with timelapse data. Currently supported type annotations are:

  • napari.types.ImageData
  • napari.types.LabelsData
  • napari.types.PointsData
  • napari.types.VectorsData
  • napari.types.SurfaceData
  • napari.layers.Layer
  • napari.layers.Image
  • napari.layers.Labels
  • napari.layers.Points
  • napari.layers.Vectors
  • napari.layers.Surface

Additionally, the frame_by_frame supports parallelization with dask.distributed. To use it, simply pass the use_dask=True argument to the decorated function, even if the function itself does not require this argument. The decorater will then automatically parallelize the function call over the time-axis and remove the use_dask argument when calling the function.

Example interactive code usage: If you want to use the frame_by_frame functionality in, say, a Jupyter notebook, use it like this:

from napari_timelapse_processor import frame_by_frame
import numpy as np

def my_function(image: 'napari.types.ImageData') -> 'napari.types.ImageData':
    return 2 * image

image_4d = np.random.rand(10, 32, 32, 32)  # 10 timepoints of 32x32x32 data

image_4d_processed = frame_by_frame(my_function)(image_4d)  # without dask
image_4d_processed = frame_by_frame(my_function)(image_4d, use_dask=True)  # with dask

Example napari code If you want to use the frame_by_frame functionality in a napari plugin, use it like this:

from napari_timelapse_processor import frame_by_frame

@frame_by_frame
def my_function(image: 'napari.types.ImageData') -> 'napari.types.ImageData':
    return 2 * image

Hint: The frame_by_frame functionality runs under the assumption that input napari-data (e.g., an Image, a Surface, Points, etc) are always arguments and any other parameters are always keyword arguments. If this is not the case, the decorator will not work as intended.

# This works
frame_by_frame(my_function)(image_4d, some_parameter=2, use_dask=True)

# This does not work
frame_by_frame(my_function)(image=image_4d, some_parameter=2, use_dask=True)

This napari plugin was generated with Cookiecutter using @napari's cookiecutter-napari-plugin template.

Installation

You can install napari-timelapse-processor via pip:

pip install napari-timelapse-processor

Contributing

Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.

License

Distributed under the terms of the BSD-3 license, "napari-timelapse-processor" is free and open source software

Issues

If you encounter any problems, please [file an issue] along with a detailed description.

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

napari_timelapse_processor-0.1.0.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

napari_timelapse_processor-0.1.0-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file napari_timelapse_processor-0.1.0.tar.gz.

File metadata

File hashes

Hashes for napari_timelapse_processor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 154bc80dfc36d996ef4634a7f0b5db1a8915a58811cfe164f009e30d0561fb20
MD5 4156e6f2d0f9ed37e4695dab5e43e7fe
BLAKE2b-256 f9f70378609cf4d422c45ec8a870767d5eec8f66013343bb6b940baf3d398d56

See more details on using hashes here.

Provenance

The following attestation bundles were made for napari_timelapse_processor-0.1.0.tar.gz:

Publisher: test_and_deploy.yml on jo-mueller/napari-timelapse-processor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file napari_timelapse_processor-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for napari_timelapse_processor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7902a2625e0eefb5f8197a70645e374cd8d22b83510d42f6232a96ccb3ee3dc2
MD5 4b7bffafde72afa8dc04b942234f0415
BLAKE2b-256 47459e39d805072520a059bf1e916a7c70093cd596a6e04aaf0c7ec6309a844f

See more details on using hashes here.

Provenance

The following attestation bundles were made for napari_timelapse_processor-0.1.0-py3-none-any.whl:

Publisher: test_and_deploy.yml on jo-mueller/napari-timelapse-processor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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