1010from abc import ABCMeta
1111from numcodecs import Zstd
1212import logging
13+ import copy
1314
1415class 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 ]
0 commit comments