@@ -154,6 +154,22 @@ def make_problem(project: RATapi.Project) -> ProblemDefinition:
154154 hydrate_id = {"bulk in" : 1 , "bulk out" : 2 }
155155 prior_id = {"uniform" : 1 , "gaussian" : 2 , "jeffreys" : 3 }
156156
157+ # Ensure backgrounds and resolutions have a source defined
158+ for contrast in project .contrasts :
159+ background = project .backgrounds [contrast .background ]
160+ resolution = project .resolutions [contrast .resolution ]
161+ if background .source == "" :
162+ raise ValueError (
163+ f"All backgrounds must have a source defined. For a { background .type } type background, "
164+ f"the source must be defined in "
165+ f'"{ RATapi .project .values_defined_in [f"backgrounds.{ background .type } .source" ]} "'
166+ )
167+ if resolution .source == "" and resolution .type != TypeOptions .Data :
168+ raise ValueError (
169+ f"Constant resolutions must have a source defined. The source must be defined in "
170+ f'"{ RATapi .project .values_defined_in [f"resolutions.{ resolution .type } .source" ]} "'
171+ )
172+
157173 # Set contrast parameters according to model type
158174 if project .model == LayerModels .StandardLayers :
159175 if project .calculation == Calculations .Domains :
@@ -194,9 +210,9 @@ def make_problem(project: RATapi.Project) -> ProblemDefinition:
194210 contrast_resolution_params = []
195211 contrast_resolution_types = []
196212
197- # set data, background and resolution for each contrast
213+ # Set data, background and resolution for each contrast
198214 for contrast in project .contrasts :
199- # set data
215+ # Set data
200216 data_index = project .data .index (contrast .data )
201217 data = project .data [data_index ].data
202218 data_range = project .data [data_index ].data_range
@@ -212,7 +228,7 @@ def make_problem(project: RATapi.Project) -> ProblemDefinition:
212228 else :
213229 simulation_limits .append ([0.0 , 0.0 ])
214230
215- # set background parameters
231+ # Set background parameters
216232 background = project .backgrounds [contrast .background ]
217233 contrast_background_types .append (background .type )
218234 contrast_background_param = []
@@ -221,7 +237,7 @@ def make_problem(project: RATapi.Project) -> ProblemDefinition:
221237 contrast_background_param .append (project .data .index (background .source , True ))
222238 if background .value_1 != "" :
223239 contrast_background_param .append (project .background_parameters .index (background .value_1 ))
224- # if we are using a data background, we add the background data to the contrast data
240+ # If we are using a data background, we add the background data to the contrast data
225241 data = append_data_background (data , project .data [background .source ].data )
226242
227243 elif background .type == TypeOptions .Function :
@@ -245,7 +261,7 @@ def make_problem(project: RATapi.Project) -> ProblemDefinition:
245261
246262 contrast_background_params .append (contrast_background_param )
247263
248- # set resolution parameters
264+ # Set resolution parameters
249265 resolution = project .resolutions [contrast .resolution ]
250266 contrast_resolution_types .append (resolution .type )
251267 contrast_resolution_param = []
@@ -270,7 +286,7 @@ def make_problem(project: RATapi.Project) -> ProblemDefinition:
270286
271287 contrast_resolution_params .append (contrast_resolution_param )
272288
273- # contrast data has exactly six columns to include background data if relevant
289+ # Contrast data has exactly six columns to include background data if relevant
274290 all_data .append (np .column_stack ((data , np .zeros ((data .shape [0 ], 6 - data .shape [1 ])))))
275291
276292 problem = ProblemDefinition ()
0 commit comments