Skip to content

Commit 7219422

Browse files
author
David Turner
committed
Added symlink clean up commands to the eROSITA spectral generation command stacks.
1 parent 7b17ba4 commit 7219422

1 file changed

Lines changed: 26 additions & 17 deletions

File tree

xga/generate/esass/spec.py

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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 (turne540@msu.edu) 09/12/2025, 15:01. Copyright (c) The Contributors
2+
# Last modified by David J Turner (turne540@msu.edu) 09/12/2025, 15:07. Copyright (c) The Contributors
33

44
import os
55
from copy import deepcopy, copy
@@ -156,7 +156,8 @@ def _make_spec_cmd_info(cur_evt_list: EventList):
156156
os.makedirs(dest_dir, exist_ok=True)
157157
# The temporary directory will now have a symlink to the relevant event list, with the symlink name
158158
# the same as the actual event list
159-
os.symlink(cur_evt_list.path, os.path.join(dest_dir, os.path.basename(cur_evt_list.path)))
159+
evt_symlink_name = os.path.basename(cur_evt_list.path)
160+
os.symlink(cur_evt_list.path, os.path.join(dest_dir, evt_symlink_name))
160161

161162
# This constructs the eSASS strings/region files
162163
reg = get_annular_esass_region(source,
@@ -270,7 +271,8 @@ def _make_spec_cmd_info(cur_evt_list: EventList):
270271
# As with the paths to the event lists, it is possible that the image
271272
# file names will be too long for eSASS' srctool to handle. To
272273
# mitigate the potential problem, we make another symlink
273-
os.symlink(im.path, os.path.join(dest_dir, os.path.basename(im.path)))
274+
im_symlink_name = os.path.basename(im.path)
275+
os.symlink(im.path, os.path.join(dest_dir, im_symlink_name))
274276

275277
# Fill out the spectrum generation (srctool) command specific to extended sources
276278
s_cmd_str = ext_sp_cmd.format(d=dest_dir,
@@ -340,13 +342,13 @@ def _make_spec_cmd_info(cur_evt_list: EventList):
340342
else:
341343
cmd_str = ";".join([s_cmd_str, rename_spec, rename_rmf, rename_arf, remove_merged_cmd])
342344
# Add handling for DR1 produced merged files
343-
if ESASS_VERSION == "ESASS4DR1":
344-
# Remove "TM9" output if the instrument number is 5 or 7
345-
if inst_no in ['5', '7']:
346-
cmd_str += f";{remove_merged_dr1_9}"
347-
else:
348-
# Remove "TM8" output otherwise
349-
cmd_str += f";{remove_merged_dr1_8}"
345+
# if ESASS_VERSION == "ESASS4DR1":
346+
# # Remove "TM9" output if the instrument number is 5 or 7
347+
# if inst_no in ['5', '7']:
348+
# cmd_str += f";{remove_merged_dr1_9}"
349+
# else:
350+
# # Remove "TM8" output otherwise
351+
# cmd_str += f";{remove_merged_dr1_8}"
350352

351353
# This currently ensures that there is a ';' divider between these two chunks of commands - hopefully
352354
# we'll neaten it up at some point
@@ -359,13 +361,13 @@ def _make_spec_cmd_info(cur_evt_list: EventList):
359361
else:
360362
cmd_str += ";".join([sb_cmd_str, rename_b_spec, rename_b_rmf, rename_b_arf, remove_merged_cmd])
361363
# Add handling for DR1 produced merged files
362-
if ESASS_VERSION == "ESASS4DR1":
363-
# Remove "TM9" output if the instrument number is 5 or 7
364-
if inst_no in ['5', '7']:
365-
cmd_str += f";{remove_merged_dr1_9}"
366-
else:
367-
# Remove "TM8" output otherwise
368-
cmd_str += f";{remove_merged_dr1_8}"
364+
# if ESASS_VERSION == "ESASS4DR1":
365+
# # Remove "TM9" output if the instrument number is 5 or 7
366+
# if inst_no in ['5', '7']:
367+
# cmd_str += f";{remove_merged_dr1_9}"
368+
# else:
369+
# # Remove "TM8" output otherwise
370+
# cmd_str += f";{remove_merged_dr1_8}"
369371

370372
# If the user wants to group the spectrum then this command should be added
371373
if group_spec:
@@ -375,6 +377,13 @@ def _make_spec_cmd_info(cur_evt_list: EventList):
375377
# no grouping applied.
376378
cmd_str += "; " + grp_cmd_str
377379

380+
# Adds symlink-removal commands - we don't want to be moving them along
381+
# with every else in the temporary working directory
382+
cmd_str += "; rm {esym}".format(esym=evt_symlink_name)
383+
# Image symlink will only be present if the source is extended
384+
if extended_src:
385+
cmd_str += "; rm {esym}".format(esym=im_symlink_name)
386+
378387
# Adds clean up commands to move all generated files and remove the temporary directory
379388
cmd_str += "; mv * ../; cd ..; rm -r {d}".format(d=dest_dir)
380389
# If temporary region files were made, they will be here

0 commit comments

Comments
 (0)