From 96e9db09713727f467c59234e0403973fcc487d9 Mon Sep 17 00:00:00 2001 From: jluethi Date: Wed, 25 Oct 2023 15:14:38 +0200 Subject: [PATCH 1/5] Add failing test for get_ROI_table_with_translation --- ...test_unit_registration_helper_functions.py | 145 ++++++++++++------ 1 file changed, 95 insertions(+), 50 deletions(-) diff --git a/tests/tasks/test_unit_registration_helper_functions.py b/tests/tasks/test_unit_registration_helper_functions.py index df5677ef0..cb6b0bf3d 100644 --- a/tests/tasks/test_unit_registration_helper_functions.py +++ b/tests/tasks/test_unit_registration_helper_functions.py @@ -58,60 +58,105 @@ def test_calculate_physical_shifts(shifts): assert np.allclose(shifts_physical, expected_shifts_physical) -@pytest.mark.parametrize("fail", [False, True]) -def test_get_ROI_table_with_translation(fail: bool): - new_shifts = { - "FOV_1": [ - 0, - 7.8, - 32.5, - ], - "FOV_2": [ - 0, - 7.8, - 32.5, +ROI_table_FOV = ad.AnnData( + X=np.array( + [ + [ + -1.4483e03, + -1.5177e03, + 0.0000e00, + 4.1600e02, + 3.5100e02, + 1.0000e00, + -1.4483e03, + -1.5177e03, + ], + [ + -1.0323e03, + -1.5177e03, + 0.0000e00, + 4.1600e02, + 3.5100e02, + 1.0000e00, + -1.0323e03, + -1.5177e03, + ], ], - } - if fail: - new_shifts.pop("FOV_2") - ROI_table = ad.AnnData( - X=np.array( + dtype=np.float32, + ) +) +ROI_table_FOV.obs_names = ["FOV_1", "FOV_2"] +ROI_table_FOV.var_names = [ + "x_micrometer", + "y_micrometer", + "z_micrometer", + "len_x_micrometer", + "len_y_micrometer", + "len_z_micrometer", + "x_micrometer_original", + "y_micrometer_original", +] +new_shifts_FOV = { + "FOV_1": [ + 0, + 7.8, + 32.5, + ], + "FOV_2": [ + 0, + 7.8, + 32.5, + ], +} + + +ROI_table_well = ad.AnnData( + X=np.array( + [ [ - [ - -1.4483e03, - -1.5177e03, - 0.0000e00, - 4.1600e02, - 3.5100e02, - 1.0000e00, - -1.4483e03, - -1.5177e03, - ], - [ - -1.0323e03, - -1.5177e03, - 0.0000e00, - 4.1600e02, - 3.5100e02, - 1.0000e00, - -1.0323e03, - -1.5177e03, - ], + -1.4483e03, + -1.5177e03, + 0.0000e00, + 4.1600e02, + 3.5100e02, + 1.0000e00, ], - dtype=np.float32, - ) + ], + dtype=np.float32, ) - ROI_table.obs_names = ["FOV_1", "FOV_2"] - ROI_table.var_names = [ - "x_micrometer", - "y_micrometer", - "z_micrometer", - "len_x_micrometer", - "len_y_micrometer", - "len_z_micrometer", - "x_micrometer_original", - "y_micrometer_original", - ] +) +ROI_table_well.obs_names = ["well_1"] +ROI_table_well.var_names = [ + "x_micrometer", + "y_micrometer", + "z_micrometer", + "len_x_micrometer", + "len_y_micrometer", + "len_z_micrometer", +] +new_shifts_well = { + "well_1": [ + 0, + 7.8, + 32.5, + ], +} + + +@pytest.mark.parametrize( + "fail,ROI_table,new_shifts", + [ + (False, ROI_table_FOV, new_shifts_FOV), + (True, ROI_table_FOV, new_shifts_FOV), + (False, ROI_table_well, new_shifts_well), + ], +) +def test_get_ROI_table_with_translation( + fail: bool, ROI_table: ad.AnnData, new_shifts: dict +): + if fail: + new_shifts.pop(list(new_shifts.keys())[0]) + if fail: with pytest.raises(ValueError) as e: get_ROI_table_with_translation(ROI_table, new_shifts) From 0dce66696382d81583b847f4407bcb7e61fefe65 Mon Sep 17 00:00:00 2001 From: jluethi Date: Wed, 25 Oct 2023 15:50:39 +0200 Subject: [PATCH 2/5] Drop assumptions on column names in ROI tables, just add the new translation columns --- .../calculate_registration_image_based.py | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/fractal_tasks_core/tasks/calculate_registration_image_based.py b/fractal_tasks_core/tasks/calculate_registration_image_based.py index db9b52a19..53bb198dd 100644 --- a/fractal_tasks_core/tasks/calculate_registration_image_based.py +++ b/fractal_tasks_core/tasks/calculate_registration_image_based.py @@ -327,24 +327,10 @@ def get_ROI_table_with_translation( f"different length ({len(new_roi_table)=}) " f"from the original ROI table ({len(ROI_table)=})" ) - positional_columns = [ - "x_micrometer", - "y_micrometer", - "z_micrometer", - "len_x_micrometer", - "len_y_micrometer", - "len_z_micrometer", - "x_micrometer_original", - "y_micrometer_original", - "translation_z", - "translation_y", - "translation_x", - ] - adata = ad.AnnData( - X=new_roi_table.loc[:, positional_columns].astype(np.float32) - ) + + adata = ad.AnnData(X=new_roi_table.astype(np.float32)) adata.obs_names = new_roi_table.index - adata.var_names = list(map(str, positional_columns)) + adata.var_names = list(map(str, new_roi_table.columns)) return adata From 86009274cab4c617fb23a65f466dd91cf7fbe719 Mon Sep 17 00:00:00 2001 From: jluethi Date: Wed, 25 Oct 2023 15:52:39 +0200 Subject: [PATCH 3/5] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 427b0f424..a888b6a26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ # Unreleased * Always use `write_table` in tasks, rather than AnnData `write_elem` (\#581). +* Remove assumptions on columns in ROI frames from Calculate registration (image-based) (\#590). * Testing: * Cache Zenodo data, within GitHub actions (\#585). From c4629c965f028dee9629d5942bdcca93a58a0cb9 Mon Sep 17 00:00:00 2001 From: Tommaso Comparin <3862206+tcompa@users.noreply.github.com> Date: Thu, 26 Oct 2023 10:37:23 +0200 Subject: [PATCH 4/5] Update CHANGELOG [skip ci] --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a888b6a26..999f8175e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ # Unreleased * Always use `write_table` in tasks, rather than AnnData `write_elem` (\#581). -* Remove assumptions on columns in ROI frames from Calculate registration (image-based) (\#590). +* Remove assumptions on ROI-table columns from `get_ROI_table_with_translation` helper function of `calculate_registration_image_based` task (\#591). * Testing: * Cache Zenodo data, within GitHub actions (\#585). From e84bd743cb1653dbf0731d1c2ef24f242f7cb348 Mon Sep 17 00:00:00 2001 From: Tommaso Comparin <3862206+tcompa@users.noreply.github.com> Date: Thu, 26 Oct 2023 10:37:35 +0200 Subject: [PATCH 5/5] Update CHANGELOG [skip ci] --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 999f8175e..467983a23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ **Note**: Numbers like (\#123) point to closed Pull Requests on the fractal-tasks-core repository. -# Unreleased +# 0.13.1 * Always use `write_table` in tasks, rather than AnnData `write_elem` (\#581). * Remove assumptions on ROI-table columns from `get_ROI_table_with_translation` helper function of `calculate_registration_image_based` task (\#591).