Skip to content

Commit

Permalink
Merge 63e19bc into aa6025b
Browse files Browse the repository at this point in the history
  • Loading branch information
ashmeigh committed May 20, 2024
2 parents aa6025b + 63e19bc commit 25eef8b
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
19 changes: 18 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 @@ -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.utility.data_containers import FILE_TYPES #

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

# Handle 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)

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 Down Expand Up @@ -172,6 +177,18 @@ def add_nan(self, image_stack, fraction=0.001):
data.ravel()[nan_indices] = np.nan
return image_stack

def add_flats_and_darks(self, params):
for frame_type in ['Flat_Before', 'Flat_After', 'Dark_Before']:
if frame_type in params:
filename_group = FilenameGroup.from_file(config_manager.load_sample)
related_filename_group = filename_group.find_related(getattr(FILE_TYPES, frame_type.upper()))
related_filename_group.find_all_files()
image_stack = loader.load(filename_group=related_filename_group)
if image_stack is not None:
params[frame_type.lower()] = image_stack # Map to lower case for filter_func
else:
print(f"Failed to load image stack for {frame_type}")

def compare_mode(self):
for operation, test_case_info in TEST_CASES.items():
print(f"Running tests for {operation}:")
Expand Down
49 changes: 49 additions & 0 deletions scripts/operations_tests/test_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -678,5 +678,54 @@
}
}
]
},
"Flat-fielding": {
"params": {
"use_dark": true,
"selected_flat_fielding": "Both, concatenated"
},
"source_data": "flower128",
"cases": [
{
"test_name": "default_settings",
"pre_run_step": "add_flats_and_darks",
"params": {
"use_dark": true,
"selected_flat_fielding": "Both, concatenated",
"Flat_Before": "FLAT_BEFORE",
"Dark_Before": "DARK_BEFORE",
"Flat_After": "FLAT_AFTER"
}
},
{
"test_name": "use_only_before",
"pre_run_step": "add_flats_and_darks",
"params": {
"use_dark": true,
"selected_flat_fielding": "Only Before",
"Flat_Before": "FLAT_BEFORE",
"Dark_Before": "DARK_BEFORE"
}
},
{
"test_name": "use_only_after",
"pre_run_step": "add_flats_and_darks",
"params": {
"use_dark": true,
"selected_flat_fielding": "Only After",
"Flat_After": "FLAT_AFTER"
}
},
{
"test_name": "no_dark_frames",
"pre_run_step": "add_flats_and_darks",
"params": {
"use_dark": false,
"selected_flat_fielding": "Both, concatenated",
"Flat_Before": "FLAT_BEFORE",
"Flat_After": "FLAT_AFTER"
}
}
]
}
}

0 comments on commit 25eef8b

Please sign in to comment.