@@ -213,7 +213,16 @@ def _spec_cmds(sources: Union[BaseSource, BaseSample], outer_radius: Union[str,
213
213
outer_radii [s_ind ] * source .background_radius_factors [1 ],
214
214
'xmm' , source .default_coord )
215
215
else :
216
- _ , bkg_outr , bkg_coord , _ = parse_custom_bkg_sas (custom_bkg , True )
216
+
217
+ if isinstance (custom_bkg , dict ):
218
+ try :
219
+ any_reg = next (iter (next (iter (custom_reg .values ())).values ()))
220
+ except KeyError :
221
+ raise KeyError ("If inputting a custom_bkg dictionary, it should be a nested one, with obs_id top keys and instruments on the next level." )
222
+ else :
223
+ any_reg = custom_bkg
224
+
225
+ _ , bkg_outr , bkg_coord , _ = parse_custom_bkg_sas (any_reg , True )
217
226
back_inter_reg = source .regions_within_radii (Quantity (0 , 'deg' ), bkg_outr , 'xmm' ,
218
227
bkg_coord )
219
228
src_inn_rad_str = inner_radii [s_ind ].value
@@ -268,10 +277,18 @@ def _spec_cmds(sources: Union[BaseSource, BaseSample], outer_radius: Union[str,
268
277
inst , interloper_regions = back_inter_reg ,
269
278
central_coord = source .default_coord )
270
279
else :
271
- _ , bkg_outr , bkg_coord , _ = parse_custom_bkg_sas (custom_bkg , True )
280
+ if isinstance (custom_bkg , dict ):
281
+ try :
282
+ use_custom_bkg = custom_bkg [obs_id ][inst ]
283
+ except KeyError :
284
+ raise KeyError (f"The obsID: { obs_id } and inst:{ inst } isn't in the input dictionary of custom backgrounds." )
285
+ else :
286
+ use_custom_bkg = custom_bkg
287
+
288
+ _ , bkg_outr , bkg_coord , _ = parse_custom_bkg_sas (use_custom_bkg , True )
272
289
back_inter_reg = source .regions_within_radii (Quantity (0 , 'deg' ), bkg_outr , 'xmm' ,
273
290
bkg_coord )
274
- bkg_innr , bkg_outr , bkg_coord , bkg_rot_angle = parse_custom_bkg_sas (custom_bkg )
291
+ bkg_innr , bkg_outr , bkg_coord , bkg_rot_angle = parse_custom_bkg_sas (use_custom_bkg )
275
292
b_reg = source .get_annular_sas_region (bkg_innr , bkg_outr , obs_id = obs_id , inst = inst ,
276
293
interloper_regions = back_inter_reg ,
277
294
central_coord = bkg_coord ,
@@ -301,7 +318,15 @@ def _spec_cmds(sources: Union[BaseSource, BaseSample], outer_radius: Union[str,
301
318
inst , interloper_regions = back_inter_reg ,
302
319
central_coord = source .default_coord )
303
320
else :
304
- bkg_innr , bkg_outr , bkg_coord , bkg_rot_angle = parse_custom_bkg_sas (custom_bkg )
321
+ if isinstance (custom_bkg , dict ):
322
+ try :
323
+ use_custom_bkg = custom_bkg [obs_id ][inst ]
324
+ except KeyError :
325
+ raise KeyError (f"The obsID: { obs_id } and inst:{ inst } isn't in the input dictionary of custom backgrounds." )
326
+ else :
327
+ use_custom_bkg = custom_bkg
328
+
329
+ bkg_innr , bkg_outr , bkg_coord , bkg_rot_angle = parse_custom_bkg_sas (use_custom_bkg )
305
330
b_reg = source .get_annular_sas_region (bkg_innr , bkg_outr , obs_id = obs_id , inst = inst ,
306
331
interloper_regions = back_inter_reg ,
307
332
central_coord = bkg_coord ,
0 commit comments