11# This code is a part of X-ray: Generate and Analyse (XGA), a module designed for the XMM Cluster Survey (XCS).
2- # Last modified by David J Turner (djturner@umbc.edu) 10/12/2025, 10:56 . Copyright (c) The Contributors
2+ # Last modified by David J Turner (djturner@umbc.edu) 10/12/2025, 21:11 . Copyright (c) The Contributors
33
44import os
55from copy import deepcopy , copy
@@ -103,6 +103,12 @@ def _make_spec_cmd_info(cur_evt_list: EventList):
103103 # Extracting just the instrument number for later use in eSASS commands (or indeed a list of instrument
104104 # numbers if the user has requested a combined spectrum).
105105 inst_no = inst_nums [inst_ind ]
106+ # Also pick out the current instrument srctool ID - this will be passed
107+ # to the writeinsts argument of srctool. It will be identical to 'inst_no'
108+ # for individual telescope module spectra, and will be zero (to write a
109+ # combined spectrum of all specified TMs) for combined telescope
110+ # module spectra.
111+ cur_inst_srctool_id = inst_srctool_id [inst_ind ]
106112
107113 try :
108114 if use_combine_obs and (len (source .obs_ids [cur_evt_list .telescope ]) > 1 ):
@@ -280,6 +286,7 @@ def _make_spec_cmd_info(cur_evt_list: EventList):
280286 sc = coord_str ,
281287 reg = reg ,
282288 i = inst_no ,
289+ wi = cur_inst_srctool_id ,
283290 ts = t_step ,
284291 em = os .path .basename (im .path ),
285292 et = ext_type )
@@ -291,13 +298,15 @@ def _make_spec_cmd_info(cur_evt_list: EventList):
291298 sc = coord_str ,
292299 reg = reg ,
293300 i = inst_no ,
301+ wi = cur_inst_srctool_id ,
294302 ts = t_step )
295303
296304 # TODO FIGURE OUT WHAT TO DO ABOUT THE TIMESTEP
297305 sb_cmd_str = back_sp_cmd .format (ef = os .path .basename (cur_evt_list .path ),
298306 sc = coord_str ,
299307 breg = b_reg ,
300308 i = inst_no ,
309+ wi = cur_inst_srctool_id ,
301310 ts = t_step * 4 )
302311 # Filling out the grouping command
303312 grp_cmd_str = grp_cmd .format (infi = no_grp_spec ,
@@ -337,28 +346,21 @@ def _make_spec_cmd_info(cur_evt_list: EventList):
337346 # We make sure to remove the 'merged spectra' output of srctool - which is identical to the
338347 # instrument one if we generate for one spectrum at a time. Though only if the user hasn't actually
339348 # ASKED for the merged spectrum
340- print ('TM combo' , combine_tm )
341-
342349 if combine_tm :
343- # cmd_str = ";".join([s_cmd_str, rename_spec, rename_rmf, rename_arf, remove_all_but_merged_cmd])
344- cmd_str = ";" .join ([s_cmd_str , rename_spec , rename_rmf , rename_arf ])
350+ cmd_str = ";" .join ([s_cmd_str , rename_spec , rename_rmf , rename_arf , remove_all_but_merged_cmd ])
345351 else :
346- # cmd_str = ";".join([s_cmd_str, rename_spec, rename_rmf, rename_arf, remove_merged_cmd])
347- cmd_str = ";" .join ([s_cmd_str , rename_spec , rename_rmf , rename_arf ])
352+ cmd_str = ";" .join ([s_cmd_str , rename_spec , rename_rmf , rename_arf , remove_merged_cmd ])
348353
349354 # This currently ensures that there is a ';' divider between these two chunks of commands - hopefully
350355 # we'll neaten it up at some point
351356 cmd_str += ';'
352357
353358 # Removing the 'merged spectra' output of srctool, for the background spectra in this case
354359 if combine_tm :
355- # cmd_str += ";".join([sb_cmd_str, rename_b_spec, rename_b_rmf, rename_b_arf,
356- # remove_all_but_merged_cmd])
357360 cmd_str += ";" .join ([sb_cmd_str , rename_b_spec , rename_b_rmf , rename_b_arf ,
358- ])
361+ remove_all_but_merged_cmd ])
359362 else :
360- # cmd_str += ";".join([sb_cmd_str, rename_b_spec, rename_b_rmf, rename_b_arf, remove_merged_cmd])
361- cmd_str += ";" .join ([sb_cmd_str , rename_b_spec , rename_b_rmf , rename_b_arf ])
363+ cmd_str += ";" .join ([sb_cmd_str , rename_b_spec , rename_b_rmf , rename_b_arf , remove_merged_cmd ])
362364
363365 # If the user wants to group the spectrum, then this command should be added
364366 if group_spec :
@@ -370,13 +372,13 @@ def _make_spec_cmd_info(cur_evt_list: EventList):
370372
371373 # Adds symlink-removal commands - we don't want to be moving them along
372374 # with every else in the temporary working directory
373- # cmd_str += "; rm {esym}".format(esym=evt_symlink_name)
374- # # Image symlink will only be present if the source is extended
375- # if extended_src:
376- # cmd_str += "; rm {esym}".format(esym=im_symlink_name)
375+ cmd_str += "; rm {esym}" .format (esym = evt_symlink_name )
376+ # Image symlink will only be present if the source is extended
377+ if extended_src :
378+ cmd_str += "; rm {esym}" .format (esym = im_symlink_name )
377379
378380 # Adds clean up commands to move all generated files and remove the temporary directory
379- # cmd_str += "; mv * ../; cd ..; rm -r {d}".format(d=dest_dir)
381+ cmd_str += "; mv * ../; cd ..; rm -r {d}" .format (d = dest_dir )
380382 # If temporary region files were made, they will be here
381383 if os .path .exists (final_dest_dir + '/temp_regs_{i}' .format (i = rand_ident )):
382384 # Removing this directory
@@ -506,9 +508,9 @@ def _make_spec_cmd_info(cur_evt_list: EventList):
506508 # which instruments should be written to output files - we want to be able to
507509 # set that to avoid some warnings that clog up the logs
508510 if ESASS_VERSION == "ESASS4DR1" :
509- ext_sp_cmd += " writeinsts={i }"
510- back_sp_cmd += " writeinsts={i }"
511- pnt_sp_cmd += " writeinsts={i }"
511+ ext_sp_cmd += " writeinsts={wi }"
512+ back_sp_cmd += " writeinsts={wi }"
513+ pnt_sp_cmd += " writeinsts={wi }"
512514
513515 # TODO SORT THIS SHIT OUT?!
514516 # You can't control the whole names of srctool outputs, so this renames it to the XGA format
0 commit comments