Lv2_average_ps_methods.py
def segment_threshold(eventfile,segment_length,demod,tbin_size,threshold,PI1,PI2,t1,t2):
    """
    Using the .dat files, rebin them into 1s bins, to weed out the segments below
    some desired threshold. Will return a *list* of *indices*! This is so that I
    can filter out the *sorted* array of .dat and .fft files that are below threshold!

    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!
    tbin_size - size of the time bin
    threshold - if data is under threshold (in percentage), then don't use the segment!
    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!")

    dat_files = presto_dat(eventfile,segment_length,demod,PI1,PI2,t1,t2)
    rebin_t = np.arange(segment_length+1)*1 #1-second bins
    passed_threshold = []
    print('Now finding the number of segments that can be used...')
    for i in tqdm(range(len(dat_files))):
        dat_file_data = np.fromfile(dat_files[i],dtype='<f',count=-1)
        data_t = np.arange(len(dat_file_data))*tbin_size
        rebin_sum,rebin_edges,rebin_trunc = stats.binned_statistic(data_t,dat_file_data,statistic='sum',bins=rebin_t)
        #print(str(pathlib.Path(dat_files[i]).name),len(rebin_sum[rebin_sum>0])/len(rebin_sum)*100)
        #print(len(rebin_sum[rebin_sum>0]),len(rebin_sum))
        if len(rebin_sum[rebin_sum>0])/len(rebin_sum)*100 >= threshold:
            passed_threshold.append(i)

    print('Will use ' + str(len(passed_threshold)) + ' out of ' + str(len(dat_files)) + ' segments.')

    return np.array(passed_threshold), len(passed_threshold)

    Using the .dat files, rebin them into 1s bins, to weed out the segments below
    some desired threshold. Will return a *list* of *indices*! This is so that I
    can filter out the *sorted* array of .dat and .fft files that are below threshold!

    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!
    tbin_size - size of the time bin
    threshold - if data is under threshold (in percentage), then don't use the segment!
    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)
    
Using the .dat files, rebin them into 1s bins, to weed out the segments below
some desired threshold. Will return a *list* of *indices*. This is so that I
can filter out the *sorted* array of .dat and .fft files that are below threshold!

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.
tbin_size - size of the time bin
threshold - if data is under threshold (in percentage), then don't use the segment.
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)
Using the . dat files rebin them into 1s bins to weed out the segments below some desired threshold . Will return a * list * of * indices * . This is so that I can filter out the * sorted * array of . dat and . fft files that are below threshold! 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 . tbin_size - size of the time bin threshold - if data is under threshold ( in percentage ) then don ' t use the segment . 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 segment_threshold(eventfile,segment_length,demod,tbin_size,threshold,PI1,PI2,t1,t2):
    if demod != True and demod != False:
        raise ValueError("demod should either be True or False!")
    dat_files = presto_dat(eventfile,segment_length,demod,PI1,PI2,t1,t2)
    rebin_t = np.arange(segment_length+1)*1 
    passed_threshold = []
    print('Now finding the number of segments that can be used...')
    for i in tqdm(range(len(dat_files))):
        dat_file_data = np.fromfile(dat_files[i],dtype='<f',count=-1)
        data_t = np.arange(len(dat_file_data))*tbin_size
        rebin_sum,rebin_edges,rebin_trunc = stats.binned_statistic(data_t,dat_file_data,statistic='sum',bins=rebin_t)
        if len(rebin_sum[rebin_sum>0])/len(rebin_sum)*100 >= threshold:
            passed_threshold.append(i)
    print('Will use ' + str(len(passed_threshold)) + ' out of ' + str(len(dat_files)) + ' segments.')
    return np.array(passed_threshold), len(passed_threshold)
def segment_threshold ( eventfile , segment_length , demod , tbin_size , threshold , PI1 , PI2 , t1 , t2 ) : if demod != True and demod != False : raise ValueError ( "demod should either be True or False!" ) dat_files = presto_dat ( eventfile , segment_length , demod , PI1 , PI2 , t1 , t2 ) rebin_t = np . arange ( segment_length + 1 ) * 1 passed_threshold = [ ] print ( 'Now finding the number of segments that can be used...' ) for i in tqdm ( range ( len ( dat_files ) ) ) : dat_file_data = np . fromfile ( dat_files [ i ] , dtype = '<f' , count = - 1 ) data_t = np . arange ( len ( dat_file_data ) ) * tbin_size rebin_sum , rebin_edges , rebin_trunc = stats . binned_statistic ( data_t , dat_file_data , statistic = 'sum' , bins = rebin_t ) if len ( rebin_sum [ rebin_sum > 0 ] ) / len ( rebin_sum ) * 100 >= threshold : passed_threshold . append ( i ) print ( 'Will use ' + str ( len ( passed_threshold ) ) + ' out of ' + str ( len ( dat_files ) ) + ' segments.' ) return np . array ( passed_threshold ) , len ( passed_threshold )
Using the .dat files, rebin them into 1s bins, to weed out the segments below
some desired threshold.
Using the . dat files rebin them into 1s bins to weed out the segments below some desired threshold .
"""
    Using the .dat files, rebin them into 1s bins, to weed out the segments below
    some desired threshold. Will return a *list* of *indices*! This is so that I
    can filter out the *sorted* array of .dat and .fft files that are below threshold!

    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!
    tbin_size - size of the time bin
    threshold - if data is under threshold (in percentage), then don't use the segment!
    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)
    """ #1-second bins #print(str(pathlib.Path(dat_files[i]).name),len(rebin_sum[rebin_sum>0])/len(rebin_sum)*100) #print(len(rebin_sum[rebin_sum>0]),len(rebin_sum))
eventfile
segment_length
demod
tbin_size
threshold
PI1
PI2
t1
t2