Skip to content

Commit

Permalink
adding configurable CZYX chunk size (#154)
Browse files Browse the repository at this point in the history
adding chunk_czyx to config to modify the chunksize.
  • Loading branch information
edyoshikun authored Jul 30, 2024
1 parent 7c9cf51 commit cad662b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
9 changes: 9 additions & 0 deletions mantis/analysis/AnalysisSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class ConcatenateSettings(MyBaseModel):
X_slice: Union[list[int], Literal["all"]] = "all"
Y_slice: Union[list[int], Literal["all"]] = "all"
Z_slice: Union[list[int], Literal["all"]] = "all"
chunks_czyx: Union[Literal[None], list[int]] = None

@validator("concat_data_paths")
def check_concat_data_paths(cls, v):
Expand All @@ -106,6 +107,14 @@ def check_slices(cls, v):
raise ValueError("Slices must be 'all' or lists of two non-negative integers.")
return v

@validator("chunks_czyx")
def check_chunk_size(cls, v):
if v is not None and (
not isinstance(v, list) or len(v) != 4 or not all(isinstance(i, int) for i in v)
):
raise ValueError("chunks_czyx must be a list of 4 integers (C, Z, Y, X)")
return v


class StabilizationSettings(MyBaseModel):
stabilization_estimation_channel: str
Expand Down
1 change: 1 addition & 0 deletions mantis/analysis/settings/example_concatenate_settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ channel_names: [all,all] # replace "all" with e.g. "[['Retardance', 'Orientatio
X_slice: all # replace "all" with e.g. "[0, 100]" for cropping
Y_slice: all # replace "all" with e.g. "[0, 100]" for cropping
Z_slice: all # replace "all" with e.g. "[0, 100]" for cropping
chunks_czyx: null # replace "null" with e.g. "[1, 100, 100, 100]" for desired chunking [C,Z,Y,X]
8 changes: 7 additions & 1 deletion mantis/cli/concatenate.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,16 @@ def concatenate(config_filepath: str, output_dirpath: str, num_processes: int):
if cropped_shape_zyx[0] > Z or cropped_shape_zyx[1] > Y or cropped_shape_zyx[2] > X:
raise ValueError("The cropped shape is larger than the original shape.")

# TODO: make assertion for chunk size?
if settings.chunks_czyx is not None:
chunk_size = [1] + list(settings.chunks_czyx)
else:
chunk_size = settings.chunks_czyx

# Logic for creation of zarr and metadata
output_metadata = {
"shape": (len(time_indices), len(all_channel_names)) + tuple(cropped_shape_zyx),
"chunks": None,
"chunks": chunk_size,
"scale": (1,) * 2 + tuple(output_voxel_size),
"channel_names": all_channel_names,
"dtype": np.float32,
Expand Down

0 comments on commit cad662b

Please sign in to comment.