Avoid negative dx/dy and allow for float CSM image resolution

This commit is contained in:
jaknapper 2024-01-10 15:38:34 +00:00
parent d219e32bc8
commit 6d622c1bf8

View file

@ -110,7 +110,7 @@ def distance_to_site(current, next):
def steps_from_centre(current_loc, starting_loc, dx, dy): def steps_from_centre(current_loc, starting_loc, dx, dy):
step_size = np.array([dx,dy]) step_size = np.array([dx,dy])
return np.max(np.divide(np.abs(np.subtract(current_loc, starting_loc)), step_size)) return np.max(np.abs(np.divide(np.subtract(current_loc, starting_loc), step_size)))
# def set_template(microscope, pos): # def set_template(microscope, pos):
# microscope.move(pos) # microscope.move(pos)
@ -368,7 +368,7 @@ class SmartScanThing(Thing):
r = cam.grab_jpeg() r = cam.grab_jpeg()
arr = np.array(Image.open(r.open())) arr = np.array(Image.open(r.open()))
if list(arr.shape[:2]) != csm.image_resolution: if list(arr.shape[:2]) != [int(i) for i in csm.image_resolution]:
logger.error( logger.error(
f"Images are, by default, {arr.shape[:2]}, but the CSM was " f"Images are, by default, {arr.shape[:2]}, but the CSM was "
f"calibrated at {csm.image_resolution}." f"calibrated at {csm.image_resolution}."
@ -386,8 +386,8 @@ class SmartScanThing(Thing):
overlap = self.overlap overlap = self.overlap
dx = int(np.dot(np.array([0, arr.shape[1] * (1 - overlap)]), CSM)[0]) dx = int(np.abs(np.dot(np.array([0, arr.shape[1] * (1 - overlap)]), CSM)[0]))
dy = int(np.dot(np.array([arr.shape[0] * (1 - overlap), 0]), CSM)[1]) dy = int(np.abs(np.dot(np.array([arr.shape[0] * (1 - overlap), 0]), CSM)[1]))
logger.info(f"Based on an overlap of {overlap}, we will make steps of {dx}, {dy}") logger.info(f"Based on an overlap of {overlap}, we will make steps of {dx}, {dy}")