Skip to content

20x alignment fixes and tests #32

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

Merged
merged 1 commit into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions camera_alignment_core/alignment_utils/segment_rings.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(
self.thresh = (0.5, 99.5)

def dot_2d_slice_by_slice_wrapper(
self, struct_img: np.typing.NDArray[np.uint16], s2_param: List
self, struct_img: np.typing.NDArray[np.float32], s2_param: List
) -> np.typing.NDArray[np.bool_]:
"""
https://github.com/AllenCell/aics-segmentation/blob/main/aicssegmentation/core/seg_dot.py
Expand Down Expand Up @@ -197,7 +197,7 @@ def segment_rings_dot_filter(
thresh: filter parameter after optimization

"""
img = np.zeros((1, img_2d.shape[0], img_2d.shape[1]), dtype=np.uint16)
img = np.zeros((1, img_2d.shape[0], img_2d.shape[1]), dtype=np.float32)
img[0, :, :] = img_2d

thresh = None
Expand Down
3 changes: 3 additions & 0 deletions camera_alignment_core/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
# Taken from /allen/aics/microscopy/PRODUCTION/OpticalControl/ArgoLight/Argo_QC_Daily/ZSD1/ZSD1_argo_100X_SLF-015_20210624 # noqa E501
ZSD_100x_OPTICAL_CONTROL_IMAGE_URL = "https://s3.us-west-2.amazonaws.com/public-dev-objects.allencell.org/camera-alignment-core/optical-controls/argo_ZSD1_100X_SLF-015_20210624.czi" # noqa E501

# Taken from //allen/aics/microscopy/PRODUCTION/OpticalControl/ArgoLight/Argo_QC_Daily/ZSD1/ZSD1_argo_20X_SLG-506_20220510/ZSD1_argo_20X_SLG-506_20220510.czi # noqa E501
ZSD_20x_OPTICAL_CONTROL_IMAGE_URL = "https://s3.us-west-2.amazonaws.com/public-dev-objects.allencell.org/camera-alignment-core/optical-controls/ZSD1_argo_20X_SLG-506_20220510.czi" # noqa E501

# FMS ID: 0023c446cd384dc3947c90dc7a76f794; 303.38 MB
GENERIC_OME_TIFF_URL = "https://s3.us-west-2.amazonaws.com/public-dev-objects.allencell.org/camera-alignment-core/images/3500003897_100X_20200306_1r-Scene-30-P89-G11.ome.tiff" # noqa E501

Expand Down
32 changes: 32 additions & 0 deletions camera_alignment_core/tests/test_alignment_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
ALIGNED_ZSD1_IMAGE_URL,
ARGOLIGHT_OPTICAL_CONTROL_IMAGE_URL,
UNALIGNED_ZSD1_IMAGE_URL,
ZSD_20x_OPTICAL_CONTROL_IMAGE_URL,
ZSD_100x_OPTICAL_CONTROL_IMAGE_URL,
get_test_image,
)
Expand Down Expand Up @@ -66,6 +67,37 @@ def test_generate_alignment_matrix(self):
actual_alignment_matrix - expected_matrix
)

def test_generate_alignment_matrix_20x(self):
# Arrange
optical_control_image, _ = get_test_image(ZSD_20x_OPTICAL_CONTROL_IMAGE_URL)
optical_control_image_data = optical_control_image.get_image_data("CZYX", T=0)

expected_matrix = numpy.array(
[
[1.00122588e00, -3.02161488e-03, 1.91048540e00],
[3.02161488e-03, 1.00122588e00, -4.75823245e00],
[0.00000000e00, 0.00000000e00, 1.00000000e00],
]
)

# Act
(actual_alignment_matrix, _,) = generate_alignment_matrix(
optical_control_image_data,
reference_channel=2, # TaRFP
shift_channel=3, # CMDRP
magnification=Magnification.TWENTY.value,
px_size_xy=optical_control_image.physical_pixel_sizes.X,
)

# Assert
assert actual_alignment_matrix.shape == expected_matrix.shape

# Due to inherent challenges with floating point precision across different environments,
# compare actual vs expected elementwise with a (very) small epsilon (i.e., allowed error margin)
assert numpy.allclose(actual_alignment_matrix, expected_matrix, atol=1e-14), (
actual_alignment_matrix - expected_matrix
)

def test_generate_alignment_matrix_reproducability(self):
# Arrange
optical_control_image, _ = get_test_image(ZSD_100x_OPTICAL_CONTROL_IMAGE_URL)
Expand Down