Lv2_merging_events.py
def merging(obsids,merged_id):
    """
    Given a list of ObsIDs, create a file which merges all the rows in the EVENTS
    extension of the FITS files!
    Updated 8/14/2020: Use a list of event files given in a text file!

    obsids - list (or array) of ObsIDs
    merged_id - 6-digit ID for the merged event file
    """
    if type(obsids) != list and type(obsids) != np.ndarray:
        raise TypeError("obsids should either be a list or an array!")
    if type(merged_id) != str or len(merged_id) != 6:
        raise TypeError("merged_id should be a string and have 6 digits in the string!")

    all_merged_dir = Lv0_dirs.NICERSOFT_DATADIR + 'merged_events/'
    merged_dir = all_merged_dir + 'merged' + merged_id + '/'
    Lv2_mkdir.makedir(merged_dir)

    filelist = np.array([Lv0_dirs.NICERSOFT_DATADIR + str(obsids[i]) + '_pipe/ni' + str(obsids[i]) + '_nicersoft_bary.evt' for i in range(len(obsids))])
    int_text = open(merged_dir+'filelist.txt','w')
    for i in range(len(filelist)): #writing the paths to each file in filelist
        int_text.write(filelist[i] + '\n')
    int_text.close()

    subprocess.run(['ftmerge','@'+merged_dir+'filelist.txt',merged_dir+'intermediate.evt'])

    gti_filelist = np.array([Lv0_dirs.NICERSOFT_DATADIR + str(obsids[i]) + '_pipe/ni' + str(obsids[i]) + '_nicersoft_bary.evt[GTI]' for i in range(1,len(obsids))])
    final_text = open(merged_dir+'filelist_gti.txt','w') #list of files with the GTI extension referenced
    final_text.write(merged_dir+'intermediate.evt[GTI]'+'\n')
    for i in range(len(gti_filelist)):
        final_text.write(gti_filelist[i] + '\n')
    final_text.close()

    merged_file = merged_dir+'merged'+merged_id+'_nicersoft_bary.evt'
    subprocess.run(['ftmerge','@'+merged_dir+'filelist_gti.txt',merged_file,'clobber=YES'])
    subprocess.run(['rm','-r',merged_dir+'intermediate.evt'])

    merged_gtis = fits.open(merged_file)[2].data
    gti_sum = sum(np.array([merged_gtis[i][1]-merged_gtis[i][0] for i in range(len(merged_gtis))]))
    subprocess.run(['fparkey',str(gti_sum),merged_file,'EXPOSURE'])

    return

    Given a list of ObsIDs, create a file which merges all the rows in the EVENTS
    extension of the FITS files!
    Updated 8/14/2020: Use a list of event files given in a text file!

    obsids - list (or array) of ObsIDs
    merged_id - 6-digit ID for the merged event file
    
Given a list of ObsIDs, create a file which merges all the rows in the EVENTS
extension of the FITS files.
Updated 8/14/2020: Use a list of event files given in a text file!

list (or array) of ObsIDs
merged_id - 6-digit ID for the merged event file
Given a list of ObsIDs create a file which merges all the rows in the EVENTS extension of the FITS files . Updated 8 / 14 / 2020 : Use a list of event files given in a text file! list ( or array ) of ObsIDs merged_id - 6 - digit ID for the merged event file
def merging(obsids,merged_id):
    if type(obsids) != list and type(obsids) != np.ndarray:
        raise TypeError("obsids should either be a list or an array!")
    if type(merged_id) != str or len(merged_id) != 6:
        raise TypeError("merged_id should be a string and have 6 digits in the string!")
    all_merged_dir = Lv0_dirs.NICERSOFT_DATADIR + 'merged_events/'
    merged_dir = all_merged_dir + 'merged' + merged_id + '/'
    Lv2_mkdir.makedir(merged_dir)
    filelist = np.array([Lv0_dirs.NICERSOFT_DATADIR + str(obsids[i]) + '_pipe/ni' + str(obsids[i]) + '_nicersoft_bary.evt' for i in range(len(obsids))])
    int_text = open(merged_dir+'filelist.txt','w')
    for i in range(len(filelist)): 
        int_text.write(filelist[i] + '\n')
    int_text.close()
    subprocess.run(['ftmerge','@'+merged_dir+'filelist.txt',merged_dir+'intermediate.evt'])
    gti_filelist = np.array([Lv0_dirs.NICERSOFT_DATADIR + str(obsids[i]) + '_pipe/ni' + str(obsids[i]) + '_nicersoft_bary.evt[GTI]' for i in range(1,len(obsids))])
    final_text = open(merged_dir+'filelist_gti.txt','w') 
    final_text.write(merged_dir+'intermediate.evt[GTI]'+'\n')
    for i in range(len(gti_filelist)):
        final_text.write(gti_filelist[i] + '\n')
    final_text.close()
    merged_file = merged_dir+'merged'+merged_id+'_nicersoft_bary.evt'
    subprocess.run(['ftmerge','@'+merged_dir+'filelist_gti.txt',merged_file,'clobber=YES'])
    subprocess.run(['rm','-r',merged_dir+'intermediate.evt'])
    merged_gtis = fits.open(merged_file)[2].data
    gti_sum = sum(np.array([merged_gtis[i][1]-merged_gtis[i][0] for i in range(len(merged_gtis))]))
    subprocess.run(['fparkey',str(gti_sum),merged_file,'EXPOSURE'])
    return
def merging ( obsids , merged_id ) : if type ( obsids ) != list and type ( obsids ) != np . ndarray : raise TypeError ( "obsids should either be a list or an array!" ) if type ( merged_id ) != str or len ( merged_id ) != 6 : raise TypeError ( "merged_id should be a string and have 6 digits in the string!" ) all_merged_dir = Lv0_dirs . NICERSOFT_DATADIR + 'merged_events/' merged_dir = all_merged_dir + 'merged' + merged_id + '/' Lv2_mkdir . makedir ( merged_dir ) filelist = np . array ( [ Lv0_dirs . NICERSOFT_DATADIR + str ( obsids [ i ] ) + '_pipe/ni' + str ( obsids [ i ] ) + '_nicersoft_bary.evt' for i in range ( len ( obsids ) ) ] ) int_text = open ( merged_dir + 'filelist.txt' , 'w' ) for i in range ( len ( filelist ) ) : int_text . write ( filelist [ i ] + '\n' ) int_text . close ( ) subprocess . run ( [ 'ftmerge' , '@' + merged_dir + 'filelist.txt' , merged_dir + 'intermediate.evt' ] ) gti_filelist = np . array ( [ Lv0_dirs . NICERSOFT_DATADIR + str ( obsids [ i ] ) + '_pipe/ni' + str ( obsids [ i ] ) + '_nicersoft_bary.evt[GTI]' for i in range ( 1 , len ( obsids ) ) ] ) final_text = open ( merged_dir + 'filelist_gti.txt' , 'w' ) final_text . write ( merged_dir + 'intermediate.evt[GTI]' + '\n' ) for i in range ( len ( gti_filelist ) ) : final_text . write ( gti_filelist [ i ] + '\n' ) final_text . close ( ) merged_file = merged_dir + 'merged' + merged_id + '_nicersoft_bary.evt' subprocess . run ( [ 'ftmerge' , '@' + merged_dir + 'filelist_gti.txt' , merged_file , 'clobber=YES' ] ) subprocess . run ( [ 'rm' , '-r' , merged_dir + 'intermediate.evt' ] ) merged_gtis = fits . open ( merged_file ) [ 2 ] . data gti_sum = sum ( np . array ( [ merged_gtis [ i ] [ 1 ] - merged_gtis [ i ] [ 0 ] for i in range ( len ( merged_gtis ) ) ] ) ) subprocess . run ( [ 'fparkey' , str ( gti_sum ) , merged_file , 'EXPOSURE' ] ) return
Given a list of ObsIDs, create a file which merges all the rows in the EVENTS
extension of the FITS files!
Given a list of ObsIDs create a file which merges all the rows in the EVENTS extension of the FITS files!
"""
    Given a list of ObsIDs, create a file which merges all the rows in the EVENTS
    extension of the FITS files!
    Updated 8/14/2020: Use a list of event files given in a text file!

    obsids - list (or array) of ObsIDs
    merged_id - 6-digit ID for the merged event file
    """ #writing the paths to each file in filelist #list of files with the GTI extension referenced
obsids
merged_id