Skip to content

Commit 03ca508

Browse files
i want to have different regs for diff obs and insts
1 parent 15be2c3 commit 03ca508

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

xga/generate/sas/spec.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,16 @@ def _spec_cmds(sources: Union[BaseSource, BaseSample], outer_radius: Union[str,
213213
outer_radii[s_ind] * source.background_radius_factors[1],
214214
'xmm', source.default_coord)
215215
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)
217226
back_inter_reg = source.regions_within_radii(Quantity(0, 'deg'), bkg_outr, 'xmm',
218227
bkg_coord)
219228
src_inn_rad_str = inner_radii[s_ind].value
@@ -268,10 +277,18 @@ def _spec_cmds(sources: Union[BaseSource, BaseSample], outer_radius: Union[str,
268277
inst, interloper_regions=back_inter_reg,
269278
central_coord=source.default_coord)
270279
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)
272289
back_inter_reg = source.regions_within_radii(Quantity(0, 'deg'), bkg_outr, 'xmm',
273290
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)
275292
b_reg = source.get_annular_sas_region(bkg_innr, bkg_outr, obs_id=obs_id, inst=inst,
276293
interloper_regions=back_inter_reg,
277294
central_coord=bkg_coord,
@@ -301,7 +318,15 @@ def _spec_cmds(sources: Union[BaseSource, BaseSample], outer_radius: Union[str,
301318
inst, interloper_regions=back_inter_reg,
302319
central_coord=source.default_coord)
303320
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)
305330
b_reg = source.get_annular_sas_region(bkg_innr, bkg_outr, obs_id=obs_id, inst=inst,
306331
interloper_regions=back_inter_reg,
307332
central_coord=bkg_coord,

0 commit comments

Comments
 (0)