Lv2_phase.py
def partial_subplots_E(eventfile,par_list,tbin_size,Ebin_size,f_pulse,shift,no_phase_bins,subplot_Es,E1,E2,mode):
    """
    Plot the pulse profile for a desired energy range.
    [Though I don't think this will be used much. Count/s vs energy is pointless,
    since we're not folding in response matrix information here to get the flux.
    So we're just doing a count/s vs time with an energy cut to the data.]
    INTERJECTION: This caveat is for the spectrum, NOT the pulse profile!

    eventfile - path to the event file. Will extract ObsID from this for the NICER files.
    par_list - A list of parameters we'd like to extract from the FITS file
    (e.g., from eventcl, PI_FAST, TIME, PI,)
    tbin_size - the size of the time bins (in seconds!)
    >> e.g., tbin_size = 2 means bin by 2s
    >> e.g., tbin_size = 0.05 means by in 0.05s
    Ebin_size - the size of the energy bins (in keV!)
    >> e.g., Ebin_size = 0.1 means bin by 0.1keV
    >> e.g., Ebin_size = 0.01 means bin by 0.01keV!
    f_pulse - the frequency of the pulse
    shift - how much to shift the pulse by in the phase axis.
    It only affects how it is presented.
    no_phase_bins - number of phase bins desired
    subplot_Es - list of tuples defining energy boundaries for pulse profiles
    E1 - lower energy boundary
    E2 - upper energy boundary
    """
    if type(eventfile) != str:
        raise TypeError("eventfile should be a string!")
    if 'TIME' not in par_list:
        raise ValueError("You should have 'TIME' in the parameter list!")
    if type(par_list) != list and type(par_list) != np.ndarray:
        raise TypeError("par_list should either be a list or an array!")
    if E2<E1:
        raise ValueError("E2 should be greater than E1!")
    if mode != 'show' and mode != 'save' and mode != 'overlap':
        raise ValueError("Mode should either be 'show' or 'save' or 'overlap'!")

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

    #should find a way to generalize calling p10,p20,etc in the future..!
    fig,(p10,p20,p30,p40,p50,p60) = plt.subplots(6,1)
    gs = gridspec.GridSpec(6,1)

    for i in range(len(subplot_Es)): #for each tuple of energy boundaries
        truncated_t, truncated_t_counts, truncated_E, truncated_E_counts = Lv1_data_bin.binning_E(eventfile,par_list,tbin_size,Ebin_size,subplot_Es[i][0],subplot_Es[i][1])
        phases, phase_bins, summed_profile = pulse_profile(pulse_pars[0],truncated_t[:-1],truncated_t_counts,shift,no_phase_bins)
        plt.subplot(gs[i]).plot(phase_bins[:-1],summed_profile,'-')

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

    fig.suptitle(str(obsid),fontsize=12)

    if mode != 'overlap':
        plt.figure()
    plt.xlabel('Phase', fontsize=12)
    plt.ylabel('Count/' + str(tbin_size) + 's',fontsize=12)

    if mode != 'overlap':
        plt.title('Pulse profile for ' + obj_name + ', ObsID ' + str(obsid)+ '\n Energy range: ' + str(E1) + 'keV - ' + str(E2) + 'keV',fontsize=12)

    if mode == 'show':
        plt.show()
    elif mode == 'save':
        filename = 'pp_subplots_' + obsid + '_bin' + str(tbin_size) + 's_' + str(E1) + 'keV-' + str(E2) + 'keV.pdf'
        plt.savefig(parent_folder+'/'+filename,dpi=900)
        plt.close()

    return phase_bins[:-1],summed_profile

    Plot the pulse profile for a desired energy range.
    [Though I don't think this will be used much. Count/s vs energy is pointless,
    since we're not folding in response matrix information here to get the flux.
    So we're just doing a count/s vs time with an energy cut to the data.]
    INTERJECTION: This caveat is for the spectrum, NOT the pulse profile!

    eventfile - path to the event file. Will extract ObsID from this for the NICER files.
    par_list - A list of parameters we'd like to extract from the FITS file
    (e.g., from eventcl, PI_FAST, TIME, PI,)
    tbin_size - the size of the time bins (in seconds!)
    >> e.g., tbin_size = 2 means bin by 2s
    >> e.g., tbin_size = 0.05 means by in 0.05s
    Ebin_size - the size of the energy bins (in keV!)
    >> e.g., Ebin_size = 0.1 means bin by 0.1keV
    >> e.g., Ebin_size = 0.01 means bin by 0.01keV!
    f_pulse - the frequency of the pulse
    shift - how much to shift the pulse by in the phase axis.
    It only affects how it is presented.
    no_phase_bins - number of phase bins desired
    subplot_Es - list of tuples defining energy boundaries for pulse profiles
    E1 - lower energy boundary
    E2 - upper energy boundary
    
Plot the pulse profile for a desired energy range.
[Though I don't think this will be used much. Count/s vs energy is pointless,
since we're not folding in response matrix information here to get the flux.
So we're just doing a count/s vs time with an energy cut to the data.]
INTERJECTION: This caveat is for the spectrum, NOT the pulse profile!

path to the event file. Will extract ObsID from this for the NICER files.
Plot the pulse profile for a desired energy range . [ Though I don ' t think this will be used much . Count / s vs energy is pointless since we ' re not folding in response matrix information here to get the flux . So we ' re just doing a count / s vs time with an energy cut to the data . ] INTERJECTION : This caveat is for the spectrum NOT the pulse profile! path to the event file . Will extract ObsID from this for the NICER files .
def partial_subplots_E(eventfile,par_list,tbin_size,Ebin_size,f_pulse,shift,no_phase_bins,subplot_Es,E1,E2,mode):
    if type(eventfile) != str:
        raise TypeError("eventfile should be a string!")
    if 'TIME' not in par_list:
        raise ValueError("You should have 'TIME' in the parameter list!")
    if type(par_list) != list and type(par_list) != np.ndarray:
        raise TypeError("par_list should either be a list or an array!")
    if E2<E1:
        raise ValueError("E2 should be greater than E1!")
    if mode != 'show' and mode != 'save' and mode != 'overlap':
        raise ValueError("Mode should either be 'show' or 'save' or 'overlap'!")
    parent_folder = str(pathlib.Path(eventfile).parent)
    fig,(p10,p20,p30,p40,p50,p60) = plt.subplots(6,1)
    gs = gridspec.GridSpec(6,1)
    for i in range(len(subplot_Es)): 
        truncated_t, truncated_t_counts, truncated_E, truncated_E_counts = Lv1_data_bin.binning_E(eventfile,par_list,tbin_size,Ebin_size,subplot_Es[i][0],subplot_Es[i][1])
        phases, phase_bins, summed_profile = pulse_profile(pulse_pars[0],truncated_t[:-1],truncated_t_counts,shift,no_phase_bins)
        plt.subplot(gs[i]).plot(phase_bins[:-1],summed_profile,'-')
    event_header = fits.open(eventfile)[1].header
    obj_name = event_header['OBJECT']
    obsid = event_header['OBS_ID']
    fig.suptitle(str(obsid),fontsize=12)
    if mode != 'overlap':
        plt.figure()
    plt.xlabel('Phase', fontsize=12)
    plt.ylabel('Count/' + str(tbin_size) + 's',fontsize=12)
    if mode != 'overlap':
        plt.title('Pulse profile for ' + obj_name + ', ObsID ' + str(obsid)+ '\n Energy range: ' + str(E1) + 'keV - ' + str(E2) + 'keV',fontsize=12)
    if mode == 'show':
        plt.show()
    elif mode == 'save':
        filename = 'pp_subplots_' + obsid + '_bin' + str(tbin_size) + 's_' + str(E1) + 'keV-' + str(E2) + 'keV.pdf'
        plt.savefig(parent_folder+'/'+filename,dpi=900)
        plt.close()
    return phase_bins[:-1],summed_profile
def partial_subplots_E ( eventfile , par_list , tbin_size , Ebin_size , f_pulse , shift , no_phase_bins , subplot_Es , E1 , E2 , mode ) : if type ( eventfile ) != str : raise TypeError ( "eventfile should be a string!" ) if 'TIME' not in par_list : raise ValueError ( "You should have 'TIME' in the parameter list!" ) if type ( par_list ) != list and type ( par_list ) != np . ndarray : raise TypeError ( "par_list should either be a list or an array!" ) if E2 < E1 : raise ValueError ( "E2 should be greater than E1!" ) if mode != 'show' and mode != 'save' and mode != 'overlap' : raise ValueError ( "Mode should either be 'show' or 'save' or 'overlap'!" ) parent_folder = str ( pathlib . Path ( eventfile ) . parent ) fig , ( p10 , p20 , p30 , p40 , p50 , p60 ) = plt . subplots ( 6 , 1 ) gs = gridspec . GridSpec ( 6 , 1 ) for i in range ( len ( subplot_Es ) ) : truncated_t , truncated_t_counts , truncated_E , truncated_E_counts = Lv1_data_bin . binning_E ( eventfile , par_list , tbin_size , Ebin_size , subplot_Es [ i ] [ 0 ] , subplot_Es [ i ] [ 1 ] ) phases , phase_bins , summed_profile = pulse_profile ( pulse_pars [ 0 ] , truncated_t [ : - 1 ] , truncated_t_counts , shift , no_phase_bins ) plt . subplot ( gs [ i ] ) . plot ( phase_bins [ : - 1 ] , summed_profile , '-' ) event_header = fits . open ( eventfile ) [ 1 ] . header obj_name = event_header [ 'OBJECT' ] obsid = event_header [ 'OBS_ID' ] fig . suptitle ( str ( obsid ) , fontsize = 12 ) if mode != 'overlap' : plt . figure ( ) plt . xlabel ( 'Phase' , fontsize = 12 ) plt . ylabel ( 'Count/' + str ( tbin_size ) + 's' , fontsize = 12 ) if mode != 'overlap' : plt . title ( 'Pulse profile for ' + obj_name + ', ObsID ' + str ( obsid ) + '\n Energy range: ' + str ( E1 ) + 'keV - ' + str ( E2 ) + 'keV' , fontsize = 12 ) if mode == 'show' : plt . show ( ) elif mode == 'save' : filename = 'pp_subplots_' + obsid + '_bin' + str ( tbin_size ) + 's_' + str ( E1 ) + 'keV-' + str ( E2 ) + 'keV.pdf' plt . savefig ( parent_folder + '/' + filename , dpi = 900 ) plt . close ( ) return phase_bins [ : - 1 ] , summed_profile
Plot the pulse profile for a desired energy range.
Plot the pulse profile for a desired energy range .
"""
    Plot the pulse profile for a desired energy range.
    [Though I don't think this will be used much. Count/s vs energy is pointless,
    since we're not folding in response matrix information here to get the flux.
    So we're just doing a count/s vs time with an energy cut to the data.]
    INTERJECTION: This caveat is for the spectrum, NOT the pulse profile!

    eventfile - path to the event file. Will extract ObsID from this for the NICER files.
    par_list - A list of parameters we'd like to extract from the FITS file
    (e.g., from eventcl, PI_FAST, TIME, PI,)
    tbin_size - the size of the time bins (in seconds!)
    >> e.g., tbin_size = 2 means bin by 2s
    >> e.g., tbin_size = 0.05 means by in 0.05s
    Ebin_size - the size of the energy bins (in keV!)
    >> e.g., Ebin_size = 0.1 means bin by 0.1keV
    >> e.g., Ebin_size = 0.01 means bin by 0.01keV!
    f_pulse - the frequency of the pulse
    shift - how much to shift the pulse by in the phase axis.
    It only affects how it is presented.
    no_phase_bins - number of phase bins desired
    subplot_Es - list of tuples defining energy boundaries for pulse profiles
    E1 - lower energy boundary
    E2 - upper energy boundary
    """ #should find a way to generalize calling p10,p20,etc in the future..! #for each tuple of energy boundaries
eventfile
par_list
tbin_size
Ebin_size
f_pulse
shift
no_phase_bins
subplot_Es
E1
E2
mode