napari-timelapse-processor


Namenapari-timelapse-processor JSON
Version 0.0.2 PyPI version JSON
download
home_pageNone
Summarymeta plugin to ease processing timelapse image data
upload_time2024-08-16 09:54:10
maintainerNone
docs_urlNone
authorJohannes Soltwedel
requires_python>=3.9
license Copyright (c) 2024, Johannes Soltwedel All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # napari-timelapse-processor

[![License BSD-3](https://img.shields.io/pypi/l/napari-timelapse-processor.svg?color=green)](https://github.com/jo-mueller/napari-timelapse-processor/raw/main/LICENSE)
[![PyPI](https://img.shields.io/pypi/v/napari-timelapse-processor.svg?color=green)](https://pypi.org/project/napari-timelapse-processor)
[![Python Version](https://img.shields.io/pypi/pyversions/napari-timelapse-processor.svg?color=green)](https://python.org)
[![tests](https://github.com/jo-mueller/napari-timelapse-processor/workflows/tests/badge.svg)](https://github.com/jo-mueller/napari-timelapse-processor/actions)
[![codecov](https://codecov.io/gh/jo-mueller/napari-timelapse-processor/branch/main/graph/badge.svg)](https://codecov.io/gh/jo-mueller/napari-timelapse-processor)
[![napari hub](https://img.shields.io/endpoint?url=https://api.napari-hub.org/shields/napari-timelapse-processor)](https://napari-hub.org/plugins/napari-timelapse-processor)

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:**

```python
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:**

```python
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**

```python
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](https://distributed.dask.org/en/latest/). 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:

```python

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:

```python
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.

```python

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

<!--
Don't miss the full getting started guide to set up your new package:
https://github.com/napari/cookiecutter-napari-plugin#getting-started

and review the napari docs for plugin developers:
https://napari.org/stable/plugins/index.html
-->

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

[napari]: https://github.com/napari/napari
[Cookiecutter]: https://github.com/audreyr/cookiecutter
[@napari]: https://github.com/napari
[MIT]: http://opensource.org/licenses/MIT
[BSD-3]: http://opensource.org/licenses/BSD-3-Clause
[GNU GPL v3.0]: http://www.gnu.org/licenses/gpl-3.0.txt
[GNU LGPL v3.0]: http://www.gnu.org/licenses/lgpl-3.0.txt
[Apache Software License 2.0]: http://www.apache.org/licenses/LICENSE-2.0
[Mozilla Public License 2.0]: https://www.mozilla.org/media/MPL/2.0/index.txt
[cookiecutter-napari-plugin]: https://github.com/napari/cookiecutter-napari-plugin

[napari]: https://github.com/napari/napari
[tox]: https://tox.readthedocs.io/en/latest/
[pip]: https://pypi.org/project/pip/
[PyPI]: https://pypi.org/

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "napari-timelapse-processor",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Johannes Soltwedel",
    "author_email": "johannes_richard.soltwedel@tu-dresden.de",
    "download_url": "https://files.pythonhosted.org/packages/26/94/22d4bd7451ffdaaad13d42e586b9ffa8306d1020051939b817b8fa96f254/napari_timelapse_processor-0.0.2.tar.gz",
    "platform": null,
    "description": "# napari-timelapse-processor\n\n[![License BSD-3](https://img.shields.io/pypi/l/napari-timelapse-processor.svg?color=green)](https://github.com/jo-mueller/napari-timelapse-processor/raw/main/LICENSE)\n[![PyPI](https://img.shields.io/pypi/v/napari-timelapse-processor.svg?color=green)](https://pypi.org/project/napari-timelapse-processor)\n[![Python Version](https://img.shields.io/pypi/pyversions/napari-timelapse-processor.svg?color=green)](https://python.org)\n[![tests](https://github.com/jo-mueller/napari-timelapse-processor/workflows/tests/badge.svg)](https://github.com/jo-mueller/napari-timelapse-processor/actions)\n[![codecov](https://codecov.io/gh/jo-mueller/napari-timelapse-processor/branch/main/graph/badge.svg)](https://codecov.io/gh/jo-mueller/napari-timelapse-processor)\n[![napari hub](https://img.shields.io/endpoint?url=https://api.napari-hub.org/shields/napari-timelapse-processor)](https://napari-hub.org/plugins/napari-timelapse-processor)\n\nmeta plugin to ease processing timelapse image data\n\n## API\n\nThis plugin exposes two principal funcionalities:\n\n### TimelapseConverter\n\nThe `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:\n\n- `napari.layers.Image`\n- `napari.layers.Labels`\n- `napari.layers.Points`\n- `napari.layers.Vectors`\n- `napari.layers.Surface`\n\n`napari.layers.Tracks` are intrinsically 4D and thus not supported.\n\n**Unstacking example usage:**\n\n```python\nfrom napari_timelapse_processor import TimelapseConverter\nimport numpy as np\n\nimage_4d = np.random.rand(10, 32, 32, 32)  # 10 timepoints of 32x32x32 data\nconverter = TimelapseConverter()\nlist_of_images = converter.unstack(image_4d, layertype='napari.types.ImageData')\n```\n\n**Stacking example usage:**\n\n```python\nfrom napari_timelapse_processor import TimelapseConverter\nimport numpy as np\n\nrandom_points = [np.random.rand(10, 3)  for _ in range(10)]  # 10 timepoints of 10 random 3D points\nconverter = TimelapseConverter()\n\n# stack the points into a single 4D layer\nstacked_points = converter.stack(random_points, layertype='napari.types.PointsData')\n```\n\nThe `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.\n\n**Layer example usage**\n\n```python\nfrom napari_timelapse_processor import TimelapseConverter\nimport numpy as np\nfrom napari.layers import Points\nimport pandas as pd\n\nrandom_points = [np.random.rand(10, 3)  for _ in range(10)]  # 10 timepoints of 10 random 3D points\nrandom_features = [pd.DataFrame(np.random.rand(10)) for _ in range(10)]  # 10 timepoints of 10 random feature values\n\n# create a list of 10 Points layers\npoints = [Points(random_points[i], properties=random_features[i]) for i in range(10)]\n\nconverter = TimelapseConverter()\nstacked_points = converter.stack(points, layertype='napari.layers.Points')\n```\n\n## frame_by_frame\n\nThe 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:\n\n- `napari.types.ImageData`\n- `napari.types.LabelsData`\n- `napari.types.PointsData`\n- `napari.types.VectorsData`\n- `napari.types.SurfaceData`\n- `napari.layers.Layer`\n- `napari.layers.Image`\n- `napari.layers.Labels`\n- `napari.layers.Points`\n- `napari.layers.Vectors`\n- `napari.layers.Surface`\n\nAdditionally, the `frame_by_frame` supports parallelization with [dask.distributed](https://distributed.dask.org/en/latest/). 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.\n\n**Example interactive code usage:** If you want to use the `frame_by_frame` functionality in, say, a Jupyter notebook, use it like this:\n\n```python\n\nfrom napari_timelapse_processor import frame_by_frame\nimport numpy as np\n\ndef my_function(image: 'napari.types.ImageData') -> 'napari.types.ImageData':\n    return 2 * image\n\nimage_4d = np.random.rand(10, 32, 32, 32)  # 10 timepoints of 32x32x32 data\n\nimage_4d_processed = frame_by_frame(my_function)(image_4d)  # without dask\nimage_4d_processed = frame_by_frame(my_function)(image_4d, use_dask=True)  # with dask\n```\n\n**Example napari code** If you want to use the `frame_by_frame` functionality in a napari plugin, use it like this:\n\n```python\nfrom napari_timelapse_processor import frame_by_frame\n\n@frame_by_frame\ndef my_function(image: 'napari.types.ImageData') -> 'napari.types.ImageData':\n    return 2 * image\n```\n\n**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.\n\n```python\n\n# This works\nframe_by_frame(my_function)(image_4d, some_parameter=2, use_dask=True)\n\n# This does not work\nframe_by_frame(my_function)(image=image_4d, some_parameter=2, use_dask=True)\n```\n\n----------------------------------\n\nThis [napari] plugin was generated with [Cookiecutter] using [@napari]'s [cookiecutter-napari-plugin] template.\n\n<!--\nDon't miss the full getting started guide to set up your new package:\nhttps://github.com/napari/cookiecutter-napari-plugin#getting-started\n\nand review the napari docs for plugin developers:\nhttps://napari.org/stable/plugins/index.html\n-->\n\n## Installation\n\nYou can install `napari-timelapse-processor` via [pip]:\n\n    pip install napari-timelapse-processor\n\n\n\n\n## Contributing\n\nContributions are very welcome. Tests can be run with [tox], please ensure\nthe coverage at least stays the same before you submit a pull request.\n\n## License\n\nDistributed under the terms of the [BSD-3] license,\n\"napari-timelapse-processor\" is free and open source software\n\n## Issues\n\nIf you encounter any problems, please [file an issue] along with a detailed description.\n\n[napari]: https://github.com/napari/napari\n[Cookiecutter]: https://github.com/audreyr/cookiecutter\n[@napari]: https://github.com/napari\n[MIT]: http://opensource.org/licenses/MIT\n[BSD-3]: http://opensource.org/licenses/BSD-3-Clause\n[GNU GPL v3.0]: http://www.gnu.org/licenses/gpl-3.0.txt\n[GNU LGPL v3.0]: http://www.gnu.org/licenses/lgpl-3.0.txt\n[Apache Software License 2.0]: http://www.apache.org/licenses/LICENSE-2.0\n[Mozilla Public License 2.0]: https://www.mozilla.org/media/MPL/2.0/index.txt\n[cookiecutter-napari-plugin]: https://github.com/napari/cookiecutter-napari-plugin\n\n[napari]: https://github.com/napari/napari\n[tox]: https://tox.readthedocs.io/en/latest/\n[pip]: https://pypi.org/project/pip/\n[PyPI]: https://pypi.org/\n",
    "bugtrack_url": null,
    "license": " Copyright (c) 2024, Johannes Soltwedel All rights reserved.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.  * Neither the name of copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ",
    "summary": "meta plugin to ease processing timelapse image data",
    "version": "0.0.2",
    "project_urls": {
        "Repository": "https://github.com/jo-mueller/napari-timelapse-processor.git"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "73f21daccddb396d78e24223dc2e635a3b13fe5a4c7d6512ae511eaaa5f6521d",
                "md5": "381248935875ce28e2198ed6fb51a0e3",
                "sha256": "632036eb251e701f9c8d92e74ecb44350d326cd4112b51044058b86558fef6f5"
            },
            "downloads": -1,
            "filename": "napari_timelapse_processor-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "381248935875ce28e2198ed6fb51a0e3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 14705,
            "upload_time": "2024-08-16T09:54:08",
            "upload_time_iso_8601": "2024-08-16T09:54:08.322922Z",
            "url": "https://files.pythonhosted.org/packages/73/f2/1daccddb396d78e24223dc2e635a3b13fe5a4c7d6512ae511eaaa5f6521d/napari_timelapse_processor-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "269422d4bd7451ffdaaad13d42e586b9ffa8306d1020051939b817b8fa96f254",
                "md5": "9eb83bc8909aa846e7ef565908f7565a",
                "sha256": "ddcb48a137f5f8798f22f8030a8828d2dfd834da6207b4fdd23442e91c92b7c5"
            },
            "downloads": -1,
            "filename": "napari_timelapse_processor-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "9eb83bc8909aa846e7ef565908f7565a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 15792,
            "upload_time": "2024-08-16T09:54:10",
            "upload_time_iso_8601": "2024-08-16T09:54:10.937180Z",
            "url": "https://files.pythonhosted.org/packages/26/94/22d4bd7451ffdaaad13d42e586b9ffa8306d1020051939b817b8fa96f254/napari_timelapse_processor-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-16 09:54:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jo-mueller",
    "github_project": "napari-timelapse-processor",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "napari-timelapse-processor"
}
        
Elapsed time: 9.56811s