-
Notifications
You must be signed in to change notification settings - Fork 5
chore: Update output data validations for frames and ctf #484
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
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b482456
- add frame_metadata fixture
Bento007 99f37d7
- add test for "Sorting acquisitionOrder low-to-high and accumulatedD…
Bento007 2887959
change to "max(acquisitionOrder) < number of frames"
Bento007 e3d8171
Validations for PerSectionParameter Metadata
Bento007 9dff442
Merge branch 'refs/heads/main' into tsmith/1528-frame-ctf-valdiation
Bento007 568ebdf
move tests to get correct metadata
Bento007 dc68a97
is in_plane_rotation for test_mdoc_tilt_axis_angle_in_alignment_per_s…
Bento007 9cfe355
make suggestest changes
Bento007 56e70ee
use angle_helper
Bento007 bc467e1
use 1 tolerance for dose rate
Bento007 976a1bc
use 1 tolerance for dose rate
Bento007 8771009
use 1 tolerance for dose rate
Bento007 407329c
minor tweak
Bento007 01d511d
Raise AssertionError if multiple errors are found
Bento007 d661774
use copies when distructive operations happen on the data
Bento007 2b35638
undo .copy
Bento007 dadfb58
Apply suggestions from code review
Bento007 3b11915
- fix spacing for -1 to - 1
Bento007 84b1885
Merge branch 'refs/heads/main' into tsmith/1528-frame-ctf-valdiation
Bento007 02f4ffa
Merge branch 'refs/heads/main' into tsmith/1528-frame-ctf-valdiation
Bento007 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 23 additions & 1 deletion
24
ingestion_tools/scripts/data_validation/standardized/tests/test_frame.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,31 @@ | ||
from typing import Dict, List, Union | ||
|
||
import allure | ||
import pytest | ||
import tifffile | ||
from data_validation.shared.helper.twodee_helper import FrameTestHelper | ||
from mrcfile.mrcinterpreter import MrcInterpreter | ||
|
||
|
||
@pytest.mark.frame | ||
@pytest.mark.parametrize("dataset, run_name", pytest.cryoet.dataset_run_combinations, scope="session") | ||
class TestFrame(FrameTestHelper): | ||
pass | ||
@allure.title("Frames: When isGainCorrected == False, a Gains entity exists for the run") | ||
def test_is_gain_corrected_false(self, | ||
frame_metadata: Dict, | ||
gain_headers: Dict[str, Union[List[tifffile.TiffPage], MrcInterpreter]], # this is skipped if it is not found | ||
): | ||
if not frame_metadata.get("is_gain_corrected"): | ||
assert len(gain_headers) > 0 | ||
|
||
@allure.title("Frames: max(acquisitionOrder) <= number of frames -1") | ||
def test_max_acquisition_order(self, frame_metadata: Dict): | ||
acquisition_order_max = max(f.get("acquisition_order", 0) for f in frame_metadata["frames"]) | ||
assert acquisition_order_max <= len(frame_metadata["frames"]) - 1 | ||
|
||
@allure.title("Frames: Sorting acquisitionOrder low-to-high and accumulatedDose low-to-high results in the same order") | ||
def test_sorting_acquisition_order_and_accumulated_dose(self, frame_metadata: Dict): | ||
frames = frame_metadata["frames"] | ||
frames_sorted_by_acquisition_order = sorted(frames, key=lambda f: (f["acquisition_order"])) | ||
frames_sorted_by_accumulated_dose = sorted(frames, key=lambda f: (f["accumulated_dose"])) | ||
assert frames_sorted_by_acquisition_order == frames_sorted_by_accumulated_dose |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import math | ||
import os | ||
from typing import Dict | ||
from typing import Any, Dict | ||
|
||
import allure | ||
import numpy as np | ||
import pandas as pd | ||
import pytest | ||
from data_validation.shared.helper.angles_helper import helper_angles_injection_errors | ||
|
@@ -135,3 +136,79 @@ def test_mdoc_tiltseries_range( | |
) | ||
|
||
### END metadata-mdoc consistency tests ### | ||
|
||
@allure.title("Tiltseries: sum of exposureDose of all frames associated with a tilt series == totalFlux +-1 of tilt series") | ||
def test_exposure_dose(self, frame_metadata: Dict, tiltseries_metadata: Dict): | ||
assert sum(f.get("exposure_dose", 0) for f in frame_metadata["frames"]) == pytest.approx(tiltseries_metadata["total_flux"], abs=1) | ||
|
||
@allure.title("PerSectionParameters: number of frames >= # of per section parameters.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The label of what it is testing against like "PerSectionParameters" is very neat! 😄 |
||
def test_per_section_parameter_with_num_frames(self, tiltseries_metadata: dict[str, Any], frame_metadata: dict[str, dict]): | ||
num_frames = len(frame_metadata["frames"]) | ||
num_per_section_parameters = len(tiltseries_metadata["per_section_parameter"]) | ||
assert num_frames >= num_per_section_parameters, f"Number of frames {num_frames} is less than number of per section parameters {num_per_section_parameters}." | ||
|
||
@allure.title("PerSectionParameters: -180 <= astigmatic_angle <= 180.") | ||
def test_astigmatic_angle(self, tiltseries_metadata: dict[str, Any]): | ||
errors = [] | ||
for i, per_section_parameter in enumerate(tiltseries_metadata["per_section_parameter"]): | ||
astigmatic_angle = per_section_parameter["astigmatic_angle"] | ||
if astigmatic_angle is None: | ||
continue | ||
try: | ||
assert -180 <= astigmatic_angle <= 180 | ||
except AssertionError: | ||
errors.append(f"per_section_parameter[{i}].astigmatic_angle= {astigmatic_angle} is out of range [-180, 180].") | ||
if len(errors) > 0: | ||
raise AssertionError("\n".join(errors)) | ||
|
||
@allure.title("PerSectionParameters: 0 <= phaseShift <= 2*pi.") | ||
def test_phase_shift(self, tiltseries_metadata: dict[str, Any]): | ||
errors = [] | ||
for i, per_section_parameter in enumerate(tiltseries_metadata["per_section_parameter"]): | ||
phase_shift = per_section_parameter["phase_shift"] | ||
if phase_shift is None: | ||
continue | ||
try: | ||
assert 0 <= phase_shift <= 2 * np.pi | ||
except AssertionError: | ||
errors.append(f"per_section_parameter[{i}].phase_shift= {phase_shift} is out of range [0, 2*pi].") | ||
if len(errors) > 0: | ||
raise AssertionError("\n".join(errors)) | ||
|
||
@allure.title("PerSectionParameters: maxResolution > 0.") | ||
def test_max_resolution(self, tiltseries_metadata: dict[str, Any]): | ||
errors = [] | ||
for i, per_section_parameter in enumerate(tiltseries_metadata["per_section_parameter"]): | ||
max_resolution = per_section_parameter["max_resolution"] | ||
if max_resolution is None: | ||
continue | ||
try: | ||
assert max_resolution > 0 | ||
except AssertionError: | ||
errors.append(f"per_section_parameter[{i}].max_resolution= {max_resolution} is not greater than 0.") | ||
if len(errors) > 0: | ||
raise AssertionError("\n".join(errors)) | ||
|
||
@allure.title("PerSectionParameters: rawAngle matches mdoc TiltAngle (+-10^-3 deg).") | ||
def test_raw_angle(self, tiltseries_metadata: dict[str, Any], mdoc_data: pd.DataFrame): | ||
errors = helper_angles_injection_errors( | ||
mdoc_data["TiltAngle"].to_list(), | ||
[psp["raw_angle"] for psp in tiltseries_metadata["per_section_parameter"]], | ||
"mdoc file", | ||
"tiltseries metadata per_section_parameter raw_angle", | ||
angle_tolerance=10 ** -3, | ||
manasaV3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
if errors: | ||
raise AssertionError("\n".join(errors)) | ||
|
||
@allure.title("PerSectionParameters: 0 <= zIndex <= (z-Dimension of tilt series - 1).") | ||
def test_z_index(self, tiltseries_metadata: dict[str, Any]): | ||
errors = [] | ||
for i, per_section_parameter in enumerate(tiltseries_metadata["per_section_parameter"]): | ||
z_index = per_section_parameter["z_index"] | ||
try: | ||
assert 0 <= z_index <= (tiltseries_metadata["size"]["z"] - 1) | ||
except AssertionError: | ||
errors.append(f"per_section_parameter[{i}].z_index= {z_index} is out of range [0, {tiltseries_metadata['size']['z'] - 1}].") | ||
if len(errors) > 0: | ||
raise AssertionError("\n".join(errors)) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@uermel Could you sanity check if this is the formula we should be using for our use case?