napari-lazy-openslide
An experimental plugin to lazily load multiscale whole-slide tiff images with openslide and dask.
This napari plugin was generated with Cookiecutter using with @napari's cookiecutter-napari-plugin template.
Installation
Step 1.) Make sure you have OpenSlide installed. Download instructions here.
NOTE: Installation on macOS is easiest via Homebrew:
brew install openslide. Up-to-date and multiplatform binaries foropenslideare also avaiable viaconda:conda install -c sdvillal openslide-python
Step 2.) Install napari-lazy-openslide via pip:
pip install napari-lazy-openslide
Usage
Napari plugin
$ napari tumor_004.tif
By installing this package via pip, the plugin should be recognized by napari. The plugin
attempts to read image formats recognized by openslide that are multiscale
(openslide.OpenSlide.level_count > 1).
It should be noted that napari-lazy-openslide is experimental and has primarily
been tested with CAMELYON16 and CAMELYON17 datasets, which can be
downloaded here.
Using OpenSlideStore with Zarr and Dask
The OpenSlideStore class wraps an openslide.OpenSlide object as a valid Zarr store.
The underlying openslide image pyramid is translated to the Zarr multiscales extension,
where each level of the pyramid is a separate 3D zarr.Array with shape (y, x, 4).
import dask.array as da
import zarr
from napari_lazy_openslide import OpenSlideStore
store = OpenSlideStore('tumor_004.tif')
grp = zarr.open(store, mode="r")
# The OpenSlideStore implements the multiscales extension
# https://forum.image.sc/t/multiscale-arrays-v0-1/37930
datasets = grp.attrs["multiscales"][0]["datasets"]
pyramid = [grp.get(d["path"]) for d in datasets]
print(pyramid)
# [
# <zarr.core.Array '/0' (23705, 29879, 4) uint8 read-only>,
# <zarr.core.Array '/1' (5926, 7469, 4) uint8 read-only>,
# <zarr.core.Array '/2' (2963, 3734, 4) uint8 read-only>,
# ]
pyramid = [da.from_zarr(store, component=d["path"]) for d in datasets]
print(pyramid)
# [
# dask.array<from-zarr, shape=(23705, 29879, 4), dtype=uint8, chunksize=(512, 512, 4), chunktype=numpy.ndarray>,
# dask.array<from-zarr, shape=(5926, 7469, 4), dtype=uint8, chunksize=(512, 512, 4), chunktype=numpy.ndarray>,
# dask.array<from-zarr, shape=(2963, 3734, 4), dtype=uint8, chunksize=(512, 512, 4), chunktype=numpy.ndarray>,
# ]
# Now you can use numpy-like indexing with openslide, reading data into memory lazily!
low_res = pyramid[-1][:]
region = pyramid[0][y_start:y_end, x_start:x_end]
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.
Issues
If you encounter any problems, please file an issue along with a detailed description.
Metadata
Release files for napari-lazy-openslide 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| napari-lazy-openslide-0.3.0.tar.gz | 9.4 MB | Without provenance | Details for napari-lazy-openslide-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| napari_lazy_openslide-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for napari_lazy_openslide-0.3.0-py3-none-any.whl |
Total release size: 9.4 MB
Release files / napari-lazy-openslide-0.3.0.tar.gz
| Download URL | napari-lazy-openslide-0.3.0.tar.gz |
|---|---|
| Size | 9.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
faf95a770b6a99ccd8c0e04bc6d2431c270258bb8912169e277377e6bc31f4d7
|
|
BLAKE2b-256 checksum How to use checksums |
eb1e6331a108dbe7b74eb9107fbe56ca2dfe69df348cc9fc5afad3b3303b10dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.10.4
|
Release files / napari_lazy_openslide-0.3.0-py3-none-any.whl
| Download URL | napari_lazy_openslide-0.3.0-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
efc5510d09f3c34e26705efecff8c2e7f331d720ab2bff53ae642850377ffbc9
|
|
BLAKE2b-256 checksum How to use checksums |
26a08d652eaa880ba0d888e8e95cbff15824442932b7272e87748115f547a764
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.10.4
|
Security for napari-lazy-openslide 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.