Skip to content

Commit

Permalink
updated branch
Browse files Browse the repository at this point in the history
  • Loading branch information
ashmeigh committed Jun 7, 2024
1 parent f482056 commit 8d95f52
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
24 changes: 22 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,17 @@ 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 == 'add_flats_and_darks':
self.add_flats_and_darks(test_case.params)
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 +171,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": {
}
}
]
}
}

0 comments on commit 8d95f52

Please sign in to comment.