Lv3_duty_cycle.py
def compare_segment_lengths(eventfile,tbin,segment_lengths,duty_cycle_bin):
    """
    To get the distribution of duty cycles over all segments, given an ObsID and
    a desired segment length! Compare through different thresholds!

    eventfile - path to the event file. Will extract ObsID from this for the NICER files.
    tbin - size of the bins in time
    segment_lengths - array of length of the individual segments
    duty_cycle_bin - binning used to calculate the duty cycle
    """
    parent_folder = str(pathlib.Path(eventfile).parent)

    thresholds = np.array([0.05,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9])
    store_threshold_y = []
    for i in range(len(seg_lengths)):
        duty_cycle_array = duty_cycle_dist(eventfile,tbin,segment_lengths[i],duty_cycle_bin,thresholds[i])
        above5 = len(duty_cycle_array[duty_cycle_array>0.05])/len(duty_cycle_array)
        above10 = len(duty_cycle_array[duty_cycle_array>0.1])/len(duty_cycle_array)
        above20 = len(duty_cycle_array[duty_cycle_array>0.2])/len(duty_cycle_array)
        above30 = len(duty_cycle_array[duty_cycle_array>0.3])/len(duty_cycle_array)
        above40 = len(duty_cycle_array[duty_cycle_array>0.4])/len(duty_cycle_array)
        above50 = len(duty_cycle_array[duty_cycle_array>0.5])/len(duty_cycle_array)
        above60 = len(duty_cycle_array[duty_cycle_array>0.6])/len(duty_cycle_array)
        above70 = len(duty_cycle_array[duty_cycle_array>0.7])/len(duty_cycle_array)
        above80 = len(duty_cycle_array[duty_cycle_array>0.8])/len(duty_cycle_array)
        above90 = len(duty_cycle_array[duty_cycle_array>0.9])/len(duty_cycle_array)
        threshold_y = np.array([above5,above10,above20,above30,above40,above50,above60,above70,above80,above90])
        store_threshold_y.append(threshold_y)

    for i in range(len(store_threshold_y)):
        plt.plot(thresholds,store_threshold_y[i],'x-',lw=0.5,alpha=0.5)
    plt.xlabel('Threshold',fontsize=12)
    plt.ylabel('Fraction of segments (for a given segment length)',fontsize=12)
    plt.legend((tuple(str(seg_lengths[i]) for i in range(len(seg_lengths)))),loc='best')
    plt.savefig(parent_folder+'/threshold_segmentlength.pdf',dpi=900,format='pdf')
    plt.close()

    To get the distribution of duty cycles over all segments, given an ObsID and
    a desired segment length! Compare through different thresholds!

    eventfile - path to the event file. Will extract ObsID from this for the NICER files.
    tbin - size of the bins in time
    segment_lengths - array of length of the individual segments
    duty_cycle_bin - binning used to calculate the duty cycle
    
To get the distribution of duty cycles over all segments, given an ObsID and
a desired segment length. Compare through different thresholds!

path to the event file. Will extract ObsID from this for the NICER files.
tbin - size of the bins in time
segment_lengths - array of length of the individual segments
duty_cycle_bin - binning used to calculate the duty cycle
To get the distribution of duty cycles over all segments given an ObsID and a desired segment length . Compare through different thresholds! path to the event file . Will extract ObsID from this for the NICER files . tbin - size of the bins in time segment_lengths - array of length of the individual segments duty_cycle_bin - binning used to calculate the duty cycle
def compare_segment_lengths(eventfile,tbin,segment_lengths,duty_cycle_bin):
    parent_folder = str(pathlib.Path(eventfile).parent)
    thresholds = np.array([0.05,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9])
    store_threshold_y = []
    for i in range(len(seg_lengths)):
        duty_cycle_array = duty_cycle_dist(eventfile,tbin,segment_lengths[i],duty_cycle_bin,thresholds[i])
        above5 = len(duty_cycle_array[duty_cycle_array>0.05])/len(duty_cycle_array)
        above10 = len(duty_cycle_array[duty_cycle_array>0.1])/len(duty_cycle_array)
        above20 = len(duty_cycle_array[duty_cycle_array>0.2])/len(duty_cycle_array)
        above30 = len(duty_cycle_array[duty_cycle_array>0.3])/len(duty_cycle_array)
        above40 = len(duty_cycle_array[duty_cycle_array>0.4])/len(duty_cycle_array)
        above50 = len(duty_cycle_array[duty_cycle_array>0.5])/len(duty_cycle_array)
        above60 = len(duty_cycle_array[duty_cycle_array>0.6])/len(duty_cycle_array)
        above70 = len(duty_cycle_array[duty_cycle_array>0.7])/len(duty_cycle_array)
        above80 = len(duty_cycle_array[duty_cycle_array>0.8])/len(duty_cycle_array)
        above90 = len(duty_cycle_array[duty_cycle_array>0.9])/len(duty_cycle_array)
        threshold_y = np.array([above5,above10,above20,above30,above40,above50,above60,above70,above80,above90])
        store_threshold_y.append(threshold_y)
    for i in range(len(store_threshold_y)):
        plt.plot(thresholds,store_threshold_y[i],'x-',lw=0.5,alpha=0.5)
    plt.xlabel('Threshold',fontsize=12)
    plt.ylabel('Fraction of segments (for a given segment length)',fontsize=12)
    plt.legend((tuple(str(seg_lengths[i]) for i in range(len(seg_lengths)))),loc='best')
    plt.savefig(parent_folder+'/threshold_segmentlength.pdf',dpi=900,format='pdf')
    plt.close()
def compare_segment_lengths ( eventfile , tbin , segment_lengths , duty_cycle_bin ) : parent_folder = str ( pathlib . Path ( eventfile ) . parent ) thresholds = np . array ( [ 0.05 , 0.1 , 0.2 , 0.3 , 0.4 , 0.5 , 0.6 , 0.7 , 0.8 , 0.9 ] ) store_threshold_y = [ ] for i in range ( len ( seg_lengths ) ) : duty_cycle_array = duty_cycle_dist ( eventfile , tbin , segment_lengths [ i ] , duty_cycle_bin , thresholds [ i ] ) above5 = len ( duty_cycle_array [ duty_cycle_array > 0.05 ] ) / len ( duty_cycle_array ) above10 = len ( duty_cycle_array [ duty_cycle_array > 0.1 ] ) / len ( duty_cycle_array ) above20 = len ( duty_cycle_array [ duty_cycle_array > 0.2 ] ) / len ( duty_cycle_array ) above30 = len ( duty_cycle_array [ duty_cycle_array > 0.3 ] ) / len ( duty_cycle_array ) above40 = len ( duty_cycle_array [ duty_cycle_array > 0.4 ] ) / len ( duty_cycle_array ) above50 = len ( duty_cycle_array [ duty_cycle_array > 0.5 ] ) / len ( duty_cycle_array ) above60 = len ( duty_cycle_array [ duty_cycle_array > 0.6 ] ) / len ( duty_cycle_array ) above70 = len ( duty_cycle_array [ duty_cycle_array > 0.7 ] ) / len ( duty_cycle_array ) above80 = len ( duty_cycle_array [ duty_cycle_array > 0.8 ] ) / len ( duty_cycle_array ) above90 = len ( duty_cycle_array [ duty_cycle_array > 0.9 ] ) / len ( duty_cycle_array ) threshold_y = np . array ( [ above5 , above10 , above20 , above30 , above40 , above50 , above60 , above70 , above80 , above90 ] ) store_threshold_y . append ( threshold_y ) for i in range ( len ( store_threshold_y ) ) : plt . plot ( thresholds , store_threshold_y [ i ] , 'x-' , lw = 0.5 , alpha = 0.5 ) plt . xlabel ( 'Threshold' , fontsize = 12 ) plt . ylabel ( 'Fraction of segments (for a given segment length)' , fontsize = 12 ) plt . legend ( ( tuple ( str ( seg_lengths [ i ] ) for i in range ( len ( seg_lengths ) ) ) ) , loc = 'best' ) plt . savefig ( parent_folder + '/threshold_segmentlength.pdf' , dpi = 900 , format = 'pdf' ) plt . close ( )
To get the distribution of duty cycles over all segments, given an ObsID and
a desired segment length!
To get the distribution of duty cycles over all segments given an ObsID and a desired segment length!
"""
    To get the distribution of duty cycles over all segments, given an ObsID and
    a desired segment length! Compare through different thresholds!

    eventfile - path to the event file. Will extract ObsID from this for the NICER files.
    tbin - size of the bins in time
    segment_lengths - array of length of the individual segments
    duty_cycle_bin - binning used to calculate the duty cycle
    """
eventfile
tbin
segment_lengths
duty_cycle_bin