Skip to content

Commit

Permalink
update main workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
akhanf committed Jan 26, 2025
1 parent 6c60fc2 commit de52398
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 39 deletions.
2 changes: 1 addition & 1 deletion dask-stitch/scripts/create_test_dataset_singletile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import math
from zarrnii import ZarrNii

def create_test_dataset_single(tile_index, template="MNI152NLin2009cAsym", res=2, grid_shape=(3, 4), overlap=16, random_seed=42, final_chunks=(1,32, 32, 1)):
def create_test_dataset_single(tile_index, template="MNI152NLin2009cAsym", res=2, grid_shape=(3, 4), overlap=16, random_seed=42, final_chunks=(1,32, 32, 32)):
"""
Create a low-resolution test dataset for tile-based stitching.
Expand Down
50 changes: 12 additions & 38 deletions dask-stitch/scripts/fuse_volume.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from lib.utils import *

from zarrnii import ZarrNii

# Paths to input tiles
ome_zarr_paths = snakemake.input.ome_zarr
Expand All @@ -9,46 +9,20 @@


# Parameters for the fused array
fused_shape = (128,128,128) # Full shape of the fused array
chunk_shape = (64,64,64) # Chunk size of the fused array
global_bbox_min = np.array([0, 0, 0]) # Minimum physical coordinate of the fused array
target_voxel_spacing = np.array([1.0, 1.0, 1.0]) # Voxel spacing of the fused array

# Create an empty Dask array for the fused output
fused_dask_array = da.zeros(fused_shape, chunks=chunk_shape, dtype=np.float32)



# Apply map_blocks to process the fused array
processed_dask_array = fused_dask_array.map_blocks(
process_block,
dtype=np.float32,
rtree_idx=rtree_idx,
znimgs=znimgs,
global_bbox_min=global_bbox_min,
target_voxel_spacing=target_voxel_spacing,
)

output_shape=(400,400,400)
output_chunks=(100,100,100)
fused_dask_array = da.zeros(output_shape, chunks=output_chunks, dtype=np.float32)
znimg_out = ZarrNii.from_darr(fused_dask_array,
axes_order=znimgs[0].axes_order,
orientation=znimgs[0].get_orientation(),
spacing=(1,1,1),
origin=(-100,-100,-100))

znimg_out = ZarrNii.from_darr(processed_dask_array.reshape((1,processed_dask_array.shape[0],processed_dask_array.shape[1],processed_dask_array.shape[2])))
znimg_out.to_ome_zarr(snakemake.output.ome_zarr)
znimg_out.to_nifti(snakemake.output.nifti)
znimg_fused = fuse_output_blocks(znimg_out,rtree_idx=rtree_idx,tile_znimgs=znimgs)

"""
znimg_fused.to_ome_zarr(snakemake.output.ome_zarr)

print('doing test query')
# Define the bounding box of an output chunk (example)
output_chunk_bbox =( -1, -1, -1, 0,0,0) # Replace with actual bounding box of a fused chunk
output_chunk_bbox =( -36, -33, -49, -35,-32,-47) # Replace with actual bounding box of a fused chunk
print(output_chunk_bbox)
ZarrNii.from_ome_zarr(snakemake.output.ome_zarr).to_nifti(snakemake.output.nifti)

# Query intersecting chunks
intersecting_chunks = query_intersections(rtree_idx, output_chunk_bbox)

print(f'found {len(intersecting_chunks)} chunks')
# Extract the attached data (tile_idx, chunk_id)
for entry in intersecting_chunks:
tile_idx, chunk_id = entry.object
print(f"Intersecting chunk: tile_idx={tile_idx}, chunk_id={chunk_id}")

"""

0 comments on commit de52398

Please sign in to comment.