Skip to content

Commit

Permalink
back to reading whole zstack tif at once
Browse files Browse the repository at this point in the history
  • Loading branch information
akhanf committed Oct 2, 2024
1 parent feb5988 commit 05498fe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion workflow/rules/import.smk
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ rule tif_to_zarr_gcs:
),
group:
"preproc"
threads: 16 #config["cores_per_rule"]
threads: config["cores_per_rule"]
container:
config["containers"]["spimprep"]
script:
Expand Down
13 changes: 4 additions & 9 deletions workflow/scripts/tif_to_zarr_gcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ def read_tiff_slice(fs,gcs_uri, key=0):
with fs.open(gcs_uri, 'rb') as file:
return tifffile.imread(file, key=key)

def read_page_as_numpy(tif_file_uri, page, fs):
"""Gets a single page (i.e., 2D image) from a tif file z-stack stored in a cloud URI."""
def read_stack_as_numpy(tif_file_uri, fs):
"""Gets the full stack (i.e., 3D image) from a tif file z-stack stored in a cloud URI."""

# Open the file from the cloud storage using fsspec
with fs.open(tif_file_uri, 'rb') as f:
# Read the file content into a buffer
file_buffer = f.read()

# Use pyvips to read from the buffer
return pyvips.Image.new_from_buffer(file_buffer, "", page=page).numpy()
return pyvips.Image.new_from_buffer(file_buffer, "").numpy()



Expand Down Expand Up @@ -122,12 +122,7 @@ def build_zstack_from_single(gcs_uri,zstack_metadata,fs):

tif_file = in_tif_pattern.format(tilex=tilex,tiley=tiley,prefix=metadata['prefixes'][0],channel=channel)

pages=[]
#read each page
for i_z in range(size_z):
pages.append(da.from_delayed(delayed(read_page_as_numpy)('gcs://'+tif_file,i_z,fs),shape=(size_y,size_x),dtype='uint16'))

zstacks.append(da.stack(pages))
zstacks.append(da.from_delayed(delayed(read_page_as_numpy)('gcs://'+tif_file,fs),shape=(size_z,size_y,size_x),dtype='uint16'))

else:
zstacks.append(build_zstack(fs.glob('gcs://'+in_tif_glob.format(tilex=tilex,tiley=tiley,prefix=metadata['prefixes'][0],channel=channel,zslice='*')),fs=fs))
Expand Down

0 comments on commit 05498fe

Please sign in to comment.