Skip to content

Events from SIXTE

events_management

create_count_map(final_evt_file, image_file, ra=0.0, dec=0.0, count_map_shape=(58, 58), xifu_config=XIFU_Config())

Create a count map using the imgev function from SIXTE.

Parameters:

Name Type Description Default
final_evt_file str

Path to event file from which to make the count map

required
image_file str

Path and name of count map

required
ra float

Right ascension of pointing represented

0.0
dec float

Declination of the pointing represented

0.0
count_map_shape tuple

Shape of the count map (default for one X-IFU pointing is 58x58)

(58, 58)
xifu_config XIFU_Config

X-IFU Configuration instance

XIFU_Config()
Source code in src/xifu_cluster_sim/events_management.py
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
def create_count_map(final_evt_file,
                    image_file,
                    ra =0.,
                    dec = 0.,
                    count_map_shape = (58,58),
                    xifu_config = XIFU_Config()):
    """
    Create a count map using the imgev function from SIXTE.

    Parameters:
        final_evt_file (str): Path to event file from which to make the count map
        image_file (str): Path and name of count map
        ra (float): Right ascension of pointing represented
        dec (float): Declination of the pointing represented
        count_map_shape (tuple): Shape of the count map (default for one X-IFU pointing is 58x58)
        xifu_config (XIFU_Config): X-IFU Configuration instance

    """

    pixsize_degree = xifu_config.pixsize_arcsec.to(units.degree).value

    subprocess.check_call(["imgev",
                            "EvtFile="+final_evt_file,
                            "Image="+image_file,
                            "NAXIS1={}".format(count_map_shape[0]),
                            "NAXIS2={}".format(count_map_shape[1]),
                            "CRVAL1={}".format(ra),
                            "CRVAL2={}".format(dec),
                           "CRPIX1={}".format(int(count_map_shape[0]/2)),
                           "CRPIX2={}".format(int(count_map_shape[1]/2)),
                           "CDELT1=-%.15f" %(pixsize_degree),
                           "CDELT2=%.15f" %(pixsize_degree),
                           "CoordinateSystem=0",
                           "Projection=TAN",
                           "CUNIT1=deg",
                           "CUNIT2=deg"])

merge_evt_files_recursive(output_file, pattern, clobber=False, file_list=None, depth=0)

Merges different event files matching a given pattern recursively. This is needed when running multiple SIXTE processes in parallel, in order to merge the output event files.

Parameters:

Name Type Description Default
output_file str

name of the final event list to write

required
pattern str

pattern to find the event files to merge (e.g. "/sixte_files/part[0-9]/events_[0-9].fits")

required
clobber bool

standard FITS clobber option

False
file_list list

list of files to merge (for recursive calls)

None
depth int

depth of recursive call

0
Source code in src/xifu_cluster_sim/events_management.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def merge_evt_files_recursive(output_file,
                            pattern,
                            clobber = False,
                            file_list = None,
                            depth=0):
    '''
    Merges different event files matching a given pattern recursively.
    This is needed when running multiple SIXTE processes in parallel, 
    in order to merge the output event files.


    Parameters:
        output_file (str): name of the final event list to write
        pattern (str): pattern to find the event files to merge (e.g. "/sixte_files/part[0-9]*/events_[0-9]*.fits")
        clobber (bool): standard FITS clobber option
        file_list (list): list of files to merge (for recursive calls)
        depth (int): depth of recursive call
    '''        

    if file_list==None:
        file_list = glob(pattern)

    if os.path.exists(output_file):
        if not clobber : 
            raise RuntimeError("File %s already exists!" % output_file)

    nb_files = len(file_list)
    if nb_files==1:
        os.system("cp -r " + file_list[0] + " " + output_file)
    else:
        if nb_files>3:
            outfile1 = os.path.dirname(output_file)+'/tmp_evt_%d_0.fits' % depth
            merge_evt_files_recursive(outfile1,'',clobber=True,file_list=file_list[:int(nb_files/2)],depth=depth+1)
            outfile2 = os.path.dirname(output_file)+'/tmp_evt_%d_1.fits' % depth
            merge_evt_files_recursive(outfile2,'',clobber=True,file_list=file_list[int(nb_files/2):],depth=depth+1)
            print('Merging',outfile1,outfile2)
            os.system("fmerge \"%s %s\" %s \" \" clobber=yes" % (outfile1,outfile2,output_file))
        elif nb_files>0:
            print("Merging",file_list[0],file_list[1])
            os.system("fmerge \"%s %s\" %s \" \" clobber=yes" % (file_list[0],file_list[1],output_file))
            for evt_file in file_list[2:]:
                print('Merging',output_file,evt_file)
                os.system("fmerge \"%s %s\" %s \" \" clobber=yes" % (output_file,evt_file,output_file))
        if depth==0:
            for tmp_file in glob(os.path.dirname(output_file)+"/tmp_evt_*_*.fits"):
                os.remove(tmp_file)

    if os.path.exists(output_file):
        # Copy std GTI extension into final file
        hdu_evt = fits.open(output_file)
        hdu_evt0 = fits.open(file_list[0])
        hdu_evt.append(hdu_evt0['STDGTI'])
        hdu_evt.writeto(output_file, overwrite=True)
        hdu_evt.close()