Lv2_TBOs_method.py
def burst_cands(eventfile):
    """
    Identifies 1s bins which are burst candidates by adopting the method from Galloway+ 08;
    that is, looking for bins where the number of counts exceeds 4 sigma of the overall mean

    eventfile - path to the event file. Will extract ObsID from this for the NICER files.
    """
    parent_folder = str(pathlib.Path(eventfile).parent)

    event_header = fits.open(eventfile)[1].header
    obj_name = event_header['OBJECT']
    obsid = event_header['OBS_ID']

    data_dict = Lv0_fits2dict.fits2dict(eventfile,1,['TIME'])
    times = data_dict['TIME']
    counts = np.ones(len(times))

    gtis = Lv0_fits2dict.fits2dict(eventfile,2,['START','STOP'])
    starts = gtis['START']
    stops = gtis['STOP']
    T_obs = sum(np.array([ (gtis['STOP'][i]-gtis['START'][i]) for i in range(len(gtis)) ]))

    shifted_t = times-times[0]
    t_bins = np.linspace(0,np.ceil(shifted_t[-1]),np.ceil(shifted_t[-1])*1/1+1)
    binned_counts, bin_edges, binnumber = stats.binned_statistic(shifted_t,counts,statistic='sum',bins=t_bins) #binning the time values in the data

    mean_counts = np.mean(binned_counts)
    std_counts = np.std(binned_counts)

    burst_cand_text = open(parent_folder+'/' + obsid + '_burst_cands.txt','w')
    burst_cand_times = []
    for i in range(len(binned_counts)):
        if binned_counts[i] >= mean_counts + 3*std_counts: #e.g., mean + 4 sigma
            burst_cand_times.append(t_bins[i])
            burst_cand_text.write(str(t_bins[i]) + ' ')
            if i%10 == 0:
                burst_cand_text.write('\n')
    burst_cand_text.close()

    if len(burst_cand_times) != 0:
        with PdfPages(parent_folder+'/'+obsid+'_burst_cands.pdf') as pdf:
            plt.figure()
            plt.plot(burst_cand_times,np.ones(len(burst_cand_times))*np.max(binned_counts),'rx')
            plt.plot(t_bins[:-1],binned_counts,'b-')
            plt.legend(('Burst candidate bins','Data'),loc='best',fontsize=12)
            plt.title('Burst candidates for ' + obj_name + ' with ObsID ' + str(obsid) + '\n Mean counts: ' + str(round(mean_counts,2)) + ' ; std: ' + str(round(std_counts,2)),fontsize=12)
            plt.xlabel('Time (s)',fontsize=12)
            plt.xlim([burst_cand_times[0]-10,burst_cand_times[-1]+10])
            plt.ylabel('Count rate in counts/s',fontsize=12)
            pdf.savefig()
            plt.close()

    return

    Identifies 1s bins which are burst candidates by adopting the method from Galloway+ 08;
    that is, looking for bins where the number of counts exceeds 4 sigma of the overall mean

    eventfile - path to the event file. Will extract ObsID from this for the NICER files.
    
Identifies 1s bins which are burst candidates by adopting the method from Galloway+ 08;
that is, looking for bins where the number of counts exceeds 4 sigma of the overall mean

path to the event file. Will extract ObsID from this for the NICER files.
Identifies 1s bins which are burst candidates by adopting the method from Galloway + 08 ; that is looking for bins where the number of counts exceeds 4 sigma of the overall mean path to the event file . Will extract ObsID from this for the NICER files .
def burst_cands(eventfile):
    parent_folder = str(pathlib.Path(eventfile).parent)
    event_header = fits.open(eventfile)[1].header
    obj_name = event_header['OBJECT']
    obsid = event_header['OBS_ID']
    data_dict = Lv0_fits2dict.fits2dict(eventfile,1,['TIME'])
    times = data_dict['TIME']
    counts = np.ones(len(times))
    gtis = Lv0_fits2dict.fits2dict(eventfile,2,['START','STOP'])
    starts = gtis['START']
    stops = gtis['STOP']
    T_obs = sum(np.array([ (gtis['STOP'][i]-gtis['START'][i]) for i in range(len(gtis)) ]))
    shifted_t = times-times[0]
    t_bins = np.linspace(0,np.ceil(shifted_t[-1]),np.ceil(shifted_t[-1])*1/1+1)
    binned_counts, bin_edges, binnumber = stats.binned_statistic(shifted_t,counts,statistic='sum',bins=t_bins) 
    mean_counts = np.mean(binned_counts)
    std_counts = np.std(binned_counts)
    burst_cand_text = open(parent_folder+'/' + obsid + '_burst_cands.txt','w')
    burst_cand_times = []
    for i in range(len(binned_counts)):
        if binned_counts[i] >= mean_counts + 3*std_counts: 
            burst_cand_times.append(t_bins[i])
            burst_cand_text.write(str(t_bins[i]) + ' ')
            if i%10 == 0:
                burst_cand_text.write('\n')
    burst_cand_text.close()
    if len(burst_cand_times) != 0:
        with PdfPages(parent_folder+'/'+obsid+'_burst_cands.pdf') as pdf:
            plt.figure()
            plt.plot(burst_cand_times,np.ones(len(burst_cand_times))*np.max(binned_counts),'rx')
            plt.plot(t_bins[:-1],binned_counts,'b-')
            plt.legend(('Burst candidate bins','Data'),loc='best',fontsize=12)
            plt.title('Burst candidates for ' + obj_name + ' with ObsID ' + str(obsid) + '\n Mean counts: ' + str(round(mean_counts,2)) + ' ; std: ' + str(round(std_counts,2)),fontsize=12)
            plt.xlabel('Time (s)',fontsize=12)
            plt.xlim([burst_cand_times[0]-10,burst_cand_times[-1]+10])
            plt.ylabel('Count rate in counts/s',fontsize=12)
            pdf.savefig()
            plt.close()
    return
def burst_cands ( eventfile ) : parent_folder = str ( pathlib . Path ( eventfile ) . parent ) event_header = fits . open ( eventfile ) [ 1 ] . header obj_name = event_header [ 'OBJECT' ] obsid = event_header [ 'OBS_ID' ] data_dict = Lv0_fits2dict . fits2dict ( eventfile , 1 , [ 'TIME' ] ) times = data_dict [ 'TIME' ] counts = np . ones ( len ( times ) ) gtis = Lv0_fits2dict . fits2dict ( eventfile , 2 , [ 'START' , 'STOP' ] ) starts = gtis [ 'START' ] stops = gtis [ 'STOP' ] T_obs = sum ( np . array ( [ ( gtis [ 'STOP' ] [ i ] - gtis [ 'START' ] [ i ] ) for i in range ( len ( gtis ) ) ] ) ) shifted_t = times - times [ 0 ] t_bins = np . linspace ( 0 , np . ceil ( shifted_t [ - 1 ] ) , np . ceil ( shifted_t [ - 1 ] ) * 1 / 1 + 1 ) binned_counts , bin_edges , binnumber = stats . binned_statistic ( shifted_t , counts , statistic = 'sum' , bins = t_bins ) mean_counts = np . mean ( binned_counts ) std_counts = np . std ( binned_counts ) burst_cand_text = open ( parent_folder + '/' + obsid + '_burst_cands.txt' , 'w' ) burst_cand_times = [ ] for i in range ( len ( binned_counts ) ) : if binned_counts [ i ] >= mean_counts + 3 * std_counts : burst_cand_times . append ( t_bins [ i ] ) burst_cand_text . write ( str ( t_bins [ i ] ) + ' ' ) if i % 10 == 0 : burst_cand_text . write ( '\n' ) burst_cand_text . close ( ) if len ( burst_cand_times ) != 0 : with PdfPages ( parent_folder + '/' + obsid + '_burst_cands.pdf' ) as pdf : plt . figure ( ) plt . plot ( burst_cand_times , np . ones ( len ( burst_cand_times ) ) * np . max ( binned_counts ) , 'rx' ) plt . plot ( t_bins [ : - 1 ] , binned_counts , 'b-' ) plt . legend ( ( 'Burst candidate bins' , 'Data' ) , loc = 'best' , fontsize = 12 ) plt . title ( 'Burst candidates for ' + obj_name + ' with ObsID ' + str ( obsid ) + '\n Mean counts: ' + str ( round ( mean_counts , 2 ) ) + ' ; std: ' + str ( round ( std_counts , 2 ) ) , fontsize = 12 ) plt . xlabel ( 'Time (s)' , fontsize = 12 ) plt . xlim ( [ burst_cand_times [ 0 ] - 10 , burst_cand_times [ - 1 ] + 10 ] ) plt . ylabel ( 'Count rate in counts/s' , fontsize = 12 ) pdf . savefig ( ) plt . close ( ) return
Identifies 1s bins which are burst candidates by adopting the method from Galloway+ 08;
that is, looking for bins where the number of counts exceeds 4 sigma of the overall mean
Identifies 1s bins which are burst candidates by adopting the method from Galloway + 08 ; that is looking for bins where the number of counts exceeds 4 sigma of the overall mean
"""
    Identifies 1s bins which are burst candidates by adopting the method from Galloway+ 08;
    that is, looking for bins where the number of counts exceeds 4 sigma of the overall mean

    eventfile - path to the event file. Will extract ObsID from this for the NICER files.
    """ #binning the time values in the data #e.g., mean + 4 sigma
eventfile