Skip to content

Commit

Permalink
Merge pull request #591 from fractal-analytics-platform/590-generaliz…
Browse files Browse the repository at this point in the history
…e-calculate-registration-roi-table-handling

590 generalize calculate registration roi table handling
  • Loading branch information
tcompa authored Oct 26, 2023
2 parents 4f39f32 + e84bd74 commit 897c8f6
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 68 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
**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).
* Testing:
* Cache Zenodo data, within GitHub actions (\#585).

Expand Down
20 changes: 3 additions & 17 deletions fractal_tasks_core/tasks/calculate_registration_image_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
145 changes: 95 additions & 50 deletions tests/tasks/test_unit_registration_helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 897c8f6

Please sign in to comment.