Metadata-Version: 2.4
Name: bioio-nd2
Version: 1.6.2
Summary: A BioIO reader plugin for reading ND2 images.
Author-email: bioio-devs <brian.whitney@alleninstitute.org>
License: MIT License
Project-URL: Homepage, https://github.com/bioio-devs/bioio-nd2
Project-URL: Bug Tracker, https://github.com/bioio-devs/bioio-nd2/issues
Project-URL: Documentation, https://bioio-devs.github.io/bioio-nd2
Project-URL: User Support, https://github.com/bioio-devs/bioio-nd2/issues
Classifier: Development Status :: 4 - Beta
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: bioio-base>=3.0.0
Requires-Dist: nd2[legacy]>=0.10.3
Requires-Dist: dask[array]>=2021.4.1
Requires-Dist: fsspec>=2022.8.0
Requires-Dist: numpy>=1.16
Requires-Dist: PyYAML>=6.0
Requires-Dist: xarray>=0.16.1
Provides-Extra: lint
Requires-Dist: pre-commit>=2.20.0; extra == "lint"
Provides-Extra: test
Requires-Dist: coverage>=5.1; extra == "test"
Requires-Dist: pytest>=5.4.3; extra == "test"
Requires-Dist: pytest-cov>=2.9.0; extra == "test"
Requires-Dist: pytest-raises>=0.11; extra == "test"
Requires-Dist: types-PyYAML>=6.0.12.9; extra == "test"
Dynamic: license-file

# bioio-nd2

[![Build Status](https://github.com/bioio-devs/bioio-nd2/actions/workflows/ci.yml/badge.svg)](https://github.com/bioio-devs/bioio-nd2/actions)
[![PyPI version](https://badge.fury.io/py/bioio-nd2.svg)](https://badge.fury.io/py/bioio-nd2)
[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
[![Python 3.10–3.13](https://img.shields.io/badge/python-3.10--3.13-blue.svg)](https://www.python.org/downloads/)

A BioIO reader plugin for reading nd2 (Nikon microscope) files using `nd2`

---


## Documentation

[See the full documentation on our GitHub pages site](https://bioio-devs.github.io/bioio/OVERVIEW.html) - the generic use and installation instructions there will work for this package.

Information about the base reader this package relies on can be found in the `bioio-base` repository [here](https://github.com/bioio-devs/bioio-base)

## Installation

**Stable Release:** `pip install bioio-nd2`<br>
**Development Head:** `pip install git+https://github.com/bioio-devs/bioio-nd2.git`

## Example Usage (see full documentation for more examples)

Install bioio-nd2 alongside bioio:

`pip install bioio bioio-nd2`


This example shows a simple use case for just accessing the pixel data of the image
by explicitly passing this `Reader` into the `BioImage`. Passing the `Reader` into
the `BioImage` instance is optional as `bioio` will automatically detect installed
plug-ins and auto-select the most recently installed plug-in that supports the file
passed in.
```python
from bioio import BioImage
import bioio_nd2

img = BioImage("my_file.nd2", reader=bioio_nd2.Reader)
img.data
```

## Multi-Well Plate & Well Assignment Support (ND2)

`bioio-nd2` includes support for mapping ND2 XY stage positions to
**multi-well plate positions** (e.g. A1, B3, H12). This is primarily
intended for experiments acquired using Nikon’s **XYPosLoop** functionality
on multi-well plates.

> ⚠️ If the ND2 file does **not** contain XY position metadata (`XYPosLoop`),
> no well mapping is performed and `row` / `column` will be `None`.

A standard 96-well plate geometry is available as PLATE_96

```python
from bioio import BioImage
import bioio_nd2
from bioio_nd2.plates import PLATE_96

img = BioImage(
    "my_file.nd2",
    reader=bioio_nd2.Reader,
    plate=PLATE_96,
)

img.set_scene(0)

img.reader.row     # e.g. "B"
img.reader.column  # e.g. "3"
```

### Custom Plate Geometries

Users may define their own plate geometry and pass it to the reader.

```python
from bioio import BioImage
import bioio_nd2
from bioio_nd2.plates import Plate, WellAssignmentMode

custom_plate = Plate(
    name="custom_96",
    rows=list("ABCDEFGH")[::-1],
    cols=[str(i) for i in range(1, 13)],
    plate_width_mm=126.6,
    plate_height_mm=85.7,
    a1_offset_mm=(14.3, 11.36),
    well_spacing_um=9000.0,
    well_radius_um=6210.0 / 2,
    assignment_mode=WellAssignmentMode.CLOSEST,
)

img = BioImage(
    "my_file.nd2",
    reader=bioio_nd2.Reader,
    plate=custom_plate,
)
```

---

### Controlling well assignment strictness

The plate definition includes a **well assignment mode** that controls how
strictly stage positions must correspond to a physical well.

Available modes:

| Mode           | Behavior                                             |
| -------------- | ---------------------------------------------------- |
| `CLOSEST`      | Always assign the nearest well (most permissive)     |
| `WITHIN_WELL`  | Assign only if position falls within the well radius |
| `HALF_SPACING` | Assign only if within half the inter-well spacing    |

In strict modes, scenes that fall outside the allowed region will have
`row` / `column` set to `None`.

---

## Issues
[_Click here to view all open issues in bioio-devs organization at once_](https://github.com/search?q=user%3Abioio-devs+is%3Aissue+is%3Aopen&type=issues&ref=advsearch) or check this repository's issue tab.


## Development

See [CONTRIBUTING.md](CONTRIBUTING.md) for information related to developing the code.
