跳转到主要内容

元插件,简化时间序列图像数据处理

项目描述

napari-timelapse-processor

License BSD-3 PyPI Python Version tests codecov napari hub

元插件,简化时间序列图像数据处理

API

此插件公开了两个主要功能

时间序列转换器

TimeLapseConverter类允许您将支持的任何napari层从4D数据堆叠或取消堆叠到3D层列表中,反之亦然。当前支持的层包括

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

napari.layers.Tracks本质上是4D的,因此不受支持。

取消堆叠示例用法

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')

堆叠示例用法

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')

TimeLapseConverter类还支持(取消)堆叠napari.layers.Layer类型(及其上述子类)。重要的是,与相应层关联的features也会(取消)堆叠。

层示例用法

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')

帧到帧

帧到帧功能提供了一个装饰器,该装饰器将检查被装饰的函数是否有TimelapseConverter兼容的参数,并且如果传递了4D值作为参数,将在函数调用前后自动(取消)堆叠数据。这允许在处理时间序列数据时有一个更直观的API。目前支持的类型注解包括

  • 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

此外,frame_by_frame支持与dask.distributed并行化。要使用它,只需将装饰函数的use_dask=True参数传递,即使函数本身不需要此参数。装饰器随后将自动并行化函数调用沿时间轴,并在调用函数时删除use_dask参数。

示例交互式代码使用: 如果您想在Jupyter笔记本中使用frame_by_frame功能,可以像这样使用:

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

示例napari代码: 如果您想在napari插件中使用frame_by_frame功能,可以像这样使用:

from napari_timelapse_processor import frame_by_frame

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

提示: frame_by_frame功能假定输入的napari数据(例如,图像、表面、点等)始终是参数,而任何其他参数始终是关键字参数。如果不是这样,装饰器将不会按预期工作。

# 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)

napari插件是用Cookiecutter@naparicookiecutter-napari-plugin模板生成的。

安装

您可以通过pip安装napari-timelapse-processor

pip install napari-timelapse-processor

贡献

欢迎贡献力量。可以使用tox运行测试,请在提交拉取请求之前确保覆盖率至少保持不变。

许可证

根据BSD-3许可协议分发,“napari-timelapse-processor”是免费和开源软件。

问题

如果您遇到任何问题,请[提交问题]并附上详细描述。

项目详情


下载文件

下载您平台上的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

napari_timelapse_processor-0.0.2.tar.gz (15.8 kB 查看哈希值)

上传时间

构建分布

napari_timelapse_processor-0.0.2-py3-none-any.whl (14.7 kB 查看哈希值)

上传时间 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面