Lv2_presto_subroutines.py
def accelsearch(eventfile,segment_length,mode,flags):
    """
    Performing PRESTO's accelsearch on the FFT data (.fft)
    eventfile - path to the event file. Will extract ObsID from this for the NICER files.
    segment_length - length of the individual segments
    mode - "all", "t", "gtis" or "E" ; basically to tell the function where to access files to run accelsearch for
    flags - a LIST of input flags for accelsearch
    """
    if type(flags) != list:
        raise TypeError("flags should be a list! Not even an array.")

    parent_folder = str(pathlib.Path(eventfile).parent)

    if mode == "all":
        fft_files = sorted(glob.glob(parent_folder+'/*.fft'))
        logfile = parent_folder + '/accelsearch_all.log'
    elif mode == "t":
        fft_files = sorted(glob.glob(parent_folder+'/accelsearch_'+str(segment_length)+'s/*.fft'))
        logfile = parent_folder + '/accelsearch_' + str(segment_length) + 's/accelsearch_t.log'
    elif mode == "E":
        fft_files = sorted(glob.glob(parent_folder+'/accelsearch_E/*.fft'))
        logfile = parent_folder + '/accelsearch_E/accelsearch_E.log'
    elif mode == "gtis":
        fft_files = sorted(glob.glob(parent_folder+'/accelsearch_GTIs/*.fft'))
        logfile = parent_folder + '/accelsearch_GTIs/accelsearch_gtis.log'
    else:
        raise ValueError("mode should either of 'all', 't', 'gtis', or 'E'!")

    zmax_index = flags.index('-zmax')
    zmax_num = str(flags[zmax_index+1])
    print("Running accelsearch now:")
    with open(logfile,'w') as logtextfile:
        for i in tqdm(range(len(fft_files))):
            #if os.path.exists(fft_files[i][:-4] + '_ACCEL_' + zmax_num + '.txtcand') == False:
            command = ['accelsearch'] + flags + [fft_files[i]]
            output = subprocess.run(command,capture_output=True,text=True)
            logtextfile.write(output.stdout)
            logtextfile.write('*------------------------------* \n')
            logtextfile.write(output.stderr)
        logtextfile.close()

    return

    Performing PRESTO's accelsearch on the FFT data (.fft)
    eventfile - path to the event file. Will extract ObsID from this for the NICER files.
    segment_length - length of the individual segments
    mode - "all", "t", "gtis" or "E" ; basically to tell the function where to access files to run accelsearch for
    flags - a LIST of input flags for accelsearch
    
Performing PRESTO's accelsearch on the FFT data (.fft)
eventfile - path to the event file. Will extract ObsID from this for the NICER files.
Performing PRESTO ' s accelsearch on the FFT data ( . fft ) eventfile - path to the event file . Will extract ObsID from this for the NICER files .
def accelsearch(eventfile,segment_length,mode,flags):
    if type(flags) != list:
        raise TypeError("flags should be a list! Not even an array.")
    parent_folder = str(pathlib.Path(eventfile).parent)
    if mode == "all":
        fft_files = sorted(glob.glob(parent_folder+'/*.fft'))
        logfile = parent_folder + '/accelsearch_all.log'
    elif mode == "t":
        fft_files = sorted(glob.glob(parent_folder+'/accelsearch_'+str(segment_length)+'s/*.fft'))
        logfile = parent_folder + '/accelsearch_' + str(segment_length) + 's/accelsearch_t.log'
    elif mode == "E":
        fft_files = sorted(glob.glob(parent_folder+'/accelsearch_E/*.fft'))
        logfile = parent_folder + '/accelsearch_E/accelsearch_E.log'
    elif mode == "gtis":
        fft_files = sorted(glob.glob(parent_folder+'/accelsearch_GTIs/*.fft'))
        logfile = parent_folder + '/accelsearch_GTIs/accelsearch_gtis.log'
    else:
        raise ValueError("mode should either of 'all', 't', 'gtis', or 'E'!")
    zmax_index = flags.index('-zmax')
    zmax_num = str(flags[zmax_index+1])
    print("Running accelsearch now:")
    with open(logfile,'w') as logtextfile:
        for i in tqdm(range(len(fft_files))):
            command = ['accelsearch'] + flags + [fft_files[i]]
            output = subprocess.run(command,capture_output=True,text=True)
            logtextfile.write(output.stdout)
            logtextfile.write('*------------------------------* \n')
            logtextfile.write(output.stderr)
        logtextfile.close()
    return
def accelsearch ( eventfile , segment_length , mode , flags ) : if type ( flags ) != list : raise TypeError ( "flags should be a list! Not even an array." ) parent_folder = str ( pathlib . Path ( eventfile ) . parent ) if mode == "all" : fft_files = sorted ( glob . glob ( parent_folder + '/*.fft' ) ) logfile = parent_folder + '/accelsearch_all.log' elif mode == "t" : fft_files = sorted ( glob . glob ( parent_folder + '/accelsearch_' + str ( segment_length ) + 's/*.fft' ) ) logfile = parent_folder + '/accelsearch_' + str ( segment_length ) + 's/accelsearch_t.log' elif mode == "E" : fft_files = sorted ( glob . glob ( parent_folder + '/accelsearch_E/*.fft' ) ) logfile = parent_folder + '/accelsearch_E/accelsearch_E.log' elif mode == "gtis" : fft_files = sorted ( glob . glob ( parent_folder + '/accelsearch_GTIs/*.fft' ) ) logfile = parent_folder + '/accelsearch_GTIs/accelsearch_gtis.log' else : raise ValueError ( "mode should either of 'all', 't', 'gtis', or 'E'!" ) zmax_index = flags . index ( '-zmax' ) zmax_num = str ( flags [ zmax_index + 1 ] ) print ( "Running accelsearch now:" ) with open ( logfile , 'w' ) as logtextfile : for i in tqdm ( range ( len ( fft_files ) ) ) : command = [ 'accelsearch' ] + flags + [ fft_files [ i ] ] output = subprocess . run ( command , capture_output = True , text = True ) logtextfile . write ( output . stdout ) logtextfile . write ( '*------------------------------* \n' ) logtextfile . write ( output . stderr ) logtextfile . close ( ) return
Performing PRESTO's accelsearch on the FFT data (.fft)
eventfile - path to the event file.
Performing PRESTO ' s accelsearch on the FFT data ( . fft ) eventfile - path to the event file .
"""
    Performing PRESTO's accelsearch on the FFT data (.fft)
    eventfile - path to the event file. Will extract ObsID from this for the NICER files.
    segment_length - length of the individual segments
    mode - "all", "t", "gtis" or "E" ; basically to tell the function where to access files to run accelsearch for
    flags - a LIST of input flags for accelsearch
    """ #if os.path.exists(fft_files[i][:-4] + '_ACCEL_' + zmax_num + '.txtcand') == False:
eventfile
segment_length
mode
flags