Skip to content

Commit

Permalink
Update roi table calculation to fix 3D support
Browse files Browse the repository at this point in the history
  • Loading branch information
jluethi committed May 31, 2024
1 parent 0520bd1 commit 8b082a9
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/fractal_faim_ipa/__FRACTAL_MANIFEST__.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@
"enum": [
"MD Stack Acquisition",
"MD Single Plane Acquisition",
"MD MixedAcquisition",
"MD Mixed Acquisition",
"MetaXpress MD Stack Acquisition",
"MetaXpress MD Single Plane Acquisition",
"MetaXpress MD Single Plane Acquisition as 3D"
"MetaXpress MD Single Plane Acquisition as 3D",
"MetaXpress MD Mixed Acquisition"
],
"type": "string",
"description": "Choose conversion mode. MetaXpress modes are used when data is exported via MetaXpress. Choose whether you have 3D data (StackAcquisition), 2D data (Single Plane Acquisition) or mixed."
Expand Down
4 changes: 4 additions & 0 deletions src/fractal_faim_ipa/roi_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def create_ROI_tables(plate_acquisition: PlateAcquisition):
# Get pixel sizes
xy_spacing = well_acquisition.get_yx_spacing()
z_spacing = well_acquisition.get_z_spacing()
# Set Z spacing to 1 if it's not set, because Fractal ROI tables
# always contain XYZ information.
if z_spacing is None:
z_spacing = 1
pixel_size_zyx = (z_spacing, *xy_spacing)

# Create ROI tables
Expand Down
71 changes: 67 additions & 4 deletions tests/test_roi_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@
from fractal_faim_ipa.roi_tables import create_ROI_tables


def test_roi_tables():
@pytest.mark.parametrize(
"mode", ["MD Stack Acquisition", "MD Single Plane Acquisition"]
)
def test_roi_tables(mode):
ROOT_DIR = Path(__file__).parent
image_dir = str(join(ROOT_DIR.parent, "resources", "Projection-Mix"))

mode = ModeEnum.StackAcquisition
mode = ModeEnum(mode)
plate_acquisition = mode.get_plate_acquisition(
acquisition_dir=image_dir,
alignment=TileAlignmentOptions.GRID,
)
roi_tables = create_ROI_tables(plate_acquisition=plate_acquisition)
assert set(roi_tables.keys()) == {"E08", "E07"}
assert set(roi_tables["E08"].keys()) == {"FOV_ROI_table", "well_ROI_table"}
print(roi_tables["E08"]["FOV_ROI_table"].to_df())
print(roi_tables["E08"]["well_ROI_table"].to_df())

target_values = [
0.0,
Expand All @@ -31,6 +32,9 @@ def test_roi_tables():
699.8015747070312,
50.0,
]
if mode == ModeEnum.SinglePlaneAcquisition:
target_values[5] = 1.0

assert all(
math.isclose(a, b, rel_tol=1e-5)
for a, b in zip(
Expand Down Expand Up @@ -59,6 +63,8 @@ def test_roi_tables():
699.8015747070312,
50.0,
]
if mode == ModeEnum.SinglePlaneAcquisition:
target_values[5] = 1.0
assert all(
math.isclose(a, b, rel_tol=1e-5)
for a, b in zip(df_fov.loc["FOV_2"].values.flatten().tolist(), target_values)
Expand Down Expand Up @@ -117,3 +123,60 @@ def test_roi_table_overlaps(alignment):
target_values_well[alignment],
)
)


# def test_roi_tables_2d():
# ROOT_DIR = Path(__file__).parent
# image_dir = str(join(ROOT_DIR.parent, "resources", "Projection-Mix"))

# mode = ModeEnum.SinglePlaneAcquisition
# plate_acquisition = mode.get_plate_acquisition(
# acquisition_dir=image_dir,
# alignment=TileAlignmentOptions.GRID,
# )
# roi_tables = create_ROI_tables(plate_acquisition=plate_acquisition)
# assert set(roi_tables.keys()) == {"E08", "E07"}
# assert set(roi_tables["E08"].keys()) == {"FOV_ROI_table", "well_ROI_table"}
# print(roi_tables["E08"]["FOV_ROI_table"].to_df())
# print(roi_tables["E08"]["well_ROI_table"].to_df())

# target_values = [
# 0.0,
# 0.0,
# 0.0,
# 1399.6031494140625,
# 699.8015747070312,
# 50.0,
# ]
# assert all(
# math.isclose(a, b, rel_tol=1e-5)
# for a, b in zip(
# roi_tables["E08"]["well_ROI_table"].to_df().values.flatten().tolist(),
# target_values,
# )
# )

# roi_columns = [
# "x_micrometer",
# "y_micrometer",
# "z_micrometer",
# "len_x_micrometer",
# "len_y_micrometer",
# "len_z_micrometer",
# ]

# df_fov = roi_tables["E08"]["FOV_ROI_table"].to_df()
# assert list(df_fov.columns) == roi_columns
# assert len(df_fov) == 2
# target_values = [
# 699.8015747070312,
# 0.0,
# 0.0,
# 699.8015747070312,
# 699.8015747070312,
# 50.0,
# ]
# assert all(
# math.isclose(a, b, rel_tol=1e-5)
# for a, b in zip(df_fov.loc["FOV_2"].values.flatten().tolist(), target_values)
# )

0 comments on commit 8b082a9

Please sign in to comment.