Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add reading to memory mapped temp array #3

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions src/sparcscore/pipeline/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

from alphabase.io import tempmmap


class Segmentation(ProcessingStep):
"""Segmentation helper class used for creating segmentation workflows.

Expand Down Expand Up @@ -280,7 +281,7 @@ def save_segmentation_zarr(self, labels=None):
loc = parse_url(path, mode="w").store
group = zarr.group(store=loc)

segmentation_names = ["nucleus", "cyotosol"]
segmentation_names = ["nucleus", "cytosol"]

# check if segmentation names already exist if so delete
for seg_names in segmentation_names:
Expand All @@ -301,7 +302,15 @@ def save_segmentation_zarr(self, labels=None):
path_labels = os.path.join(self.directory, self.DEFAULT_OUTPUT_FILE)

with h5py.File(path_labels, "r") as hf:
labels = hf[self.DEFAULT_MASK_NAME][:]
# initialize tempmmap array to save label results into
labels = tempmmap.array(
shape=hf[self.DEFAULT_MASK_NAME].shape,
dtype=hf[self.DEFAULT_MASK_NAME].dtype,
tmp_dir_abs_path=self._tmp_dir_path,
)

labels[0] = hf[self.DEFAULT_MASK_NAME][0]
labels[1] = hf[self.DEFAULT_MASK_NAME][1]

segmentations = [np.expand_dims(seg, axis=0) for seg in labels]

Expand All @@ -316,6 +325,7 @@ def save_segmentation_zarr(self, labels=None):
)

self.log("finished saving segmentation results to ome.zarr")
del labels
else:
self.log(
"Not saving shard segmentation into ome.zarr. Will only save completely assembled image."
Expand Down Expand Up @@ -538,9 +548,8 @@ def save_segmentation(self, channels, labels, classes):

self.check_filter_status()
self.save_classes(classes)

self.log("=== finished segmentation ===")
self.save_segmentation_zarr(labels=labels)
self.log("=== finished segmentation ===")

def initialize_shard_list(self, sharding_plan):
_shard_list = []
Expand Down Expand Up @@ -832,7 +841,15 @@ def resolve_sharding(self, sharding_plan):
path_labels = os.path.join(self.directory, self.DEFAULT_OUTPUT_FILE)

with h5py.File(path_labels, "r") as hf:
labels = hf[self.DEFAULT_MASK_NAME][:]
# initialize tempmmap array to save label results into
labels = tempmmap.array(
shape=hf[self.DEFAULT_MASK_NAME].shape,
dtype=hf[self.DEFAULT_MASK_NAME].dtype,
tmp_dir_abs_path=self._tmp_dir_path,
)

labels[0] = hf[self.DEFAULT_MASK_NAME][0]
labels[1] = hf[self.DEFAULT_MASK_NAME][1]

self.save_segmentation_zarr(labels=labels)
self.log(
Expand Down
Loading