@@ -154,6 +154,23 @@ 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"All constant and function resolutions must have a source defined. For a "
170+ f"{ resolution .type } type resolution, the source must be defined in "
171+ f'"{ RATapi .project .values_defined_in [f"resolutions.{ resolution .type } .source" ]} "'
172+ )
173+
157174 # Set contrast parameters according to model type
158175 if project .model == LayerModels .StandardLayers :
159176 if project .calculation == Calculations .Domains :
@@ -194,9 +211,9 @@ def make_problem(project: RATapi.Project) -> ProblemDefinition:
194211 contrast_resolution_params = []
195212 contrast_resolution_types = []
196213
197- # set data, background and resolution for each contrast
214+ # Set data, background and resolution for each contrast
198215 for contrast in project .contrasts :
199- # set data
216+ # Set data
200217 data_index = project .data .index (contrast .data )
201218 data = project .data [data_index ].data
202219 data_range = project .data [data_index ].data_range
@@ -212,7 +229,7 @@ def make_problem(project: RATapi.Project) -> ProblemDefinition:
212229 else :
213230 simulation_limits .append ([0.0 , 0.0 ])
214231
215- # set background parameters
232+ # Set background parameters
216233 background = project .backgrounds [contrast .background ]
217234 contrast_background_types .append (background .type )
218235 contrast_background_param = []
@@ -221,7 +238,7 @@ def make_problem(project: RATapi.Project) -> ProblemDefinition:
221238 contrast_background_param .append (project .data .index (background .source , True ))
222239 if background .value_1 != "" :
223240 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
241+ # If we are using a data background, we add the background data to the contrast data
225242 data = append_data_background (data , project .data [background .source ].data )
226243
227244 elif background .type == TypeOptions .Function :
@@ -245,7 +262,7 @@ def make_problem(project: RATapi.Project) -> ProblemDefinition:
245262
246263 contrast_background_params .append (contrast_background_param )
247264
248- # set resolution parameters
265+ # Set resolution parameters
249266 resolution = project .resolutions [contrast .resolution ]
250267 contrast_resolution_types .append (resolution .type )
251268 contrast_resolution_param = []
@@ -270,7 +287,7 @@ def make_problem(project: RATapi.Project) -> ProblemDefinition:
270287
271288 contrast_resolution_params .append (contrast_resolution_param )
272289
273- # contrast data has exactly six columns to include background data if relevant
290+ # Contrast data has exactly six columns to include background data if relevant
274291 all_data .append (np .column_stack ((data , np .zeros ((data .shape [0 ], 6 - data .shape [1 ])))))
275292
276293 problem = ProblemDefinition ()
0 commit comments