Skip to content

Commit 081e7e2

Browse files
committed
Fix bug with data backgrounds validation
1 parent 81aaab6 commit 081e7e2

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

ratapi/inputs.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,10 @@ def make_problem(project: ratapi.Project) -> ProblemDefinition:
243243
contrast_background_param = []
244244

245245
if background.type == TypeOptions.Data:
246-
contrast_background_param.append(project.data.index(background.source, True))
246+
# Background data is appended to contrast data so empty index
247+
contrast_background_param.append(np.array([]))
247248
if background.value_1 != "":
248-
contrast_background_param.append(project.background_parameters.index(background.value_1))
249+
contrast_background_param[-1] = project.background_parameters.index(background.value_1)
249250
# If we are using a data background, we add the background data to the contrast data
250251
data = append_data_background(data, project.data[background.source].data)
251252

@@ -492,7 +493,7 @@ def check_indices(problem: ProblemDefinition) -> None:
492493

493494
source_param_lists = {
494495
"constant": "backgroundParams",
495-
"data": "data",
496+
"data": "backgroundParams",
496497
"function": "customFiles",
497498
}
498499

@@ -501,11 +502,13 @@ def check_indices(problem: ProblemDefinition) -> None:
501502

502503
# check source param is in range of the relevant parameter list
503504
param_list = getattr(problem, source_param_lists[background_type])
504-
source_index = background_data[0]
505-
if not 0 < source_index <= len(param_list):
505+
# For data, background data is appended to the contrast data so first index could
506+
# either be empty or be the index of an offset.
507+
first_index = background_data[0]
508+
if np.size(first_index) > 0 and not 0 < first_index <= len(param_list):
506509
raise IndexError(
507510
f'Entry {i} of contrastBackgroundParams has type "{background_type}" '
508-
f"and source index {source_index}, "
511+
f"and source index {first_index}, "
509512
f'which is outside the range of "{source_param_lists[background_type]}".'
510513
)
511514

tests/test_inputs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ def test_background_params_source_indices(self, test_problem, background_type, b
537537

538538
source_param_lists = {
539539
"constant": "backgroundParams",
540-
"data": "data",
540+
"data": "backgroundParams",
541541
"function": "customFiles",
542542
}
543543

0 commit comments

Comments
 (0)