Lv2_presto_subroutines.py
def do_nicerfits2presto(eventfile,tbin,segment_length,mode):
    """
    Using nicerfits2presto.py to bin the data, and to convert into PRESTO-readable format.
    I can always move files to different folders to prevent repeats (especially for large files)
    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 for combining power spectra
    mode - "all", "t", "gtis" or "E" ; basically to tell the function where to access files to run realfft for
    """
    parent_folder = str(pathlib.Path(eventfile).parent)
    event_header = fits.open(eventfile)[1].header
    obj_name = event_header['OBJECT']
    obsid = event_header['OBS_ID']

    if mode == "all": #for non-segmented event file
        subprocess.run(['nicerfits2presto.py','--dt='+str(tbin),eventfile])

    if mode == "E":
        E_files = glob.glob(parent_folder+'/accelsearch_E/*.evt')
        if len(E_files) != 0: #if E_files is not empty
            for i in tqdm(range(len(E_files))):
                if os.path.exists(E_files[i][:-3] + 'dat'):
                    continue
                try:
                    subprocess.run(['nicerfits2presto.py','--dt='+str(tbin),E_files[i]])
                except (ValueError,subprocess.CalledProcessError):
                    pass

    if mode == 't':
        time_files = glob.glob(parent_folder+'/accelsearch_' + str(segment_length) + 's/*.evt')
        if len(time_files) != 0:
            for i in tqdm(range(len(time_files))):
                if os.path.exists(time_files[i][:-3] + 'dat'):
                    continue
                try:
                    subprocess.run(['nicerfits2presto.py','--dt='+str(tbin),time_files[i]])
                except (ValueError,subprocess.CalledProcessError):
                    pass

    if mode == "gtis":
        gti_files = glob.glob(parent_folder+'/accelsearch_GTIs/*.evt')
        if len(gti_files) != 0:
            for i in tqdm(range(len(gti_files))):
                if os.path.exists(gti_files[i][:-3] + 'dat'):
                    continue
                try:
                    subprocess.run(['nicerfits2presto.py','--dt='+str(tbin),gti_files[i]])
                except (ValueError,subprocess.CalledProcessError):
                    pass

    ##### will probably remove once I know to either NOT work in nicerpy_xrayanalysis,
    ##### and/or install my packages such that I can run the scripts from anywhere
    ##### in the terminal!

    presto_files = glob.glob('*'+obsid+'*')
    if 'merged' in eventfile:
        presto_files = glob.glob('merged*')
    for i in range(len(presto_files)):
        if mode == "all":
            subprocess.run(['mv',presto_files[i],parent_folder+'/'])
        if mode == "t":
            subprocess.run(['mv',presto_files[i],parent_folder+'/accelsearch_' + str(segment_length) + 's/'])
        if mode == "E":
            subprocess.run(['mv',presto_files[i],parent_folder+'/accelsearch_E/'])
        if mode == "gtis":
            subprocess.run(['mv',presto_files[i],parent_folder+'/accelsearch_GTIs/'])

    return

    Using nicerfits2presto.py to bin the data, and to convert into PRESTO-readable format.
    I can always move files to different folders to prevent repeats (especially for large files)
    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 for combining power spectra
    mode - "all", "t", "gtis" or "E" ; basically to tell the function where to access files to run realfft for
    
Using nicerfits2presto.py to bin the data, and to convert into PRESTO-readable format.
I can always move files to different folders to prevent repeats (especially for large files)
eventfile - path to the event file. Will extract ObsID from this for the NICER files.
Using nicerfits2presto . py to bin the data and to convert into PRESTO - readable format . I can always move files to different folders to prevent repeats ( especially for large files ) eventfile - path to the event file . Will extract ObsID from this for the NICER files .
def do_nicerfits2presto(eventfile,tbin,segment_length,mode):
    parent_folder = str(pathlib.Path(eventfile).parent)
    event_header = fits.open(eventfile)[1].header
    obj_name = event_header['OBJECT']
    obsid = event_header['OBS_ID']
    if mode == "all": 
        subprocess.run(['nicerfits2presto.py','--dt='+str(tbin),eventfile])
    if mode == "E":
        E_files = glob.glob(parent_folder+'/accelsearch_E/*.evt')
        if len(E_files) != 0: 
            for i in tqdm(range(len(E_files))):
                if os.path.exists(E_files[i][:-3] + 'dat'):
                    continue
                try:
                    subprocess.run(['nicerfits2presto.py','--dt='+str(tbin),E_files[i]])
                except (ValueError,subprocess.CalledProcessError):
                    pass
    if mode == 't':
        time_files = glob.glob(parent_folder+'/accelsearch_' + str(segment_length) + 's/*.evt')
        if len(time_files) != 0:
            for i in tqdm(range(len(time_files))):
                if os.path.exists(time_files[i][:-3] + 'dat'):
                    continue
                try:
                    subprocess.run(['nicerfits2presto.py','--dt='+str(tbin),time_files[i]])
                except (ValueError,subprocess.CalledProcessError):
                    pass
    if mode == "gtis":
        gti_files = glob.glob(parent_folder+'/accelsearch_GTIs/*.evt')
        if len(gti_files) != 0:
            for i in tqdm(range(len(gti_files))):
                if os.path.exists(gti_files[i][:-3] + 'dat'):
                    continue
                try:
                    subprocess.run(['nicerfits2presto.py','--dt='+str(tbin),gti_files[i]])
                except (ValueError,subprocess.CalledProcessError):
                    pass
    presto_files = glob.glob('*'+obsid+'*')
    if 'merged' in eventfile:
        presto_files = glob.glob('merged*')
    for i in range(len(presto_files)):
        if mode == "all":
            subprocess.run(['mv',presto_files[i],parent_folder+'/'])
        if mode == "t":
            subprocess.run(['mv',presto_files[i],parent_folder+'/accelsearch_' + str(segment_length) + 's/'])
        if mode == "E":
            subprocess.run(['mv',presto_files[i],parent_folder+'/accelsearch_E/'])
        if mode == "gtis":
            subprocess.run(['mv',presto_files[i],parent_folder+'/accelsearch_GTIs/'])
    return
def do_nicerfits2presto ( eventfile , tbin , segment_length , mode ) : parent_folder = str ( pathlib . Path ( eventfile ) . parent ) event_header = fits . open ( eventfile ) [ 1 ] . header obj_name = event_header [ 'OBJECT' ] obsid = event_header [ 'OBS_ID' ] if mode == "all" : subprocess . run ( [ 'nicerfits2presto.py' , '--dt=' + str ( tbin ) , eventfile ] ) if mode == "E" : E_files = glob . glob ( parent_folder + '/accelsearch_E/*.evt' ) if len ( E_files ) != 0 : for i in tqdm ( range ( len ( E_files ) ) ) : if os . path . exists ( E_files [ i ] [ : - 3 ] + 'dat' ) : continue try : subprocess . run ( [ 'nicerfits2presto.py' , '--dt=' + str ( tbin ) , E_files [ i ] ] ) except ( ValueError , subprocess . CalledProcessError ) : pass if mode == 't' : time_files = glob . glob ( parent_folder + '/accelsearch_' + str ( segment_length ) + 's/*.evt' ) if len ( time_files ) != 0 : for i in tqdm ( range ( len ( time_files ) ) ) : if os . path . exists ( time_files [ i ] [ : - 3 ] + 'dat' ) : continue try : subprocess . run ( [ 'nicerfits2presto.py' , '--dt=' + str ( tbin ) , time_files [ i ] ] ) except ( ValueError , subprocess . CalledProcessError ) : pass if mode == "gtis" : gti_files = glob . glob ( parent_folder + '/accelsearch_GTIs/*.evt' ) if len ( gti_files ) != 0 : for i in tqdm ( range ( len ( gti_files ) ) ) : if os . path . exists ( gti_files [ i ] [ : - 3 ] + 'dat' ) : continue try : subprocess . run ( [ 'nicerfits2presto.py' , '--dt=' + str ( tbin ) , gti_files [ i ] ] ) except ( ValueError , subprocess . CalledProcessError ) : pass presto_files = glob . glob ( '*' + obsid + '*' ) if 'merged' in eventfile : presto_files = glob . glob ( 'merged*' ) for i in range ( len ( presto_files ) ) : if mode == "all" : subprocess . run ( [ 'mv' , presto_files [ i ] , parent_folder + '/' ] ) if mode == "t" : subprocess . run ( [ 'mv' , presto_files [ i ] , parent_folder + '/accelsearch_' + str ( segment_length ) + 's/' ] ) if mode == "E" : subprocess . run ( [ 'mv' , presto_files [ i ] , parent_folder + '/accelsearch_E/' ] ) if mode == "gtis" : subprocess . run ( [ 'mv' , presto_files [ i ] , parent_folder + '/accelsearch_GTIs/' ] ) return
Using nicerfits2presto.py to bin the data, and to convert into PRESTO-readable format.
Using nicerfits2presto . py to bin the data and to convert into PRESTO - readable format .
"""
    Using nicerfits2presto.py to bin the data, and to convert into PRESTO-readable format.
    I can always move files to different folders to prevent repeats (especially for large files)
    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 for combining power spectra
    mode - "all", "t", "gtis" or "E" ; basically to tell the function where to access files to run realfft for
    """ #for non-segmented event file #if E_files is not empty ##### will probably remove once I know to either NOT work in nicerpy_xrayanalysis, ##### and/or install my packages such that I can run the scripts from anywhere ##### in the terminal!
eventfile
tbin
segment_length
mode