Skip to content

Commit 8443c12

Browse files
committed
Address review comment
1 parent 081e7e2 commit 8443c12

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

ratapi/inputs.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,8 @@ def make_problem(project: ratapi.Project) -> ProblemDefinition:
244244

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

@@ -504,11 +503,11 @@ def check_indices(problem: ProblemDefinition) -> None:
504503
param_list = getattr(problem, source_param_lists[background_type])
505504
# For data, background data is appended to the contrast data so first index could
506505
# 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):
506+
if background_data and not 0 < background_data[0] <= len(param_list):
507+
first_entry_name = "data offset" if background_type == "data" else "source"
509508
raise IndexError(
510509
f'Entry {i} of contrastBackgroundParams has type "{background_type}" '
511-
f"and source index {first_index}, "
510+
f"and {first_entry_name} index {background_data[0]}, "
512511
f'which is outside the range of "{source_param_lists[background_type]}".'
513512
)
514513

tests/test_inputs.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,17 +534,18 @@ def test_background_params_source_indices(self, test_problem, background_type, b
534534
test_problem = request.getfixturevalue(test_problem)
535535
test_problem.contrastBackgroundParams = bad_value
536536
test_problem.contrastBackgroundTypes = [background_type]
537-
538537
source_param_lists = {
539538
"constant": "backgroundParams",
540539
"data": "backgroundParams",
541540
"function": "customFiles",
542541
}
543542

543+
first_entry_name = "data offset" if background_type == "data" else "source"
544+
544545
with pytest.raises(
545546
IndexError,
546547
match=f'Entry 0 of contrastBackgroundParams has type "{background_type}" '
547-
f"and source index {bad_value[0][0]}, "
548+
f"and {first_entry_name} index {bad_value[0][0]}, "
548549
f'which is outside the range of "{source_param_lists[background_type]}".',
549550
):
550551
check_indices(test_problem)

0 commit comments

Comments
 (0)