Skip to content

Commit b33824a

Browse files
Pip install (#53)
* Clean up * Add workflow for publishing on PyPI * Add workflow for publishing on PyPI * Dask test update
1 parent 2b8b133 commit b33824a

9 files changed

Lines changed: 99 additions & 75 deletions

File tree

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ name: pybdv-build-env
22
channels:
33
- conda-forge
44
dependencies:
5+
- pip
56
- imageio
67
- h5py
78
- scikit-image
89
- tqdm
910
- z5py
10-
# zarr doesn't work yet, because it doesn't allow writing 'dataType' as group attribute
11-
# - zarr

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
activate-environment: pybdv-build-env
2525
auto-update-conda: true
2626
channels: conda-forge
27-
environment-file: .github/workflows/environment.yaml
27+
environment-file: .github/environment.yaml
2828
python-version: ${{ matrix.python-version }}
2929
auto-activate-base: false
3030
env:
@@ -33,7 +33,7 @@ jobs:
3333
- name: Install pybdv
3434
if: matrix.os == 'ubuntu-latest'
3535
shell: bash -l {0}
36-
run: pip install -e .[dask]
36+
run: python -m pip install -e .[dask]
3737

3838
- name: Run tests
3939
shell: bash -l {0}

.github/workflows/publish.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
name: publish
3+
4+
on:
5+
release:
6+
types: [published]
7+
workflow_dispatch:
8+
9+
jobs:
10+
build:
11+
name: Build distribution
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
18+
- name: Setup python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: "3.12"
22+
23+
- name: Install build
24+
run: python -m pip install build
25+
26+
- name: Build sdist and wheel
27+
run: python -m build
28+
29+
- name: Upload distribution
30+
uses: actions/upload-artifact@v4
31+
with:
32+
name: python-package-distributions
33+
path: dist/
34+
35+
publish-pypi:
36+
name: Publish to PyPI
37+
if: github.event_name == 'release'
38+
needs: build
39+
runs-on: ubuntu-latest
40+
41+
environment:
42+
name: pypi
43+
url: https://pypi.org/p/pybdv
44+
45+
permissions:
46+
id-token: write
47+
48+
steps:
49+
- name: Download distribution
50+
uses: actions/download-artifact@v4
51+
with:
52+
name: python-package-distributions
53+
path: dist/
54+
55+
- name: Publish to PyPI
56+
uses: pypa/gh-action-pypi-publish@release/v1
57+
58+
publish-testpypi:
59+
name: Publish to TestPyPI
60+
if: github.event_name == 'workflow_dispatch'
61+
needs: build
62+
runs-on: ubuntu-latest
63+
64+
environment:
65+
name: testpypi
66+
url: https://test.pypi.org/p/pybdv
67+
68+
permissions:
69+
id-token: write
70+
71+
steps:
72+
- name: Download distribution
73+
uses: actions/download-artifact@v4
74+
with:
75+
name: python-package-distributions
76+
path: dist/
77+
78+
- name: Publish to TestPyPI
79+
uses: pypa/gh-action-pypi-publish@release/v1
80+
with:
81+
repository-url: https://test.pypi.org/legacy/

conda-recipe/meta.yaml

Lines changed: 0 additions & 45 deletions
This file was deleted.

pybdv/bdv_datasets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def _scale_and_add_to_dataset(
9797
scale_factors = scales[1: 2].tolist()
9898

9999
for scale in scales[2:]:
100-
scale_factors.append((scale / np.product(scale_factors, axis=0)).astype(int).tolist())
100+
scale_factors.append((scale / np.prod(scale_factors, axis=0)).astype(int).tolist())
101101

102102
# Scale the data
103103
downscaled_vols = [target_vol]

pybdv/converter.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
try:
1818
import dask.array as da
19-
import zarr
20-
from numcodecs import GZip
2119
has_dask = True
2220
except ImportError:
2321
has_dask = False
@@ -589,11 +587,7 @@ def make_scales_dask(data, data_path, is_n5,
589587
elif downscale_factors is not None:
590588
downsample_chunks = tuple(((64, 64, 64) for _ in range(len(downscale_factors))))
591589

592-
if is_n5:
593-
store = zarr.N5FSStore(data_path, overwrite=overwrite)
594-
else:
595-
store = zarr.DirectoryStore(data_path)
596-
with zarr.open(store, mode='a') as group:
590+
with open_file(data_path, mode='a') as group:
597591
# run all downsample steps for better data locality with dask
598592
base_key = get_key(is_h5=False, timepoint=timepoint, setup_id=setup_id, scale=0)
599593
have_data = base_key in group
@@ -621,8 +615,11 @@ def make_scales_dask(data, data_path, is_n5,
621615
save_chunks_all = [data.chunksize]
622616
arrays = []
623617
for (k, v), save_chunks in zip(pyramid.items(), save_chunks_all):
624-
arrays.append(group.zeros(
625-
name=k, shape=v.shape, dtype=v.dtype, chunks=save_chunks, compressor=GZip(), overwrite=overwrite
618+
# deleting is required to over-write, because the shape may change
619+
if k in group and overwrite:
620+
del group[k]
621+
arrays.append(group.create_dataset(
622+
k, shape=v.shape, dtype=v.dtype, chunks=tuple(save_chunks), compression='gzip'
626623
))
627624
array = da.store(pyramid.values(), arrays, lock=None, compute=compute, return_stored=return_stored)
628625

pybdv/util.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,21 @@
1919
if open_file is None:
2020
import h5py
2121

22+
# n5 and zarr files are always opened with z5py;
23+
# zarr >= 3 has dropped support for the n5 format
2224
try:
2325
import z5py
2426
n5_file = z5py.File
2527
except ImportError:
2628
n5_file = None
2729

28-
if n5_file is None:
29-
try:
30-
import zarr
31-
n5_file = zarr.open
32-
except ImportError:
33-
n5_file = None
34-
3530
def open_file(path, mode='r'):
3631
ext = os.path.splitext(path)[1].lower()
3732
if ext in HDF5_EXTENSIONS:
3833
return h5py.File(path, mode=mode)
39-
elif ext in N5_EXTENSIONS:
40-
if n5_file is None:
41-
raise ValueError("Need zarr or z5py to open n5 files")
42-
return n5_file(path, mode=mode)
43-
elif ext in ZARR_EXTENSIONS:
34+
elif ext in N5_EXTENSIONS + ZARR_EXTENSIONS:
4435
if n5_file is None:
45-
raise ValueError("Need zarr or z5py to open zarr files")
36+
raise ValueError("Need z5py to open n5 or zarr files")
4637
return n5_file(path, mode=mode)
4738
else:
4839
raise ValueError(f"Invalid extension: {ext}")

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
"numpy",
99
"h5py",
1010
"scikit-image",
11-
"tqdm"
11+
"tqdm",
12+
"z5py"
1213
]
1314

14-
extras = {"elf": ["elf"], "dask": ["dask", "zarr"]}
15+
extras = {"elf": ["elf"], "dask": ["dask"]}
1516
extras["all"] = list(itertools.chain.from_iterable(extras.values()))
1617

1718
setup(

test/test_make_bdv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def test_dask_lazy(self):
344344
if self.is_dask:
345345
data = np.random.rand(10,10,10).astype(np.float32)
346346
array = self._make_bdv(data, self.out_path, compute=False, return_stored=True )
347-
self.assertTrue('store-map' in array.name)
347+
self.assertIsInstance(array, dask.array.Array)
348348
key = get_key(self.is_h5, timepoint=0, setup_id=0, scale=0)
349349
self.assertTrue(os.path.exists(self.out_path))
350350
with open_file(self.out_path, 'r') as f:

0 commit comments

Comments
 (0)