Skip to content

Commit

Permalink
Fix batching for stackid assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdstein committed May 24, 2024
1 parent 425102f commit d24ba48
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
3 changes: 3 additions & 0 deletions mirar/data/base_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def __getitem__(self, item):
def __setitem__(self, key, value):
raise NotImplementedError

def __str__(self):
return f"<An {self.__class__.__name__} object, built from {self.get_name()}>"

def get_name(self) -> str:
"""Function to retrieve the :variable:`mirar.paths.BASE_NAME_KEY`
of the parent image
Expand Down
3 changes: 0 additions & 3 deletions mirar/data/image_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ def get_cache_path(self) -> Path:
name = f"{hashlib.sha1(base.encode()).hexdigest()}.npy"
return cache.get_cache_dir().joinpath(name)

def __str__(self):
return f"<An {self.__class__.__name__} object, built from {self.get_name()}>"

def set_data(self, data: np.ndarray):
"""
Set the data with cache
Expand Down
6 changes: 5 additions & 1 deletion mirar/pipelines/winter/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,11 @@
save_raw = [
ImageSaver(output_dir_name="raw_unpacked", write_mask=False),
DatabaseImageInserter(db_table=Raw, duplicate_protocol="replace"),
# Group into planned stacks, and label each image with the intended stackid
ImageRebatcher(["BOARD_ID", "FILTER", "EXPTIME", TARGET_KEY, "SUBCOORD"]),
CustomImageBatchModifier(winter_stackid_annotator),
# Process each raw image in parallel
ImageRebatcher(BASE_NAME_KEY),
ImageSaver(output_dir_name="raw_unpacked", write_mask=False),
HeaderAnnotator(input_keys=LATEST_SAVE_KEY, output_key=RAW_IMG_KEY),
ImageRejector(("BOARD_ID", "0")),
Expand Down Expand Up @@ -444,7 +448,7 @@

stack_dithers = [
CustomImageBatchModifier(winter_boardid_6_demasker),
ImageRebatcher(["BOARD_ID", "FILTER", "EXPTIME", TARGET_KEY, "SUBCOORD"]),
ImageRebatcher("STACKID"),
Swarp(
swarp_config_path=swarp_config_path,
calculate_dims_in_swarp=True,
Expand Down
6 changes: 5 additions & 1 deletion mirar/processors/utils/image_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def _apply_to_images(
for image in batch:
new_image_file = image.header[self.header_key]
new_image = self.load_image(new_image_file)

if self.copy_header_keys is not None:
for key in self.copy_header_keys:
new_image.header[key] = image.header[key]
Expand Down Expand Up @@ -219,7 +220,10 @@ def __init__(
self.load_image = load_image

def description(self):
return f"Processor to load {len(self.img_list)} images from list"
return (
f"Load {len(self.img_list)} images from "
f"list of {len(self.img_list)} files"
)

def _apply_to_images(self, batch: ImageBatch) -> ImageBatch:
"""
Expand Down
6 changes: 5 additions & 1 deletion mirar/processors/utils/image_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ def split_images_into_batches(
groups[uid] = [image]
else:
groups[uid] += [image]
logger.debug(groups)

logger.debug(
" & ".join(f"({key}: {[str(x) for x in val]})" for key, val in groups.items())
)

res = Dataset([ImageBatch(x) for x in groups.values()])

return res
Expand Down

0 comments on commit d24ba48

Please sign in to comment.