Yet another Bio-Formats wrapper for python
Project description
bffile
Modern Bio-Formats wrapper for python
Documentation 📖
https://imaging-formats.github.io/bffile/
Installation
pip install bffile
Usage
Quick Start
from bffile import BioFile
import numpy as np
with BioFile("tests/data/ND2_dims_p4z5t3c2y32x32.nd2") as bf:
# Access OME metadata
print(bf.ome_metadata) # ome_types.OME object
# Get lazy array for series 0 (no data loaded yet)
arr = bf.as_array(series=0)
print(arr.shape, arr.dtype) # (T, C, Z, Y, X) shape
# Index specific planes on-demand
plane = arr[0, 0, 2] # Only reads this plane
roi = arr[:, :, :, 100:200, 50:150] # Sub-regions
# Materialize all data when needed
full_data = np.array(arr)
# Or use dask for lazy computation
darr = bf.to_dask(series=0, chunks="auto")
result = darr.mean(axis=2).compute()
For simple cases, use imread() to load a single series/resolution into memory:
from bffile import imread
# Read series0/resolution0 into numpy array
# series and resolution parameters are optional and default to 0
data = imread("image.nd2", series=0, resolution=0)
print(data.shape, data.dtype) # (T, C, Z, Y, X) array
Selecting Bio-Formats Version
Bio-Formats is downloaded at runtime (via jgo).
By default, it will download the latest ome:formats-gpl:RELEASE maven artifact.
You can specify a different version by setting the BIOFORMATS_VERSION environment variable:
This variable accepts either a simple version string (e.g. 6.0.1) or a full maven coordinate
(e.g. ome:formats-gpl:6.0.1 or ome:formats-bsd:7.3.1):
# Use Bio-Formats 6.0.1 (GPL-licensed)
export BIOFORMATS_VERSION="6.0.1"
# Use BSD-licensed Bio-Formats 7.3.1
export BIOFORMATS_VERSION="ome:formats-bsd:7.3.1"
To see the currently installed version of Bio-Formats, you can check the
BioFile.bioformats_version static method:
from bffile import BioFile
print(BioFile.bioformats_version()) # e.g. "8.1.1"
and to see the full maven coordinate that was used:
from bffile import BioFile
print(BioFile.bioformats_maven_coordinate()) # e.g. "ome:formats-gpl:8.1.1"
[!NOTE] We test back to version 6.0.1, but older versions may also work. If you specifically need this code to work with an older version of bioformats, please open an issue.
Java Runtime
[!TIP] No manual Java installation required!
This package automatically downloads and manages the Java runtime using cjdk (via scyjava).
By default, scyjava uses Zulu JRE 11 (defined here). You can configure the Java version and/or vendor using environment variables:
# Use Adoptium JDK 17
export BFF_JAVA_VERSION=17
export BFF_JAVA_VENDOR=adoptium
# Use Temurin JDK 21
export BFF_JAVA_VERSION=21
export BFF_JAVA_VENDOR=temurin
Available vendors: zulu-jre, zulu, adoptium, temurin, and
other vendors listed in cjdk
Java 8 Support
Bffile is not currently expected to work with Java 8, as jpype has
deprecated support for Java 8 as of jpype version 1.6. If you do want to try
with Java 8, you will minimally need to explicitly pin jpype<1.6. If this is
an important use case for you, please open an issue to discuss Java 8 support.
License
Licensing is a bit complicated for this project, so please read carefully.
- All code in this
bffilerepository is licensed under the BSD-3-Clause License. You may use and distribute this code under the terms of the BSD-3-Clause License. - However, a user who installs
bffilefrom PyPI will, by default, end up with Java jars that are licensed under the GPL-2.0 License (read below). As such, this package is listed on PyPI as GPL-2.0-or-later.
When you run bffile for the first time, it will automatically download a number
of Java jars (via jgo), each of which has its
own license. By default, bffile downloads the
ome:formats-gpl:RELEASE
maven artifact.
ome:formats-gplis licensed under the GPLv2+ License
If you would like to use bffile without any GPL-licensed jars, you can instead
opt into using
ome:formats-bsd by
setting the BIOFORMATS_VERSION environment variable:
BIOFORMATS_VERSION="ome:formats-bsd"
ome:formats-bsdis licensed under the BSD-2-Clause License
If you need a package that defaults to BSD-licensed jars (and ships as
BSD-3 on PyPI), open an issue to discuss a bffile-bsd variant.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bffile-0.1.0.tar.gz.
File metadata
- Download URL: bffile-0.1.0.tar.gz
- Upload date:
- Size: 92.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a751f2a325a9bf61a9ec210af147c6c8e5a21e74bc843570e45653ddb4cc25d
|
|
| MD5 |
409cedc9b4d6935439872d139cf26058
|
|
| BLAKE2b-256 |
bb05157be902b8b5e7fb9511a0d615454df582da3ab9bffad83c3b524f233f2f
|
Provenance
The following attestation bundles were made for bffile-0.1.0.tar.gz:
Publisher:
ci.yml on imaging-formats/bffile
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bffile-0.1.0.tar.gz -
Subject digest:
9a751f2a325a9bf61a9ec210af147c6c8e5a21e74bc843570e45653ddb4cc25d - Sigstore transparency entry: 1091766880
- Sigstore integration time:
-
Permalink:
imaging-formats/bffile@837a47db0528a52454f9155d45570280504b49e3 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/imaging-formats
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@837a47db0528a52454f9155d45570280504b49e3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file bffile-0.1.0-py3-none-any.whl.
File metadata
- Download URL: bffile-0.1.0-py3-none-any.whl
- Upload date:
- Size: 62.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2523eef28a8305567b8dc6612516c39018323ca5f1de21496b541ce927bafa85
|
|
| MD5 |
a2a8212c2c2e30d46cecd646fdbafc78
|
|
| BLAKE2b-256 |
c3ea8214243816c570ce52b7be2eaea59e72ef10730a4a027db6e6538f19b9e8
|
Provenance
The following attestation bundles were made for bffile-0.1.0-py3-none-any.whl:
Publisher:
ci.yml on imaging-formats/bffile
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bffile-0.1.0-py3-none-any.whl -
Subject digest:
2523eef28a8305567b8dc6612516c39018323ca5f1de21496b541ce927bafa85 - Sigstore transparency entry: 1091766916
- Sigstore integration time:
-
Permalink:
imaging-formats/bffile@837a47db0528a52454f9155d45570280504b49e3 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/imaging-formats
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@837a47db0528a52454f9155d45570280504b49e3 -
Trigger Event:
push
-
Statement type: