Skip to content
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

Tests for Monitor Normalisation: #2215

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions scripts/operations_tests/operations_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import numpy as np
import pandas as pd

try:
from plotly import graph_objs as go
from plotly.subplots import make_subplots
Expand All @@ -31,6 +32,7 @@
from mantidimaging.core.io.filenames import FilenameGroup # noqa: E402
from mantidimaging.core.io.loader import loader # noqa: E402
from mantidimaging.core.operations.loader import load_filter_packages # noqa: E402
from mantidimaging.core.io.instrument_log import InstrumentLog

script_dir = Path(__file__).resolve().parent
log_directory = script_dir / "logs"
Expand Down Expand Up @@ -139,11 +141,15 @@ def run_tests(self):
def run_test(self, test_case):
image_stack = self.load_image_stack()

# Handling various pre-run steps
if test_case.pre_run_step == 'add_nan':
self.image_stack = self.add_nan(image_stack, fraction=0.1)
image_stack = self.add_nan(image_stack, fraction=0.1)
elif test_case.pre_run_step == 'load_monitor_log':
log_data = self.load_monitor_log()
image_stack.log_file = log_data

test_case.duration, new_image_stack = self.time_operation(image_stack, test_case.op_func, test_case.params)
file_name = config_manager.save_dir / (test_case.test_name + ".npz")
file_name = config_manager.save_dir / f"{test_case.test_name}.npz"

if file_name.is_file():
baseline_image_stack = self.load_post_operation_image_stack(file_name)
Expand All @@ -163,6 +169,18 @@ def run_test(self, test_case):

TEST_CASE_RESULTS.append(test_case)

def load_monitor_log(self):
filename_group = FilenameGroup.from_file(config_manager.load_sample)
filename_group.find_log_file()
log_file_path = filename_group.log_path

if log_file_path is None:
raise ValueError("Log file path could not be determined.")

with open(log_file_path) as file:
log_lines = file.readlines()
return InstrumentLog(log_lines, Path(log_file_path))

def add_nan(self, image_stack, fraction=0.001):
data = image_stack.data
total_elements = data.size
Expand Down
12 changes: 12 additions & 0 deletions scripts/operations_tests/test_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -678,5 +678,17 @@
}
}
]
},
"Monitor Normalisation": {
"params": {},
"source_data": "flower128",
"cases": [
{
"test_name": "default_normalisation",
"pre_run_step": "load_monitor_log",
"params": {
}
}
]
}
}