diff --git a/chunkflow/chunk/base.py b/chunkflow/chunk/base.py index ea42480..364e0d1 100755 --- a/chunkflow/chunk/base.py +++ b/chunkflow/chunk/base.py @@ -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, @@ -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}, \ diff --git a/chunkflow/flow/flow.py b/chunkflow/flow/flow.py index 154d5ee..c767f6d 100755 --- a/chunkflow/flow/flow.py +++ b/chunkflow/flow/flow.py @@ -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, @@ -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.""" @@ -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, @@ -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) diff --git a/chunkflow/flow/load_pngs.py b/chunkflow/flow/load_pngs.py index cc3e573..4c01a11 100644 --- a/chunkflow/flow/load_pngs.py +++ b/chunkflow/flow/load_pngs.py @@ -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) @@ -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)