Skip to content

Commit

Permalink
- Added function load_monitor_log.
Browse files Browse the repository at this point in the history
- Added JSON config to use Monitor Normalisation
- Improved error messages for missing related filename groups or log files.
  • Loading branch information
ashmeigh committed Jun 4, 2024
1 parent 619bdd4 commit 16973ff
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 19 deletions.
37 changes: 36 additions & 1 deletion 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 @@ -28,6 +29,7 @@
exit(1)

sys.path.append(str(Path(__file__).resolve().parent.parent.parent))
from mantidimaging.core.utility.data_containers import FILE_TYPES
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
Expand Down Expand Up @@ -139,8 +141,13 @@ 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':
self.load_monitor_log(test_case.params)

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")
Expand All @@ -163,6 +170,34 @@ def run_test(self, test_case):

TEST_CASE_RESULTS.append(test_case)

def load_monitor_log(self, params):
filename_group = FilenameGroup.from_file(config_manager.load_sample)
log_file_type = params['log_file_type']

if not hasattr(FILE_TYPES, log_file_type):
raise AttributeError(f"{log_file_type} not found in FILE_TYPES")

print(f"Looking for related files of type: {log_file_type}")
file_type_enum = getattr(FILE_TYPES, log_file_type)
related_filename_group = filename_group.find_related(file_type_enum)

if not related_filename_group:
raise FileNotFoundError(f"Related filename group for {log_file_type} not found.")

print(f"Related filename group found: {related_filename_group}")
related_filename_group.find_all_files()

log_file_path = filename_group.find_log_file()
if not log_file_path:
raise FileNotFoundError("Log file not found.")

print(f"Log file path: {log_file_path}") # Debug statement

with open(log_file_path) as file:
log_data = file.read()
print(f"Loaded monitor log from {log_file_path}")
return log_data

def add_nan(self, image_stack, fraction=0.001):
data = image_stack.data
total_elements = data.size
Expand Down
34 changes: 16 additions & 18 deletions scripts/operations_tests/test_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -642,39 +642,37 @@
}
]
},
"Circular Mask": {
"Monitor Normalisation": {
"params": {
"circular_mask_ratio": 0.95,
"circular_mask_value": 0.0
"use_dark": false,
"selected_normalisation": "Monitor"
},
"source_data": "reconstructedSlices",
"source_data": "flower128",
"cases": [
{
"test_name": "circular_mask_default",
"test_name": "default_normalisation",
"pre_run_step": "load_monitor_log",
"params": {
"circular_mask_ratio": 0.95,
"circular_mask_value": 0.0
"log_file_type": "SAMPLE_LOG"
}
},
{
"test_name": "circular_mask_tight",
"params": {
"circular_mask_ratio": 0.5,
"circular_mask_value": 0.0
}
"test_name": "no_log_file",
"pre_run_step": "none",
"params": {}
},
{
"test_name": "circular_mask_loose",
"test_name": "incorrect_log_values",
"pre_run_step": "load_monitor_log",
"params": {
"circular_mask_ratio": 0.99,
"circular_mask_value": 0.0
"log_file_type": "FLAT_BEFORE_LOG"
}
},
{
"test_name": "circular_mask_value",
"test_name": "different_exposure_times",
"pre_run_step": "load_monitor_log",
"params": {
"circular_mask_ratio": 0.95,
"circular_mask_value": -1000
"log_file_type": "FLAT_AFTER_LOG"
}
}
]
Expand Down

0 comments on commit 16973ff

Please sign in to comment.