Lv2_average_ps_methods.py
def presto_fft(eventfile,segment_length,demod,PI1,PI2,t1,t2):
    """
    Obtain the FFT files that were generated from PRESTO

    eventfile - path to the event file. Will extract ObsID from this for the NICER files.
    segment_length - length of the segments
    demod - whether we're dealing with demodulated data or not!
    PI1 - lower bound of PI (not energy in keV!) desired for the energy range
    PI2 - upper bound of PI (not energy in keV!) desired for the energy range
    t1 - starting time for calculation of averaged power spectra
    t2 - ending time for calculation of averaged power spectra
    (note that t=0 corresponds to the MET of the FIRST event in the eventfile, so will need to inspect light curve with Lv2_lc.py to get times)
    """
    if demod != True and demod != False:
        raise ValueError("demod should either be True or False!")

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

    if PI1 != '': #if we're doing energy cuts instead
        fft_files = sorted(glob.glob(parent_folder + '/accelsearch_' + str(segment_length) + 's/*E' + str(PI1).zfill(4) + '-' + str(PI2).zfill(4) + '*.fft'))
        demod_files = sorted(glob.glob(parent_folder + '/accelsearch_' + str(segment_length) + 's/*E' + str(PI1).zfill(4) + '-' + str(PI2).zfill(4) + '*demod.fft'))

    else:
        fft_files = []
        demod_files = []
        all_fft_files = sorted(glob.glob(parent_folder + '/accelsearch_' + str(segment_length) + 's/*.fft'))
        all_demod_files = sorted(glob.glob(parent_folder + '/accelsearch_' + str(segment_length) + 's/*demod.fft'))
        for i in range(len(all_fft_files)):
            if 'E' not in str(pathlib.Path(all_fft_files[i]).name):
                fft_files.append(all_fft_files[i])
        for i in range(len(all_demod_files)):
            if 'E' not in str(pathlib.Path(all_demod_files[i]).name):
                demod_files.append(all_demod_files[i])

    if t1 != 0 or t2 != 0: #if both starting and ending times are not zero; otherwise default is to use ALL the data in the eventfile
        gti_start = int(t1/segment_length)
        gti_end = np.ceil(t2/segment_length)
        filt_fft_files = np.array([fft_files[i] for i in range(len(fft_files)) if (int(fft_files[i][fft_files[i].index('GTI')+3:fft_files[i].index('GTI')+9]) >= gti_start) and (int(fft_files[i][fft_files[i].index('GTI')+3:fft_files[i].index('GTI')+9]) <= gti_end)])
        filt_demod_files = np.array([demod_files[i] for i in range(len(demod_files)) if (int(demod_files[i][demod_files[i].index('GTI')+3:demod_files[i].index('GTI')+9]) >= gti_start) and (int(demod_files[i][demod_files[i].index('GTI')+3:demod_files[i].index('GTI')+9]) <= gti_end)])

        if demod == True:
            return np.array(filt_demod_files)
        else:
            return np.array([fftfile for fftfile in filt_fft_files if fftfile not in set(filt_demod_files)])

    else:
        if demod == True:
            return np.array(demod_files)
        else:
            return np.array([fftfile for fftfile in fft_files if fftfile not in set(demod_files)])

    Obtain the FFT files that were generated from PRESTO

    eventfile - path to the event file. Will extract ObsID from this for the NICER files.
    segment_length - length of the segments
    demod - whether we're dealing with demodulated data or not!
    PI1 - lower bound of PI (not energy in keV!) desired for the energy range
    PI2 - upper bound of PI (not energy in keV!) desired for the energy range
    t1 - starting time for calculation of averaged power spectra
    t2 - ending time for calculation of averaged power spectra
    (note that t=0 corresponds to the MET of the FIRST event in the eventfile, so will need to inspect light curve with Lv2_lc.py to get times)
    
Obtain the FFT files that were generated from PRESTO
eventfile - path to the event file. Will extract ObsID from this for the NICER files.
segment_length - length of the segments
demod - whether we're dealing with demodulated data or not.
PI1 - lower bound of PI (not energy in keV!) desired for the energy range
PI2 - upper bound of PI (not energy in keV!) desired for the energy range
t1 - starting time for calculation of averaged power spectra
t2 - ending time for calculation of averaged power spectra
(note that t=0 corresponds to the MET of the FIRST event in the eventfile, so will need to inspect light curve with Lv2_lc.py to get times)
Obtain the FFT files that were generated from PRESTO eventfile - path to the event file . Will extract ObsID from this for the NICER files . segment_length - length of the segments demod - whether we ' re dealing with demodulated data or not . PI1 - lower bound of PI ( not energy in keV! ) desired for the energy range PI2 - upper bound of PI ( not energy in keV! ) desired for the energy range t1 - starting time for calculation of averaged power spectra t2 - ending time for calculation of averaged power spectra ( note that t = 0 corresponds to the MET of the FIRST event in the eventfile so will need to inspect light curve with Lv2_lc . py to get times )
def presto_fft(eventfile,segment_length,demod,PI1,PI2,t1,t2):
    if demod != True and demod != False:
        raise ValueError("demod should either be True or False!")
    parent_folder = str(pathlib.Path(eventfile).parent)
    if PI1 != '': 
        fft_files = sorted(glob.glob(parent_folder + '/accelsearch_' + str(segment_length) + 's/*E' + str(PI1).zfill(4) + '-' + str(PI2).zfill(4) + '*.fft'))
        demod_files = sorted(glob.glob(parent_folder + '/accelsearch_' + str(segment_length) + 's/*E' + str(PI1).zfill(4) + '-' + str(PI2).zfill(4) + '*demod.fft'))
    else:
        fft_files = []
        demod_files = []
        all_fft_files = sorted(glob.glob(parent_folder + '/accelsearch_' + str(segment_length) + 's/*.fft'))
        all_demod_files = sorted(glob.glob(parent_folder + '/accelsearch_' + str(segment_length) + 's/*demod.fft'))
        for i in range(len(all_fft_files)):
            if 'E' not in str(pathlib.Path(all_fft_files[i]).name):
                fft_files.append(all_fft_files[i])
        for i in range(len(all_demod_files)):
            if 'E' not in str(pathlib.Path(all_demod_files[i]).name):
                demod_files.append(all_demod_files[i])
    if t1 != 0 or t2 != 0: 
        gti_start = int(t1/segment_length)
        gti_end = np.ceil(t2/segment_length)
        filt_fft_files = np.array([fft_files[i] for i in range(len(fft_files)) if (int(fft_files[i][fft_files[i].index('GTI')+3:fft_files[i].index('GTI')+9]) >= gti_start) and (int(fft_files[i][fft_files[i].index('GTI')+3:fft_files[i].index('GTI')+9]) <= gti_end)])
        filt_demod_files = np.array([demod_files[i] for i in range(len(demod_files)) if (int(demod_files[i][demod_files[i].index('GTI')+3:demod_files[i].index('GTI')+9]) >= gti_start) and (int(demod_files[i][demod_files[i].index('GTI')+3:demod_files[i].index('GTI')+9]) <= gti_end)])
        if demod == True:
            return np.array(filt_demod_files)
        else:
            return np.array([fftfile for fftfile in filt_fft_files if fftfile not in set(filt_demod_files)])
    else:
        if demod == True:
            return np.array(demod_files)
        else:
            return np.array([fftfile for fftfile in fft_files if fftfile not in set(demod_files)])
def presto_fft ( eventfile , segment_length , demod , PI1 , PI2 , t1 , t2 ) : if demod != True and demod != False : raise ValueError ( "demod should either be True or False!" ) parent_folder = str ( pathlib . Path ( eventfile ) . parent ) if PI1 != '' : fft_files = sorted ( glob . glob ( parent_folder + '/accelsearch_' + str ( segment_length ) + 's/*E' + str ( PI1 ) . zfill ( 4 ) + '-' + str ( PI2 ) . zfill ( 4 ) + '*.fft' ) ) demod_files = sorted ( glob . glob ( parent_folder + '/accelsearch_' + str ( segment_length ) + 's/*E' + str ( PI1 ) . zfill ( 4 ) + '-' + str ( PI2 ) . zfill ( 4 ) + '*demod.fft' ) ) else : fft_files = [ ] demod_files = [ ] all_fft_files = sorted ( glob . glob ( parent_folder + '/accelsearch_' + str ( segment_length ) + 's/*.fft' ) ) all_demod_files = sorted ( glob . glob ( parent_folder + '/accelsearch_' + str ( segment_length ) + 's/*demod.fft' ) ) for i in range ( len ( all_fft_files ) ) : if 'E' not in str ( pathlib . Path ( all_fft_files [ i ] ) . name ) : fft_files . append ( all_fft_files [ i ] ) for i in range ( len ( all_demod_files ) ) : if 'E' not in str ( pathlib . Path ( all_demod_files [ i ] ) . name ) : demod_files . append ( all_demod_files [ i ] ) if t1 != 0 or t2 != 0 : gti_start = int ( t1 / segment_length ) gti_end = np . ceil ( t2 / segment_length ) filt_fft_files = np . array ( [ fft_files [ i ] for i in range ( len ( fft_files ) ) if ( int ( fft_files [ i ] [ fft_files [ i ] . index ( 'GTI' ) + 3 : fft_files [ i ] . index ( 'GTI' ) + 9 ] ) >= gti_start ) and ( int ( fft_files [ i ] [ fft_files [ i ] . index ( 'GTI' ) + 3 : fft_files [ i ] . index ( 'GTI' ) + 9 ] ) <= gti_end ) ] ) filt_demod_files = np . array ( [ demod_files [ i ] for i in range ( len ( demod_files ) ) if ( int ( demod_files [ i ] [ demod_files [ i ] . index ( 'GTI' ) + 3 : demod_files [ i ] . index ( 'GTI' ) + 9 ] ) >= gti_start ) and ( int ( demod_files [ i ] [ demod_files [ i ] . index ( 'GTI' ) + 3 : demod_files [ i ] . index ( 'GTI' ) + 9 ] ) <= gti_end ) ] ) if demod == True : return np . array ( filt_demod_files ) else : return np . array ( [ fftfile for fftfile in filt_fft_files if fftfile not in set ( filt_demod_files ) ] ) else : if demod == True : return np . array ( demod_files ) else : return np . array ( [ fftfile for fftfile in fft_files if fftfile not in set ( demod_files ) ] )
Obtain the FFT files that were generated from PRESTO
eventfile - path to the event file.
Obtain the FFT files that were generated from PRESTO eventfile - path to the event file .
"""
    Obtain the FFT files that were generated from PRESTO

    eventfile - path to the event file. Will extract ObsID from this for the NICER files.
    segment_length - length of the segments
    demod - whether we're dealing with demodulated data or not!
    PI1 - lower bound of PI (not energy in keV!) desired for the energy range
    PI2 - upper bound of PI (not energy in keV!) desired for the energy range
    t1 - starting time for calculation of averaged power spectra
    t2 - ending time for calculation of averaged power spectra
    (note that t=0 corresponds to the MET of the FIRST event in the eventfile, so will need to inspect light curve with Lv2_lc.py to get times)
    """ #if we're doing energy cuts instead #if both starting and ending times are not zero; otherwise default is to use ALL the data in the eventfile
eventfile
segment_length
demod
PI1
PI2
t1
t2