Skip to content

Commit

Permalink
reduces debug
Browse files Browse the repository at this point in the history
  • Loading branch information
David Erb committed May 5, 2023
1 parent e5b5f79 commit 647bf2f
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/xchem_chimp/detector/coord_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,12 @@ def save_preview_images(self, output_dir: Path, scale: int = 0.5) -> None:
plt.close()

def calculate_well_centres(self) -> None:
logging.debug("Calculating well centroids...")
# Load in background images
logging.debug("Loading background images")
# Load in background images.
# TODO: Make static background images for other plate types besides swiss3.
bg_image_pths = sorted(list(BG_IMAGE_DIR.glob("*.png")))
bg_image_arrays = [img_as_float(skio.imread(pth)) for pth in bg_image_pths]
for output_dict in self.combined_coords_list:
im_path = output_dict["image_path"]
logging.debug(f"{im_path}")
im_array = self.read_and_resize_image(im_path)
if "_1.jpg" in im_path:
bg_image = bg_image_arrays[0]
Expand All @@ -149,13 +147,24 @@ def calculate_well_centres(self) -> None:
elif "_3.jpg" in im_path:
bg_image = bg_image_arrays[2]
else:
logging.error("Could not parse filename.")
raise RuntimeError(
f'image filename "{im_path}" does not end with _1, _2 or _3'
)
corr = signal.correlate2d(im_array, bg_image, mode="same", boundary="fill")
y, x = np.unravel_index(np.argmax(corr), corr.shape)
y, x = np.rint(np.array([y, x]) * (1.0 / IM_SCALE_FACTOR)).astype(int)
logging.debug(f"Well centroid found at {y, x}")
# Apply a fixed fudge offset to compensate for some unknown systematic problem in the well centroid detection.
# TODO: Fix problem where well centroid calculation apparently is shifted from the true value.
# UPDATE crystal_well_autolocations SET well_centroid_x = well_centroid_x + 30, well_centroid_y = well_centroid_y - 10
fudge_x = 30
fudge_y = -10
x += fudge_x
y += fudge_y
logging.debug(
f"Well centroid found at {x, y} after applying fudge offset {fudge_x, fudge_y}"
)
output_dict["well_centroid"] = [y, x]
# Calculate realspace offset and add to dictionary
# Calculate realspace offset and add to dictionary.
if output_dict["echo_coordinate"]:
output_dict["real_space_offset"] = utils.calculate_realspace_offset(
output_dict["echo_coordinate"][0],
Expand Down

0 comments on commit 647bf2f

Please sign in to comment.