Lv2_presto_subroutines.py
def edit_inf(eventfile,tbin,segment_length):
    """
    Editing the .inf file, as it seems like accelsearch uses some information from the .inf file!
    Mainly need to edit the "Number of bins in the time series".
    This is only for when we make segments by time though!
    eventfile - path to the event file. Will extract ObsID from this for the NICER files.
    tbin - size of the bins in time
    segment_length - length of the individual segments
    """
    parent_folder = str(pathlib.Path(eventfile).parent)
    event_header = fits.open(eventfile)[1].header
    #obj_name = event_header['OBJECT']
    #obsid = event_header['OBS_ID']

    inf_files = sorted(glob.glob(parent_folder + '/accelsearch_' + str(segment_length) + 's/*GTI*' + str(segment_length).zfill(5)+'s*.inf')) #not the .evt file; some .evt files will be empty
    #inf_files = sorted(glob.glob(parent_folder + '/accelsearch_GTIs/*GTI*.inf')) #not the .evt file; some .evt files will be empty

    no_desired_bins = float(segment_length)/float(tbin)

    for i in range(len(inf_files)):
        inf_file = open(inf_files[i],'r')
        contents = inf_file.read()
        contents = contents.split('\n')
        inf_file.close()

        nobins_equal = contents[9].index('=') #find the '=' sign for the "Number of bins..." line)
        newstring = contents[9][:nobins_equal+1] + '  ' + str(int(no_desired_bins)) #replace old line with new line containing updated number of bins!

        inf_file = open(inf_files[i],'w')
        for j in range(len(contents)):
            if j != 9:
                inf_file.write(contents[j]+'\n')
            else:
                inf_file.write(newstring+'\n')
        inf_file.close()

    return

    Editing the .inf file, as it seems like accelsearch uses some information from the .inf file!
    Mainly need to edit the "Number of bins in the time series".
    This is only for when we make segments by time though!
    eventfile - path to the event file. Will extract ObsID from this for the NICER files.
    tbin - size of the bins in time
    segment_length - length of the individual segments
    
Editing the .inf file, as it seems like accelsearch uses some information from the .inf file.
Mainly need to edit the "Number of bins in the time series".
This is only for when we make segments by time though.
eventfile - path to the event file. Will extract ObsID from this for the NICER files.
tbin - size of the bins in time
segment_length - length of the individual segments
Editing the . inf file as it seems like accelsearch uses some information from the . inf file . Mainly need to edit the " Number of bins in the time series " . This is only for when we make segments by time though . eventfile - path to the event file . Will extract ObsID from this for the NICER files . tbin - size of the bins in time segment_length - length of the individual segments
def edit_inf(eventfile,tbin,segment_length):
    parent_folder = str(pathlib.Path(eventfile).parent)
    event_header = fits.open(eventfile)[1].header
    inf_files = sorted(glob.glob(parent_folder + '/accelsearch_' + str(segment_length) + 's/*GTI*' + str(segment_length).zfill(5)+'s*.inf')) 
    #inf_files = sorted(glob.glob(parent_folder + '/accelsearch_GTIs/*GTI*.inf')) 
    no_desired_bins = float(segment_length)/float(tbin)
    for i in range(len(inf_files)):
        inf_file = open(inf_files[i],'r')
        contents = inf_file.read()
        contents = contents.split('\n')
        inf_file.close()
        nobins_equal = contents[9].index('=') 
        newstring = contents[9][:nobins_equal+1] + '  ' + str(int(no_desired_bins)) 
        inf_file = open(inf_files[i],'w')
        for j in range(len(contents)):
            if j != 9:
                inf_file.write(contents[j]+'\n')
            else:
                inf_file.write(newstring+'\n')
        inf_file.close()
    return
def edit_inf ( eventfile , tbin , segment_length ) : parent_folder = str ( pathlib . Path ( eventfile ) . parent ) event_header = fits . open ( eventfile ) [ 1 ] . header inf_files = sorted ( glob . glob ( parent_folder + '/accelsearch_' + str ( segment_length ) + 's/*GTI*' + str ( segment_length ) . zfill ( 5 ) + 's*.inf' ) ) no_desired_bins = float ( segment_length ) / float ( tbin ) for i in range ( len ( inf_files ) ) : inf_file = open ( inf_files [ i ] , 'r' ) contents = inf_file . read ( ) contents = contents . split ( '\n' ) inf_file . close ( ) nobins_equal = contents [ 9 ] . index ( '=' ) newstring = contents [ 9 ] [ : nobins_equal + 1 ] + '  ' + str ( int ( no_desired_bins ) ) inf_file = open ( inf_files [ i ] , 'w' ) for j in range ( len ( contents ) ) : if j != 9 : inf_file . write ( contents [ j ] + '\n' ) else : inf_file . write ( newstring + '\n' ) inf_file . close ( ) return
Editing the .inf file, as it seems like accelsearch uses some information from the .inf file!
Editing the . inf file as it seems like accelsearch uses some information from the . inf file!
"""
    Editing the .inf file, as it seems like accelsearch uses some information from the .inf file!
    Mainly need to edit the "Number of bins in the time series".
    This is only for when we make segments by time though!
    eventfile - path to the event file. Will extract ObsID from this for the NICER files.
    tbin - size of the bins in time
    segment_length - length of the individual segments
    """ #obj_name = event_header['OBJECT'] #obsid = event_header['OBS_ID'] #not the .evt file; some .evt files will be empty #inf_files = sorted(glob.glob(parent_folder + '/accelsearch_GTIs/*GTI*.inf')) #not the .evt file; some .evt files will be empty #find the '=' sign for the "Number of bins..." line) #replace old line with new line containing updated number of bins!
eventfile
tbin
segment_length