Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:
MACOSX_DEPLOYMENT_TARGET: "10.15"
strategy:
matrix:
os: [ubuntu-22.04, macos-15-intel, windows-latest]
os: [ubuntu-22.04, macos-15-intel, windows-2022]
cibw_archs: ["auto64"]
cibw_build: ["cp310", "cp311", "cp312", "cp313"]
cibw_build: ["cp310", "cp311", "cp312", "cp313", "cp314", "cp315"]

steps:
- uses: actions/checkout@v3
Expand All @@ -30,11 +30,11 @@ jobs:
name: Add MSVS Path

- name: Add NASM
if: matrix.os == 'windows-latest'
if: matrix.os == 'windows-2022'
uses: ilammy/setup-nasm@v1

- name: Add Ninja
if: matrix.os == 'windows-latest'
if: matrix.os == 'windows-2022'
uses: seanmiddleditch/gha-setup-ninja@master

- uses: actions/setup-python@v4
Expand Down Expand Up @@ -89,10 +89,12 @@ jobs:
CIBW_ARCHS: ${{ matrix.cibw_archs }}
CIBW_BEFORE_TEST_LINUX: dnf -y module reset maven || true &&
dnf -y module enable maven:3.8 &&
dnf -y install --setopt=install_weak_deps=False java-17-openjdk-headless &&
dnf -y install --setopt=install_weak_deps=False java-17-openjdk-devel &&
dnf -y install --setopt=install_weak_deps=False maven maven-openjdk17
CIBW_TEST_REQUIRES: bfio requests numpy ome_zarr
CIBW_TEST_REQUIRES: bfio requests numpy
CIBW_TEST_COMMAND: python -W default -m unittest discover -s {project}/tests -v
# ponytail: jpype1/numcodecs (via bfio) have no cp315 wheels on Linux/Windows; remove once they do
CIBW_TEST_SKIP: "cp315-manylinux_* cp315-win_*"

- name: Install Dependencies
run: python -m pip install --upgrade twine requests
Expand All @@ -111,9 +113,9 @@ jobs:
MACOSX_DEPLOYMENT_TARGET: "11.0"
strategy:
matrix:
os: [macos-14]
os: [macos-15]
cibw_archs: ["arm64"]
cibw_build: ["cp310", "cp311", "cp312", "cp313"]
cibw_build: ["cp310", "cp311", "cp312", "cp313", "cp314", "cp315"]

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -151,7 +153,7 @@ jobs:
DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-listdeps {wheel} &&
DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-wheel --require-archs {delocate_archs} -w {dest_dir} {wheel}
CIBW_ARCHS: ${{ matrix.cibw_archs }}
CIBW_TEST_REQUIRES: bfio requests numpy ome_zarr
CIBW_TEST_REQUIRES: bfio requests numpy
CIBW_TEST_COMMAND: python -W default -m unittest discover -s {project}/tests -v

- name: Install Dependencies
Expand Down
20 changes: 11 additions & 9 deletions .github/workflows/wheel_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
MACOSX_DEPLOYMENT_TARGET: "10.15"
strategy:
matrix:
os: [ubuntu-22.04, macos-15-intel, windows-latest]
os: [ubuntu-22.04, macos-15-intel, windows-2022]
cibw_archs: ["auto64"]
cibw_build: ["cp310", "cp311", "cp312", "cp313"]
cibw_build: ["cp310", "cp311", "cp312", "cp313", "cp314", "cp315"]

steps:
- uses: actions/checkout@v3
Expand All @@ -29,11 +29,11 @@ jobs:
name: Add MSVS Path

- name: Add NASM
if: matrix.os == 'windows-latest'
if: matrix.os == 'windows-2022'
uses: ilammy/setup-nasm@v1

- name: Add Ninja
if: matrix.os == 'windows-latest'
if: matrix.os == 'windows-2022'
uses: seanmiddleditch/gha-setup-ninja@master

- uses: actions/setup-python@v4
Expand Down Expand Up @@ -88,10 +88,12 @@ jobs:
CIBW_ARCHS: ${{ matrix.cibw_archs }}
CIBW_BEFORE_TEST_LINUX: dnf -y module reset maven || true &&
dnf -y module enable maven:3.8 &&
dnf -y install --setopt=install_weak_deps=False java-17-openjdk-headless &&
dnf -y install --setopt=install_weak_deps=False java-17-openjdk-devel &&
dnf -y install --setopt=install_weak_deps=False maven maven-openjdk17
CIBW_TEST_REQUIRES: "bfio requests numpy ome_zarr"
CIBW_TEST_REQUIRES: "bfio requests numpy"
CIBW_TEST_COMMAND: python -W default -m unittest discover -s {project}/tests -v
# ponytail: jpype1/numcodecs (via bfio) have no cp315 wheels on Linux/Windows; remove once they do
CIBW_TEST_SKIP: "cp315-manylinux_* cp315-win_*"

- name: Upload Artifact
uses: actions/upload-artifact@v4
Expand All @@ -109,9 +111,9 @@ jobs:
MACOSX_DEPLOYMENT_TARGET: "11.0"
strategy:
matrix:
os: [macos-14]
os: [macos-15]
cibw_archs: ["arm64"]
cibw_build: ["cp310", "cp311", "cp312", "cp313"]
cibw_build: ["cp310", "cp311", "cp312", "cp313", "cp314", "cp315"]

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -149,7 +151,7 @@ jobs:
DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-listdeps {wheel} &&
DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-wheel --require-archs {delocate_archs} -w {dest_dir} {wheel}
CIBW_ARCHS: ${{ matrix.cibw_archs }}
CIBW_TEST_REQUIRES: "bfio requests numpy ome_zarr zarr"
CIBW_TEST_REQUIRES: "bfio requests numpy zarr"
CIBW_TEST_COMMAND: python -W default -m unittest discover -s {project}/tests -v

- name: Upload Artifact
Expand Down
41 changes: 41 additions & 0 deletions tests/_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Download helpers for test data, with retries and size/zip validation."""
import pathlib
import shutil
import time
import urllib.request
import zipfile

# Pinned to a commit of sameeul/polus-test-data (merge of PR #3).
DATA_REPO = (
"https://raw.githubusercontent.com/sameeul/polus-test-data/"
"9ec79af23d155a2bdb74823fa6fc6f204bbe2ca4/bfio"
)
SMALL_ZARR_URL = f"{DATA_REPO}/small_5d.zarr.zip"


def fetch(url, dest, tries=4, timeout=60):
"""Download url to dest, retrying with backoff; raises on final failure."""
dest = pathlib.Path(dest)
for i in range(tries):
try:
with urllib.request.urlopen(url, timeout=timeout) as r:
data = r.read()
dest.write_bytes(data)
return dest
except Exception:
if i == tries - 1:
raise
time.sleep(2**i)


def fetch_zarr(url, test_dir):
"""Download a zipped zarr and unpack it into test_dir."""
test_dir = pathlib.Path(test_dir)
z = fetch(url, test_dir / "tmp_zarr.zip")
with zipfile.ZipFile(z) as zf:
zf.extractall(test_dir)
z.unlink()


def clean(test_dir):
shutil.rmtree(test_dir, ignore_errors=True)
50 changes: 21 additions & 29 deletions tests/test_read.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
from bfiocpp import TSReader, Seq, FileType
import unittest
import requests, pathlib, shutil, logging, sys
# SEE : Initialization of bio-formats java backend https://bio-formats.readthedocs.io/en/stable/developers/java-library.html
# The order of initialization between ome_zarr.utils and bfio matters
from ome_zarr.utils import download as zarr_download
import pathlib, shutil, logging, sys
import bfio
import numpy as np
import random

TEST_IMAGES = {
"5025551.zarr": "https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0054A/5025551.zarr",
"p01_x01_y01_wx0_wy0_c1.ome.tif": "https://raw.githubusercontent.com/sameeul/polus-test-data/main/bfio/p01_x01_y01_wx0_wy0_c1.ome.tif",
"Plate1-Blue-A-12-Scene-3-P3-F2-03.czi": "https://downloads.openmicroscopy.org/images/Zeiss-CZI/idr0011/Plate1-Blue-A_TS-Stinger/Plate1-Blue-A-12-Scene-3-P3-F2-03.czi",
}

try:
from ._data import SMALL_ZARR_URL, fetch, fetch_zarr
except ImportError: # run via `unittest discover -s tests`
from _data import SMALL_ZARR_URL, fetch, fetch_zarr

TEST_DIR = pathlib.Path(__file__).with_name("data")

logging.basicConfig(
Expand All @@ -30,21 +31,12 @@ def setUpModule():
"""Download images for testing"""
TEST_DIR.mkdir(exist_ok=True)

fetch_zarr(SMALL_ZARR_URL, TEST_DIR)

for file, url in TEST_IMAGES.items():
logger.info(f"setup - Downloading: {file}")

if not file.endswith(".zarr"):
if TEST_DIR.joinpath(file).exists():
continue

r = requests.get(url)

with open(TEST_DIR.joinpath(file), "wb") as fw:
fw.write(r.content)
else:
if TEST_DIR.joinpath(file).exists():
shutil.rmtree(TEST_DIR.joinpath(file))
zarr_download(url, str(TEST_DIR))
if not TEST_DIR.joinpath(file).exists():
fetch(url, TEST_DIR.joinpath(file))

"""Load the czi image, and save as a npy file for further testing."""
with bfio.BioReader(
Expand Down Expand Up @@ -210,14 +202,14 @@ class TestOmeZarrRead(unittest.TestCase):
def test_read_zarr_2d_slice(self):
"""test_read_zarr_2d_slice - Read tiff using TSReader"""
br = TSReader(
str(TEST_DIR.joinpath("5025551.zarr/0")),
str(TEST_DIR.joinpath("small_5d.zarr/0")),
FileType.OmeZarrV2,
"",
)
assert br._X == 2702
assert br._Y == 2700
assert br._X == 302
assert br._Y == 300
assert br._Z == 1
assert br._C == 27
assert br._C == 4
assert br._T == 1

rows = Seq(0, br._Y - 1, 1)
Expand All @@ -228,24 +220,24 @@ def test_read_zarr_2d_slice(self):
tmp = br.data(rows, cols, layers, channels, tsteps)

assert tmp.dtype == np.uint8
assert tmp.sum() == 183750394
assert tmp.shape == (1, 1, 1, 2700, 2702)
assert tmp.sum() == 11522078
assert tmp.shape == (1, 1, 1, 300, 302)

def test_read_zarr_4d_slice(self):
"""test_read_zarr_4d_slice - Read tiff using TSReader"""
br = TSReader(
str(TEST_DIR.joinpath("5025551.zarr/0")),
str(TEST_DIR.joinpath("small_5d.zarr/0")),
FileType.OmeZarrV2,
"",
)

rows = Seq(0, 1023, 1)
cols = Seq(0, 1023, 1)
rows = Seq(0, 255, 1)
cols = Seq(0, 255, 1)
layers = Seq(0, 0, 1)
channels = Seq(0, 3, 1)
tsteps = Seq(0, 0, 1)
tmp = br.data(rows, cols, layers, channels, tsteps)

assert tmp.dtype == np.uint8
assert tmp.sum() == 81778531
assert tmp.shape == (1, 4, 1, 1024, 1024)
assert tmp.sum() == 33383535
assert tmp.shape == (1, 4, 1, 256, 256)
Loading
Loading