Skip to content

Commit

Permalink
[FEATURE] make rechunking optional when reading from an existing spat…
Browse files Browse the repository at this point in the history
…ialdata object

it should be possible to turn of rechunking when reading from an existing spatialdata object under the asumption that the chunksize was set logically. This prevents having to recalculate already existing chunks which has a lot of overhead during writing.
  • Loading branch information
sophiamaedler committed Feb 10, 2025
1 parent 088bf42 commit a74327d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/scportrait/pipeline/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,7 @@ def load_input_from_sdata(
overwrite: bool | None = None,
keep_all: bool = True,
remove_duplicates: bool = True,
rechunk: bool = False,
) -> None:
"""
Load input image from a spatialdata object.
Expand Down Expand Up @@ -890,8 +891,9 @@ def load_input_from_sdata(
image_c, image_x, image_y = image.scale0.image.shape

# ensure chunking is correct
for scale in image:
self._check_chunk_size(image[scale].image, chunk_size=self.DEFAULT_CHUNK_SIZE_3D)
if rechunk:
for scale in image:
self._check_chunk_size(image[scale].image, chunk_size=self.DEFAULT_CHUNK_SIZE_3D)

# get channel names
channel_names = image.scale0.image.c.values
Expand All @@ -900,7 +902,8 @@ def load_input_from_sdata(
image_c, image_x, image_y = image.shape

# ensure chunking is correct
self._check_chunk_size(image, chunk_size=self.DEFAULT_CHUNK_SIZE_3D)
if rechunk:
self._check_chunk_size(image, chunk_size=self.DEFAULT_CHUNK_SIZE_3D)

channel_names = image.c.values

Expand Down Expand Up @@ -931,7 +934,9 @@ def load_input_from_sdata(
mask_y == image_y
), "Nucleus segmentation mask does not match input image size."

self._check_chunk_size(mask, chunk_size=self.DEFAULT_CHUNK_SIZE_2D) # ensure chunking is correct
if rechunk:
self._check_chunk_size(mask, chunk_size=self.DEFAULT_CHUNK_SIZE_2D) # ensure chunking is correct

self.filehandler._write_segmentation_object_sdata(mask, self.nuc_seg_name)

# check if a cytosol segmentation exists and if so add it to the sdata object
Expand All @@ -951,7 +956,9 @@ def load_input_from_sdata(
mask_y == image_y
), "Nucleus segmentation mask does not match input image size."

self._check_chunk_size(mask, chunk_size=self.DEFAULT_CHUNK_SIZE_2D) # ensure chunking is correct
if rechunk:
self._check_chunk_size(mask, chunk_size=self.DEFAULT_CHUNK_SIZE_2D) # ensure chunking is correct

self.filehandler._write_segmentation_object_sdata(mask, self.cyto_seg_name)

self.get_project_status()
Expand Down

0 comments on commit a74327d

Please sign in to comment.