Lv1_swift_filter.py
def filtering(eventlist,regtype,instructfile):
    """
    Filtering the original event file based on the defined region files from DS9

    eventlist - list of event files
    regtype - type of region (e.g., for NGC 300, there's ngc300ulx1, ngc300x1, ngc300bg)
    instructfile - where to save the instructions file
    """
    if type(eventlist) != np.array and type(eventlist) != list:
        raise TypeError('eventlist should either be an array or a list!')

    instruct = open(instructfile,'w')

    instruct.write('set mission swift' + '\n')
    instruct.write('set inst xrt' + '\n')

    for i in range(len(eventlist)):
        parent_folder = str(pathlib.Path(eventlist[i]).parent)
        filename = str(pathlib.Path(eventlist[i]).name)

        instruct.write('set datadir ' + parent_folder + '/' + '\n')

        for j in range(len(regtype)):
            instruct.write('read event ' + filename + '\n')
            instruct.write('filter region ' + parent_folder + '/' + regtype[j] + '.reg' + '\n') #generalize this later!!! Maybe use a list
            instruct.write('extract spectrum' + '\n')
            instruct.write('save spectrum ' + parent_folder + '/' + regtype[j] + '/' + filename[:-4] + '_' + regtype[j] + '.pha' + '\n')
            instruct.write('extract event' + '\n')
            instruct.write('save event ' + parent_folder + '/' + regtype[j] + '/' + filename[:-4] + '_' + regtype[j] + '.evt' + '\n')
            instruct.write('no' + '\n')
            instruct.write('clear region' + '\n')
            instruct.write('clear data' + '\n')

        instruct.write('\n')

    instruct.close()

    Filtering the original event file based on the defined region files from DS9

    eventlist - list of event files
    regtype - type of region (e.g., for NGC 300, there's ngc300ulx1, ngc300x1, ngc300bg)
    instructfile - where to save the instructions file
    
Filtering the original event file based on the defined region files from DS9
eventlist - list of event files
regtype - type of region
instructfile - where to save the instructions file
Filtering the original event file based on the defined region files from DS9 eventlist - list of event files regtype - type of region instructfile - where to save the instructions file
def filtering(eventlist,regtype,instructfile):
    if type(eventlist) != np.array and type(eventlist) != list:
        raise TypeError('eventlist should either be an array or a list!')
    instruct = open(instructfile,'w')
    instruct.write('set mission swift' + '\n')
    instruct.write('set inst xrt' + '\n')
    for i in range(len(eventlist)):
        parent_folder = str(pathlib.Path(eventlist[i]).parent)
        filename = str(pathlib.Path(eventlist[i]).name)
        instruct.write('set datadir ' + parent_folder + '/' + '\n')
        for j in range(len(regtype)):
            instruct.write('read event ' + filename + '\n')
            instruct.write('filter region ' + parent_folder + '/' + regtype[j] + '.reg' + '\n') 
            instruct.write('extract spectrum' + '\n')
            instruct.write('save spectrum ' + parent_folder + '/' + regtype[j] + '/' + filename[:-4] + '_' + regtype[j] + '.pha' + '\n')
            instruct.write('extract event' + '\n')
            instruct.write('save event ' + parent_folder + '/' + regtype[j] + '/' + filename[:-4] + '_' + regtype[j] + '.evt' + '\n')
            instruct.write('no' + '\n')
            instruct.write('clear region' + '\n')
            instruct.write('clear data' + '\n')
        instruct.write('\n')
    instruct.close()
def filtering ( eventlist , regtype , instructfile ) : if type ( eventlist ) != np . array and type ( eventlist ) != list : raise TypeError ( 'eventlist should either be an array or a list!' ) instruct = open ( instructfile , 'w' ) instruct . write ( 'set mission swift' + '\n' ) instruct . write ( 'set inst xrt' + '\n' ) for i in range ( len ( eventlist ) ) : parent_folder = str ( pathlib . Path ( eventlist [ i ] ) . parent ) filename = str ( pathlib . Path ( eventlist [ i ] ) . name ) instruct . write ( 'set datadir ' + parent_folder + '/' + '\n' ) for j in range ( len ( regtype ) ) : instruct . write ( 'read event ' + filename + '\n' ) instruct . write ( 'filter region ' + parent_folder + '/' + regtype [ j ] + '.reg' + '\n' ) instruct . write ( 'extract spectrum' + '\n' ) instruct . write ( 'save spectrum ' + parent_folder + '/' + regtype [ j ] + '/' + filename [ : - 4 ] + '_' + regtype [ j ] + '.pha' + '\n' ) instruct . write ( 'extract event' + '\n' ) instruct . write ( 'save event ' + parent_folder + '/' + regtype [ j ] + '/' + filename [ : - 4 ] + '_' + regtype [ j ] + '.evt' + '\n' ) instruct . write ( 'no' + '\n' ) instruct . write ( 'clear region' + '\n' ) instruct . write ( 'clear data' + '\n' ) instruct . write ( '\n' ) instruct . close ( )
Filtering the original event file based on the defined region files from DS9
eventlist - list of event files
regtype - type of region (e.g., for NGC 300, there's ngc300ulx1, ngc300x1, ngc300bg)
instructfile - where to save the instructions file
Filtering the original event file based on the defined region files from DS9 eventlist - list of event files regtype - type of region ( e . g . for NGC 300 there ' s ngc300ulx1 ngc300x1 ngc300bg ) instructfile - where to save the instructions file
"""
    Filtering the original event file based on the defined region files from DS9

    eventlist - list of event files
    regtype - type of region (e.g., for NGC 300, there's ngc300ulx1, ngc300x1, ngc300bg)
    instructfile - where to save the instructions file
    """ #generalize this later!!! Maybe use a list
eventlist
regtype
instructfile