Skip to content

Commit

Permalink
add channels parameter for load-h5 operator; fix the progress bar of …
Browse files Browse the repository at this point in the history
…load-pngs operator
  • Loading branch information
xiuliren committed Mar 24, 2024
1 parent 84ae0ba commit b2a13c4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
18 changes: 13 additions & 5 deletions chunkflow/chunk/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ def from_h5(cls, file_name: str,
voxel_offset: tuple=None,
dataset_path: str = None,
voxel_size: tuple = None,
channels: str = None,
cutout_start: tuple = None,
cutout_stop: tuple = None,
cutout_size: tuple = None,
Expand Down Expand Up @@ -336,11 +337,18 @@ def from_h5(cls, file_name: str,

assert len(cutout_start) == 3
assert len(cutout_stop) == 3
dset = dset[...,
cutout_start[0]-voxel_offset[0]:cutout_stop[0]-voxel_offset[0],
cutout_start[1]-voxel_offset[1]:cutout_stop[1]-voxel_offset[1],
cutout_start[2]-voxel_offset[2]:cutout_stop[2]-voxel_offset[2],
]
if channels is None:
dset = dset[...,
cutout_start[0]-voxel_offset[0]:cutout_stop[0]-voxel_offset[0],
cutout_start[1]-voxel_offset[1]:cutout_stop[1]-voxel_offset[1],
cutout_start[2]-voxel_offset[2]:cutout_stop[2]-voxel_offset[2],
]
else:
dset = dset[ eval(channels),
cutout_start[0]-voxel_offset[0]:cutout_stop[0]-voxel_offset[0],
cutout_start[1]-voxel_offset[1]:cutout_stop[1]-voxel_offset[1],
cutout_start[2]-voxel_offset[2]:cutout_stop[2]-voxel_offset[2],
]


print(f"""read from HDF5 file: {file_name} and start with {cutout_start}, \
Expand Down
7 changes: 4 additions & 3 deletions chunkflow/flow/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,8 @@ def save_tif(tasks, input_chunk_name: str, file_name: str, dtype: str, compressi
@click.option('--voxel-size', '-x', type=click.INT, nargs=3,
default=None, callback=default_none,
help='physical size of voxels. The unit is assumed to be nm.')
@click.option('--channels', '-c', type=str, default=None,
help='selected channels.')
@click.option('--cutout-start', '-t', type=click.INT, nargs=3, callback=default_none,
help='cutout voxel offset in the array')
@click.option('--cutout-stop', '-p', type=click.INT, nargs=3, callback=default_none,
Expand All @@ -1006,7 +1008,7 @@ def save_tif(tasks, input_chunk_name: str, file_name: str, dtype: str, compressi
@operator
def load_h5(tasks, name: str, file_name: str, dataset_path: str,
dtype: str, layer_type: str, voxel_offset: tuple,
voxel_size: tuple, cutout_start: tuple,
voxel_size: tuple, channels: str, cutout_start: tuple,
cutout_stop: tuple, cutout_size: tuple, set_bbox: bool,
remove_empty: bool, output_chunk_name: str):
"""Read HDF5 files."""
Expand Down Expand Up @@ -1035,6 +1037,7 @@ def load_h5(tasks, name: str, file_name: str, dataset_path: str,
dataset_path=dataset_path,
voxel_offset=voxel_offset,
voxel_size=voxel_size,
channels = channels,
cutout_start=cutout_start_tmp,
cutout_size=cutout_size_tmp,
cutout_stop=cutout_stop_tmp,
Expand All @@ -1048,8 +1051,6 @@ def load_h5(tasks, name: str, file_name: str, dataset_path: str,
print(f'remove {file_name}')
os.remove(file_name)

# if len(chunk.array) == 0:
# breakpoint()
if chunk is not None and dtype is not None:
chunk = chunk.astype(dtype)

Expand Down
4 changes: 2 additions & 2 deletions chunkflow/flow/load_pngs.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def load_png_images(
shape = Cartesian(len(file_names), img.shape[0], img.shape[1])
bbox = BoundingBox.from_delta(voxel_offset, shape)
else:
for z in tqdm( range(bbox.start[0], bbox.stop[0]) ):
for z in range(bbox.start[0], bbox.stop[0]):
file_name = f'{path_prefix}{z:0>{digit_num}d}.png'
file_name = os.path.expanduser(file_name)
file_names.append(file_name)
Expand All @@ -55,7 +55,7 @@ def load_png_images(
voxel_size=voxel_size
)

for z_offset, file_name in enumerate(file_names):
for z_offset, file_name in tqdm(enumerate(file_names)):
if os.path.exists(file_name):
img = load_image(file_name)
img = img.astype(dtype=dtype)
Expand Down

0 comments on commit b2a13c4

Please sign in to comment.