Lv1_data_gtis.py
def GTI_bunching(eventfile,gap,gtifile):
    """
    To bunch up GTIs which are separated by less than a few seconds apart.

    eventfile - path to the event file. Will extract ObsID from this for the NICER files.
    gap - maximum separation between end time of 1st GTI and start time of 2nd GTI allowed
    gtifile - name of GTI file
    """
    parent_folder = str(pathlib.Path(eventfile).parent)
    gtifile_path = parent_folder + '/' + gtifile
    gtis = list(fits.open(eventfile)[2].data)
    N = len(gtis)

    should_restart = True
    while should_restart: #to restart the for loop if I reached a pair of GTIs that can be combined
        should_restart = False
        for i in range(N-1): #variable N is there as we need to UPDATE the length of the GTIs each time we delete one!
            if (gtis[i+1][0]-gtis[i][1]) <= gap: #if (start time of next GTI - end time of previous GTI) is less than 5s, say
                new_start = gtis[i][0] #defined here, because "i" will change after deleting the 2 previous GTIs!
                new_end = gtis[i+1][1]
                del gtis[i]
                del gtis[i] #use the SAME index since the list after the first deletion will have N-1 items!
                gtis.insert(i,(new_start,new_end))
                N = len(gtis)
                should_restart = True
                break
            else:
                N = len(gtis)
                continue

    gtitxt = open(parent_folder + '/bunchedgtis.txt','w')
    for i in range(len(gtis)):
        gtitxt.write(str(gtis[i][0]) + ' ' + str(gtis[i][1]) + '\n')
    gtitxt.close()

    gti_col_file = Lv0_dirs.NICER_DATADIR + 'gti_columns.txt'
    gti_header_file = Lv0_dirs.NICER_DATADIR + 'gti_header.txt'
    ftcreate_cmd = ['ftcreate',gti_col_file,parent_folder+'/bunchedgtis.txt',gtifile_path,'headfile='+gti_header_file,'extname="GTI"','clobber=yes']
    subprocess.run(ftcreate_cmd)

    To bunch up GTIs which are separated by less than a few seconds apart.

    eventfile - path to the event file. Will extract ObsID from this for the NICER files.
    gap - maximum separation between end time of 1st GTI and start time of 2nd GTI allowed
    gtifile - name of GTI file
    
To bunch up GTIs which are separated by less than a few seconds apart.
eventfile - path to the event file. Will extract ObsID from this for the NICER files.
gap - maximum separation between end time of 1st GTI and start time of 2nd GTI allowed
gtifile - name of GTI file
To bunch up GTIs which are separated by less than a few seconds apart . eventfile - path to the event file . Will extract ObsID from this for the NICER files . gap - maximum separation between end time of 1st GTI and start time of 2nd GTI allowed gtifile - name of GTI file
def GTI_bunching(eventfile,gap,gtifile):
    parent_folder = str(pathlib.Path(eventfile).parent)
    gtifile_path = parent_folder + '/' + gtifile
    gtis = list(fits.open(eventfile)[2].data)
    N = len(gtis)
    should_restart = True
    while should_restart: 
        should_restart = False
        for i in range(N-1): 
            if (gtis[i+1][0]-gtis[i][1]) <= gap: 
                new_start = gtis[i][0] 
                new_end = gtis[i+1][1]
                del gtis[i]
                del gtis[i] 
                gtis.insert(i,(new_start,new_end))
                N = len(gtis)
                should_restart = True
                break
            else:
                N = len(gtis)
                continue
    gtitxt = open(parent_folder + '/bunchedgtis.txt','w')
    for i in range(len(gtis)):
        gtitxt.write(str(gtis[i][0]) + ' ' + str(gtis[i][1]) + '\n')
    gtitxt.close()
    gti_col_file = Lv0_dirs.NICER_DATADIR + 'gti_columns.txt'
    gti_header_file = Lv0_dirs.NICER_DATADIR + 'gti_header.txt'
    ftcreate_cmd = ['ftcreate',gti_col_file,parent_folder+'/bunchedgtis.txt',gtifile_path,'headfile='+gti_header_file,'extname="GTI"','clobber=yes']
    subprocess.run(ftcreate_cmd)
def GTI_bunching ( eventfile , gap , gtifile ) : parent_folder = str ( pathlib . Path ( eventfile ) . parent ) gtifile_path = parent_folder + '/' + gtifile gtis = list ( fits . open ( eventfile ) [ 2 ] . data ) N = len ( gtis ) should_restart = True while should_restart : should_restart = False for i in range ( N - 1 ) : if ( gtis [ i + 1 ] [ 0 ] - gtis [ i ] [ 1 ] ) <= gap : new_start = gtis [ i ] [ 0 ] new_end = gtis [ i + 1 ] [ 1 ] del gtis [ i ] del gtis [ i ] gtis . insert ( i , ( new_start , new_end ) ) N = len ( gtis ) should_restart = True break else : N = len ( gtis ) continue gtitxt = open ( parent_folder + '/bunchedgtis.txt' , 'w' ) for i in range ( len ( gtis ) ) : gtitxt . write ( str ( gtis [ i ] [ 0 ] ) + ' ' + str ( gtis [ i ] [ 1 ] ) + '\n' ) gtitxt . close ( ) gti_col_file = Lv0_dirs . NICER_DATADIR + 'gti_columns.txt' gti_header_file = Lv0_dirs . NICER_DATADIR + 'gti_header.txt' ftcreate_cmd = [ 'ftcreate' , gti_col_file , parent_folder + '/bunchedgtis.txt' , gtifile_path , 'headfile=' + gti_header_file , 'extname="GTI"' , 'clobber=yes' ] subprocess . run ( ftcreate_cmd )
To bunch up GTIs which are separated by less than a few seconds apart.
To bunch up GTIs which are separated by less than a few seconds apart .
"""
    To bunch up GTIs which are separated by less than a few seconds apart.

    eventfile - path to the event file. Will extract ObsID from this for the NICER files.
    gap - maximum separation between end time of 1st GTI and start time of 2nd GTI allowed
    gtifile - name of GTI file
    """ #to restart the for loop if I reached a pair of GTIs that can be combined #variable N is there as we need to UPDATE the length of the GTIs each time we delete one! #if (start time of next GTI - end time of previous GTI) is less than 5s, say #defined here, because "i" will change after deleting the 2 previous GTIs! #use the SAME index since the list after the first deletion will have N-1 items!
eventfile
gap
gtifile