Metadata-Version: 2.5
Name: flimanalyzer
Version: 0.7.0
Summary: Analysis of Fluorescence Lifetime Imaging Microscopy (FLIM) data.
Project-URL: Homepage, https://github.com/uvaKCCI/flimanalyzer
Project-URL: Documentation, https://flimanalyzer.readthedocs.io
Project-URL: Repository, https://github.com/uvaKCCI/flimanalyzer
Project-URL: Changelog, https://github.com/uvaKCCI/flimanalyzer/blob/main/CHANGELOG.md
Project-URL: Issues, https://github.com/uvaKCCI/flimanalyzer/issues
Author-email: Karsten Siller <khsiller@gmail.com>
License-Expression: MIT
License-File: LICENSE
Keywords: FLIM,fluorescence lifetime,fluorescence lifetime imaging,microscopy
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Image Processing
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Classifier: Topic :: Scientific/Engineering :: Visualization
Requires-Python: >=3.12
Requires-Dist: filelock<5,>=3.12
Requires-Dist: joblib<2
Requires-Dist: matplotlib<3.13,>=3.9
Requires-Dist: networkx<4,>=3
Requires-Dist: numpy<3,>=2.1
Requires-Dist: pandas<3,>=2.2.2
Requires-Dist: platformdirs<5,>=4
Requires-Dist: prefect<4,>=3.4.7
Requires-Dist: pydantic-settings<3,>=2.7
Requires-Dist: pydantic<3,>=2.7
Requires-Dist: scikit-learn<2,>=1.5
Requires-Dist: scipy<2,>=1.13
Requires-Dist: seaborn<0.14,>=0.13.2
Requires-Dist: torch<3,>2.7
Requires-Dist: xlsxwriter<4
Provides-Extra: dask
Requires-Dist: prefect-dask<1,>=0.3.7; extra == 'dask'
Provides-Extra: gui
Requires-Dist: pypubsub<5; extra == 'gui'
Requires-Dist: wxpython<4.3,>=4.2.2; extra == 'gui'
Provides-Extra: test
Requires-Dist: pytest-cov>=4.0.0; extra == 'test'
Requires-Dist: pytest-mock>=3.10.0; extra == 'test'
Requires-Dist: pytest-xdist>=3.6; extra == 'test'
Requires-Dist: pytest>=7.0.0; extra == 'test'
Description-Content-Type: text/markdown

# <img src="src/flim/resources/flimanalyzer.png" alt="" width="80" align="top"> FLIMAnalyzer

[![Python](https://img.shields.io/badge/python-3.12%2B-blue)](https://github.com/uvaKCCI/flimanalyzer/blob/main/pyproject.toml) [![PyPI](https://img.shields.io/pypi/v/flimanalyzer)](https://pypi.org/project/flimanalyzer/) [![Tests](https://github.com/uvaKCCI/flimanalyzer/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/uvaKCCI/flimanalyzer/actions/workflows/tests.yml) [![codecov](https://codecov.io/gh/uvaKCCI/flimanalyzer/branch/main/graph/badge.svg)](https://codecov.io/gh/uvaKCCI/flimanalyzer) [![Documentation Status](https://readthedocs.org/projects/flimanalyzer/badge/?version=latest)](https://flimanalyzer.readthedocs.io/en/latest/) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.23426563.svg)](https://doi.org/10.5281/zenodo.23426563)

Python package for analysis of Fluorescence Lifetime Imaging Microscopy (FLIM) data.

Documentation: https://flimanalyzer.readthedocs.io

## Requirements

* Python 3.12 to 3.14
* All Python dependencies, including [PyTorch](https://pytorch.org) and [Prefect](https://www.prefect.io), are declared in `pyproject.toml` and installed automatically.

## Installation

### From PyPI with uv (recommended)

[uv](https://docs.astral.sh/uv/) creates a virtual environment in `.venv` (installing a matching Python if needed). Then install FLIMAnalyzer with its graphical user interface (GUI) into it:

    uv venv --python 3.12
    source .venv/bin/activate    # Windows: .venv\Scripts\activate
    uv pip install "flimanalyzer[gui]"

The `gui` extra installs the GUI. Without it, `uv pip install flimanalyzer` installs only what [batch mode](#run-flimanalyzer-in-batch-mode) needs, for example on a computing cluster. Add `dask` for the optional Dask support (see [Concurrent and distributed execution](#concurrent-and-distributed-execution)), e.g. `"flimanalyzer[gui,dask]"`.

### From PyPI with pip

    python3.12 -m venv .venv
    source .venv/bin/activate    # Windows: .venv\Scripts\activate
    pip install "flimanalyzer[gui]"

### PyTorch and the GPU

Installed from PyPI, FLIMAnalyzer gets PyTorch from PyPI, which provides a different build on each platform:

* **Linux:** the PyPI build includes CUDA, so an NVIDIA GPU is used if its driver is recent enough.
* **Windows:** the PyPI build is CPU-only. For an NVIDIA GPU, install with `uv pip install "flimanalyzer[gui]" --torch-backend=cu130`, or with pip install the CUDA build first: `pip install torch --index-url https://download.pytorch.org/whl/cu130`. See [pytorch.org](https://pytorch.org/get-started/locally/) for other CUDA versions.
* **macOS:** only Apple Silicon is supported, because current PyTorch versions are not available for Intel Macs. The PyPI build uses the Apple GPU (MPS).

### Latest development version

To install the current state of the repository, clone it and let uv create the environment. `uv sync` installs FLIMAnalyzer with the GUI in editable mode, with the exact package versions from `uv.lock` (the versions the tests run with). On Windows and Linux (x86_64), it installs the CUDA 13.0 build of PyTorch:

    git clone https://github.com/uvaKCCI/flimanalyzer.git
    cd flimanalyzer
    uv sync

Without the GUI, with the test dependencies, or with Dask support:

    uv sync --no-group gui
    uv sync --extra test
    uv sync --extra dask

With pip, in a virtual environment in the cloned folder: `pip install -e ".[gui]"`.

### With Docker

The Docker images run only [batch mode](#run-flimanalyzer-in-batch-mode). They do not include the GUI. Each release is published to the GitHub Container Registry:

| Image | |
|---|---|
| `ghcr.io/uvakcci/flimanalyzer:<version>`, `:latest` | with the CUDA build of PyTorch (x86_64, several GB) |
| `ghcr.io/uvakcci/flimanalyzer:<version>-cpu`, `:latest-cpu` | CPU only (x86_64 and ARM), much smaller |

    docker pull ghcr.io/uvakcci/flimanalyzer:latest-cpu

To build an image from the repository instead: with the CUDA 13.0 build of PyTorch, with the build for another CUDA version (here 12.6, for older GPUs), with the CPU-only build, or with Dask support:

    docker build -t flimanalyzer .
    docker build -t flimanalyzer:cu126 --build-arg TORCH_INDEX=https://download.pytorch.org/whl/cu126 .
    docker build -t flimanalyzer:cpu --build-arg TORCH_INDEX=https://download.pytorch.org/whl/cpu .
    docker build -t flimanalyzer:dask --build-arg EXTRAS=dask .

`TORCH_INDEX` replaces PyTorch with the build from that PyTorch package index, in the same PyTorch version (the one in `uv.lock`, currently 2.14.1). Choose the CUDA version that the NVIDIA driver and the GPU of your computer support. PyTorch 2.14.1 is available for CUDA 12.6 (`cu126`), 13.0 (`cu130`, the default) and 13.2 (`cu132`). CUDA 13 needs NVIDIA driver 580 or newer and a GPU of the Turing generation or newer (e.g. T4, RTX 20xx, A100, H100). For older GPUs such as the V100, try the CUDA 12.6 build (`cu126`); check PyTorch's release notes for the GPUs it supports.

`EXTRAS=gui` stops the build with an error, because the images do not support a display.

## Start FLIMAnalyzer with the GUI

With uv, no activation is needed:

    uv run flimanalyzer

In an activated environment:

    flimanalyzer

To open data files (tab- or comma-separated) at startup, each in its own window:

    uv run flimanalyzer -i results.txt more-results.csv

Run `flimanalyzer --help` for all command line options.

## Using a GPU

The autoencoder tools (Autoencoder Run and Autoencoder Augment Data) and workflows (Autoencoder Train, FLIM Data Augmentation Tuning and FLIM Feature Analysis) have a **Device** setting, in the GUI and in batch mode:

* `auto` (default): an NVIDIA GPU (`cuda`) if available, otherwise the Apple GPU (`mps`), otherwise the CPU.
* `cpu`, `cuda` or `mps`: uses that device, or the CPU if it is not available.

Which GPU can be used depends on the PyTorch build that was installed (see [Installation](#installation)). Trained models are saved so that they do not need a GPU, so a model trained on a GPU can also be used on a computer without one.

## Run FLIMAnalyzer in batch mode

`flimbatch` reads data files and runs tools or workflows on them without opening the GUI, for example on a computing cluster. A workflow file, for example the built-in `Import`, says exactly what a run does with the files. A tool runs with its settings from a tool file, which Save Settings... in the tool's dialog writes.

    uv run flimbatch -i data/ -o results/ --run Import --run summarize.json

Each call saves its results in a new folder below `-o`, named after the date and time, with a folder `run-<n>` per `--run`; a workflow file saves the results of the steps it marks to save. `--dry-run` validates the runs against the files without running them. A column that is not in the data (for example `FAD a1%` for `FAD a1[%]`) is an error, unless the tool or workflow file's `processing` section allows the closest column (`"strict": false`). The exit code is 1 if a validation or a task failed. Run `flimbatch --help` for all options.

`flimanalyzer --batch …` does the same as `flimbatch …`, but is deprecated and is removed in 0.8.0. On Windows, use `flimbatch`: `flimanalyzer` starts without a console there, so its messages are not shown.

### In Docker

The image runs `flimbatch`. Make the folder with the data and the tool or workflow files available inside the container as `/work`:

    docker run --rm -v "$PWD:/work" ghcr.io/uvakcci/flimanalyzer:latest-cpu \
        -i data/ -o results/ --run summarize.json --no-prefect-server

* On Linux, add `-u $(id -u)` so that the result files belong to you.
* With the CUDA image, add `--gpus all` to use the GPU.
* With `--no-prefect-server`, each run uses a temporary Prefect server. To report to a Prefect server instead, leave out `--no-prefect-server` and pass the server's address to `docker run`, before the image name, for example `docker run --rm -e PREFECT_API_URL=http://prefect.example.org:4200/api -v "$PWD:/work" ...`. An `-e` after the image name goes to `flimbatch`, which reads it as the executor.

## Prefect server

FLIMAnalyzer runs analyses and workflows as [Prefect](https://www.prefect.io) flows. At startup it looks for a Prefect server in this order:

1. The server configured in the active Prefect profile or in the `PREFECT_API_URL` environment variable, e.g.

       prefect profile use <profile>
       # or
       export PREFECT_API_URL=https://my-prefect-server/api

2. A server already running locally at `http://127.0.0.1:4200/api`.
3. If none is found, FLIMAnalyzer starts a local server (`prefect server start`) and stops it again when FLIMAnalyzer closes. If port 4200 is taken, the server is started on a free port. The server's output is written to `prefect-server.log`. If no server can be started, FLIMAnalyzer stops with an error.

The server found or started at startup is used for all runs until FLIMAnalyzer closes.

Flow and task runs can be inspected in the Prefect UI of the server in use, e.g. [http://127.0.0.1:4200](http://127.0.0.1:4200) for a local server. To keep a local server running across sessions, start it yourself in a separate terminal with `uv run prefect server start`. Use `--no-prefect-server` to skip starting a server; Prefect then starts a temporary server for each run, which stops when the run ends.

## Concurrent and distributed execution

Every tool and workflow step runs as a Prefect task. A task starts as soon as the results it needs are ready. Tasks that do not depend on each other run concurrently, without waiting for each other. Tasks that draw figures take turns, because matplotlib's pyplot is not thread-safe.

By default, up to one task per CPU core runs at a time, as threads. To change that number:

    uv run flimanalyzer -e local:workers=4

`workers=1` runs one task at a time. Prefect's `PREFECT_TASKS_RUNNER_THREAD_POOL_MAX_WORKERS` setting, if set, is used as the default.

FLIMAnalyzer can also use [Dask](https://www.dask.org). Dask support is optional; install it with `uv sync --extra dask` (or `pip install -e ".[dask]"`).

On a *single node*, start a local Dask cluster:

    uv run flimanalyzer -e dask-local:workers=8,scheduler=processes

As a general guideline, adjust `workers` to match the number of CPU cores in your system. Use `scheduler=threads` to run the workers as threads instead of processes.

To use an existing Dask cluster:

    uv run flimanalyzer -e dask:address=tcp://<scheduler-host>:8786

### Concurrency limits

Prefect applies [tag concurrency limits](https://docs.prefect.io/v3/develop/task-run-limits) set on the Prefect server, whichever executor is used. Every task is tagged with its tool's name as shown in the menu (e.g. `Autoencoder Train`, not the Python class name), also as a step of a workflow; workflow steps can carry more tags, which also name their results folders. For example, to let only one autoencoder training run at a time, also inside workflows:

    uv run prefect concurrency-limit create "Autoencoder Train" 1

`uv run prefect concurrency-limit ls` lists the limits, and `uv run prefect concurrency-limit delete <tag>` removes one.

## How to cite

If you use FLIMAnalyzer, please cite:

1. **The original publication**, in all cases:

   Zhang J, Wallrabe H, Siller K, Mbogo B, Cassidy T, Alam SR, Periasamy A. Measuring metabolic changes in cancer cells using two-photon fluorescence lifetime imaging microscopy and machine-learning analysis. *Journal of Biophotonics* 18(1), e202400426 (2025). [doi:10.1002/jbio.202400426](https://doi.org/10.1002/jbio.202400426)

2. **The publication closest to the version you used**, plus that release's software DOI, from the table below. Use the newest release that is not newer than your version. The version is shown in the FLIMAnalyzer window title.

| Your version | Publication | Software DOI |
|---|---|---|
| v0.5.0 or later | Alam SR, Siller K, Dreicer R, Periasamy A. Label-free optical biomarker for prostate cancer diagnosis. *Molecular Medicine* 32(1), 165 (2026). [doi:10.1186/s10020-026-01605-2](https://doi.org/10.1186/s10020-026-01605-2) | [10.5281/zenodo.23438157](https://doi.org/10.5281/zenodo.23438157) |
| v0.4.1 or earlier | Zhang et al. (2025), the original publication above | [10.5281/zenodo.23426564](https://doi.org/10.5281/zenodo.23426564) |

The concept DOI [10.5281/zenodo.23426563](https://doi.org/10.5281/zenodo.23426563) covers all versions archived on Zenodo and resolves to the latest of them. Not every release is archived on Zenodo; the table above lists the versions used in publications. Citation metadata is also in [`CITATION.cff`](CITATION.cff); GitHub shows it under "Cite this repository".

## Development

Run the test suite:

    uv sync --extra test
    uv run pytest

Tests that run flows use a temporary Prefect server and database and do not report to any configured server.

The tests run one after another. The GUI tests depend on wxPython's event loop and on timing, so they must not run in parallel. Only the core tests (no GUI) can run in parallel, one process per CPU core, with `pytest-xdist`:

    uv run pytest -n auto tests/core

Build the documentation (output in `docs/_build/html`):

    uv run --group docs sphinx-build -b html docs docs/_build/html

The `docs` dependency group contains only Sphinx and the lightweight packages needed to document the code; `docs/conf.py` imports `flim` from the source tree and mocks wxPython, PyTorch and Prefect. This is also how the documentation is built on Read the Docs (see `.readthedocs.yaml`).
