Skip to content

Commit 2d93a26

Browse files
committed
Added '_Lng_LVCC' files to test dataset and added more checks to ensure that the ISPyB entries all register the denoised datasets in their final state
1 parent cae2b69 commit 2d93a26

File tree

1 file changed

+35
-17
lines changed

1 file changed

+35
-17
lines changed

tests/workflows/clem/test_register_preprocessing_results.py

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def generate_preprocessing_messages(
4747
# Construct all the datasets to be tested
4848
datasets: list[tuple[Path, bool, bool, tuple[int, int], float, list[float]]] = [
4949
(
50-
grid_dir / "Overview_1" / "Image_1",
50+
grid_dir / "Overview 1" / "Image 1",
5151
False,
5252
True,
5353
(2400, 2400),
@@ -59,22 +59,38 @@ def generate_preprocessing_messages(
5959
datasets.extend(
6060
[
6161
(
62-
grid_dir / "TileScan_1" / f"Position_{n}",
62+
grid_dir / "TileScan 1" / f"Position {n + 1}",
6363
True,
6464
False,
6565
(2048, 2048),
6666
1.6e-7,
6767
[0.003, 0.00332768, 0.003, 0.00332768],
6868
)
69-
for n in range(5)
69+
for n in range(3)
70+
]
71+
)
72+
datasets.extend(
73+
[
74+
(
75+
grid_dir / "TileScan 1" / f"Position {n + 1}_Lng_LVCC",
76+
True,
77+
False,
78+
(2048, 2048),
79+
1.6e-7,
80+
[0.003, 0.00332768, 0.003, 0.00332768],
81+
)
82+
for n in range(3)
7083
]
7184
)
7285

7386
messages: list[dict[str, Any]] = []
74-
for dataset in datasets:
87+
for series_path, is_stack, is_montage, shape, pixel_size, extent in datasets:
7588
# Unpack items from list of dataset parameters
76-
series_path = dataset[0]
77-
series_name = str(series_path.relative_to(processed_dir)).replace("/", "--")
89+
series_name = (
90+
str(series_path.relative_to(processed_dir))
91+
.replace("/", "--")
92+
.replace(" ", "_")
93+
)
7894
metadata = series_path / "metadata" / f"{series_path.stem}.xml"
7995
metadata.parent.mkdir(parents=True, exist_ok=True)
8096
metadata.touch(exist_ok=True)
@@ -89,11 +105,6 @@ def generate_preprocessing_messages(
89105
thumbnail.parent.mkdir(parents=True)
90106
thumbnail.touch(exist_ok=True)
91107
thumbnail_size = (512, 512)
92-
is_stack = dataset[1]
93-
is_montage = dataset[2]
94-
shape = dataset[3]
95-
pixel_size = dataset[4]
96-
extent = dataset[5]
97108

98109
message = {
99110
"session_id": session_id,
@@ -373,21 +384,23 @@ def test_run_with_db(
373384
else:
374385
assert mock_align_and_merge_call.call_count == len(preprocessing_messages) * 3
375386

376-
# Both databases should have entries for data collection group, and grid squares
377-
# ISPyB database should additionally have an atlas entry
387+
# Murfey's DataCollectionGroup should have an entry
378388
murfey_dcg_search = murfey_db_session.exec(
379389
sm_select(MurfeyDB.DataCollectionGroup).where(
380390
MurfeyDB.DataCollectionGroup.session_id == murfey_session.id
381391
)
382392
).all()
383393
assert len(murfey_dcg_search) == 1
394+
395+
# GridSquare entries should be half the initial number of entries due to overwrites
384396
murfey_gs_search = murfey_db_session.exec(
385397
sm_select(MurfeyDB.GridSquare).where(
386398
MurfeyDB.GridSquare.session_id == murfey_session.id
387399
)
388400
).all()
389-
assert len(murfey_gs_search) == len(preprocessing_messages) - 1
401+
assert len(murfey_gs_search) == (len(preprocessing_messages) - 1) // 2
390402

403+
# ISPyB's DataCollectionGroup should have an entry
391404
murfey_dcg = murfey_dcg_search[0]
392405
ispyb_dcg_search = (
393406
ispyb_db_session.execute(
@@ -400,6 +413,7 @@ def test_run_with_db(
400413
)
401414
assert len(ispyb_dcg_search) == 1
402415

416+
# Atlas should have an entry
403417
ispyb_dcg = ispyb_dcg_search[0]
404418
ispyb_atlas_search = (
405419
ispyb_db_session.execute(
@@ -419,12 +433,13 @@ def test_run_with_db(
419433
}
420434
collection_mode = _determine_collection_mode(colors)
421435

436+
# Atlas color flags and collection mode should be set correctly
422437
ispyb_atlas = ispyb_atlas_search[0]
423-
# Check that the Atlas color flags and collection mode are set correctly
424438
for flag, value in color_flags.items():
425439
assert getattr(ispyb_atlas, flag) == value
426440
assert ispyb_atlas.mode == collection_mode
427441

442+
# ISPyB's GrridSquare should have half the number of intiail entries
428443
ispyb_gs_search = (
429444
ispyb_db_session.execute(
430445
sa_select(ISPyBDB.GridSquare).where(
@@ -434,9 +449,12 @@ def test_run_with_db(
434449
.scalars()
435450
.all()
436451
)
437-
assert len(ispyb_gs_search) == len(preprocessing_messages) - 1
452+
assert len(ispyb_gs_search) == (len(preprocessing_messages) - 1) // 2
438453
for gs in ispyb_gs_search:
439-
# Check that the Atlas color flags and collection mode are set correctly
454+
# Check that all entries point to the denoised images ("_Lng_LVCC")
455+
assert gs.gridSquareImage is not None and "_Lng_LVCC" in gs.gridSquareImage
456+
457+
# Check that the GridSquare color flags and collection mode are set correctly
440458
for flag, value in color_flags.items():
441459
assert getattr(gs, flag) == value
442460
assert gs.mode == collection_mode

0 commit comments

Comments
 (0)