Skip to content

Commit 2813926

Browse files
authored
Merge pull request #6 from yuriyzubov/refactor
add bokeh to the list of dependencies fix click parameter typos format parsing order resolve dask serialization issue for the lambda function that contains reference to self instance
2 parents f3e04c6 + 608a0a0 commit 2813926

File tree

4 files changed

+28
-23
lines changed

4 files changed

+28
-23
lines changed

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ dependencies = [
1717
"mrcfile>=1.5.3,<2.0.0",
1818
"natsort>=8.4.0,<9.0.0",
1919
"numcodecs>=0.13.0,<0.16",
20-
"pydantic-zarr>=0.4.0,<1.0.0",
20+
"pydantic-zarr==0.6.0",
2121
"pint>=0.20.0,<1.0.0",
2222
"tifffile>=2025.1.10,<2026.0.0",
23-
"zarr==2.18.3"
23+
"zarr==2.18.3",
24+
"bokeh>=3.1.0"
2425
]
2526

2627
[project.scripts]

src/zarrify/formats/mrc.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from abc import ABCMeta
1111
from numcodecs import Zstd
1212
import logging
13+
import copy
1314

1415
class Mrc3D(Volume):
1516

@@ -30,20 +31,9 @@ def __init__(
3031

3132
self.memmap = mrcfile.mmap(self.src_path, mode="r")
3233
self.ndim = self.memmap.data.ndim
33-
self.shape = self.memmap.shape
34+
self.shape = self.memmap.data.shape
3435
self.dtype = self.memmap.data.dtype
3536

36-
def save_chunk(self, z_arr: zarr.Array, chunk_slice: Tuple[slice, ...]):
37-
"""Copies data from a particular part of the input mrc array into a specific chunk of the output zarr array.
38-
39-
Args:
40-
z_arr (zarr.core.Array): output zarr array object
41-
chunk_slice (Tuple[slice, ...]): slice of the mrc array to copy.
42-
"""
43-
mrc_file = mrcfile.mmap(self.src_path, mode="r")
44-
45-
if not (mrc_file.data[chunk_slice] == 0).all():
46-
z_arr[chunk_slice] = mrc_file.data[chunk_slice]
4737

4838
def write_to_zarr(
4939
self,
@@ -62,8 +52,9 @@ def write_to_zarr(
6252
logging.basicConfig(level=logging.INFO,
6353
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
6454

65-
55+
src_path = copy.copy(self.src_path)
6656
z_arr = self.get_output_array(dest, zarr_chunks, comp)
57+
6758
out_slices = slices_from_chunks(
6859
normalize_chunks(z_arr.chunks, shape=z_arr.shape)
6960
)
@@ -73,10 +64,22 @@ def write_to_zarr(
7364

7465
logging.info(f"{idx + 1} / {len(out_slices_partitioned)}")
7566
start = time.time()
76-
fut = client.map(lambda v: self.save_chunk(z_arr, v), part)
67+
fut = client.map(lambda v: save_chunk(src_path, z_arr, v), part)
7768
logging.info(
7869
f"Submitted {len(part)} tasks to the scheduler in {time.time()- start}s"
7970
)
8071
# wait for all the futures to complete
8172
result = wait(fut)
8273
logging.info(f"Completed {len(part)} tasks in {time.time() - start}s")
74+
75+
def save_chunk(src_path, z_arr: zarr.Array, chunk_slice: Tuple[slice, ...]):
76+
"""Copies data from a particular part of the input mrc array into a specific chunk of the output zarr array.
77+
78+
Args:
79+
z_arr (zarr.core.Array): output zarr array object
80+
chunk_slice (Tuple[slice, ...]): slice of the mrc array to copy.
81+
"""
82+
mrc_file = mrcfile.mmap(src_path, mode="r")
83+
84+
if not (mrc_file.data[chunk_slice] == 0).all():
85+
z_arr[chunk_slice] = mrc_file.data[chunk_slice]

src/zarrify/to_zarr.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ def init_dataset(src :str,
3838
src_path = Path(src)
3939
params = (src, axes, scale, translation, units)
4040

41-
if src_path.is_dir():
42-
return TiffStack(*params)
4341

4442
ext = src_path.suffix.lower()
45-
46-
if '.n5' in src_path.name:
43+
44+
if ext=='.n5':
4745
return N5Group(*params)
46+
elif src_path.is_dir():
47+
return TiffStack(*params)
4848
elif ext == ".mrc":
4949
return Mrc3D(*params)
5050
elif ext in (".tif", ".tiff"):
@@ -92,7 +92,7 @@ def to_zarr(src : str,
9292
type=click.Path(exists=True),
9393
help="Input file/directory location",
9494
)
95-
@click.option("--dest", "-s", type=click.STRING, help="Output .zarr file path.")
95+
@click.option("--dest", "-d", type=click.STRING, help="Output .zarr file path.")
9696
@click.option(
9797
"--num_workers", "-w", default=100, type=click.INT, help="Number of dask workers"
9898
)
@@ -129,11 +129,11 @@ def to_zarr(src : str,
129129
)
130130
@click.option(
131131
"--scale",
132-
"-s",
132+
"-sc",
133133
nargs=3,
134134
default=(1.0, 1.0, 1.0),
135135
type=float,
136-
help="Metadata scale value. Order matters. \n Example: -s 1.0 2.0 3.0",
136+
help="Metadata scale value. Order matters. \n Example: --scale 1.0 2.0 3.0",
137137
)
138138
@click.option(
139139
"--units",

src/zarrify/utils/dask_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def initialize_dask_client(cluster_type: str | None = None) -> Client:
3333
raise ValueError(f"Unsupported cluster type: {cluster_type}")
3434

3535
client = Client(cluster)
36+
print(str(client.dashboard_link))
3637
with open(
3738
os.path.join(os.getcwd(), "dask_dashboard_link" + ".txt"), "w"
3839
) as text_file:

0 commit comments

Comments
 (0)