Lv2_phase.py
def partial_tE(eventfile,par_list,tbin_size,Ebin_size,pulse_pars,shift,no_phase_bins,t1,t2,E1,E2,mode):
    """
    Plot the pulse profile for a desired time interval and desired energy range.

    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!
    pulse_pars - parameters corresponding to 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
    t1 - lower time boundary
    t2 - upper time boundary
    E1 - lower energy boundary
    E2 - upper energy boundary
    mode - whether we want to show or save the plot

    pulse_pars will have [f,fdot,fdotdot]
    """
    if type(eventfile) != str:
        raise TypeError("eventfile should be a string!")
    if type(pulse_pars) != list and type(pulse_pars) != np.ndarray:
        raise TypeError("pulse_pars should either be a list or an array!")
    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 t2<t1:
        raise ValueError("t2 should be greater than t1!")
    if mode != 'show' and mode != 'save':
        raise ValueError("Mode should either be 'show' or 'save'!")

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

    data_dict = Lv0_fits2dict.fits2dict(eventfile,1,par_list)
    gtis = Lv0_fits2dict.fits2dict(eventfile,2,['START','STOP'])
    T = sum([ (gtis['STOP'][i]-gtis['START'][i]) for i in range(len(gtis['START'])) ])

    if pulse_pars[1] == 0 and pulse_pars[2] == 0:
        truncated_t, truncated_t_counts, truncated_E, truncated_E_counts = Lv1_data_bin.binning_tE(eventfile,par_list,tbin_size,Ebin_size,t1,t2,E1,E2)
        phases, phase_bins, summed_profile = pulse_profile(pulse_pars[0],truncated_t[:-1],truncated_t_counts,shift,no_phase_bins)
    else:
        phase_bins, summed_profile = pulse_folding(truncated_t,T,0,pulse_pars[0],pulse_pars[1],pulse_pars[2],no_phase_bins)

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

    if mode != 'overlap':
        plt.figure()
        plt.title('Pulse profile for ' + obj_name + ', ObsID ' + str(obsid)+ '\n Time interval: ' + str(t1) + 's - ' + str(t2) + 's'+ '\n Energy range: ' + str(E1) + 'keV - ' + str(E2) + 'keV',fontsize=12)
#    plt.plot(phase_bins[:-1], summed_profile*(times[-1]-times[0])/T)
    plt.step(phase_bins[:-1],summed_profile*(times[-1]-times[0])/T)
    plt.xlabel('Phase', fontsize=12)
    plt.ylabel('Count/' + str(tbin_size) + 's',fontsize=12)

    if mode == 'show':
        plt.show()

    elif mode == 'save':
        filename = 'pp_' + obsid + '_bin' + str(tbin_size) + 's_' + str(t1) + 's-' + str(t2) + '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 time interval and desired energy range.

    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!
    pulse_pars - parameters corresponding to 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
    t1 - lower time boundary
    t2 - upper time boundary
    E1 - lower energy boundary
    E2 - upper energy boundary
    mode - whether we want to show or save the plot

    pulse_pars will have [f,fdot,fdotdot]
    
Plot the pulse profile for a desired time interval and desired energy range.
eventfile - path to the event file. Will extract ObsID from this for the NICER files.

pulse_pars will have [f,fdot,fdotdot]
Plot the pulse profile for a desired time interval and desired energy range . eventfile - path to the event file . Will extract ObsID from this for the NICER files . pulse_pars will have [ f fdot fdotdot ]
def partial_tE(eventfile,par_list,tbin_size,Ebin_size,pulse_pars,shift,no_phase_bins,t1,t2,E1,E2,mode):
    if type(eventfile) != str:
        raise TypeError("eventfile should be a string!")
    if type(pulse_pars) != list and type(pulse_pars) != np.ndarray:
        raise TypeError("pulse_pars should either be a list or an array!")
    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 t2<t1:
        raise ValueError("t2 should be greater than t1!")
    if mode != 'show' and mode != 'save':
        raise ValueError("Mode should either be 'show' or 'save'!")
    parent_folder = str(pathlib.Path(eventfile).parent)
    data_dict = Lv0_fits2dict.fits2dict(eventfile,1,par_list)
    gtis = Lv0_fits2dict.fits2dict(eventfile,2,['START','STOP'])
    T = sum([ (gtis['STOP'][i]-gtis['START'][i]) for i in range(len(gtis['START'])) ])
    if pulse_pars[1] == 0 and pulse_pars[2] == 0:
        truncated_t, truncated_t_counts, truncated_E, truncated_E_counts = Lv1_data_bin.binning_tE(eventfile,par_list,tbin_size,Ebin_size,t1,t2,E1,E2)
        phases, phase_bins, summed_profile = pulse_profile(pulse_pars[0],truncated_t[:-1],truncated_t_counts,shift,no_phase_bins)
    else:
        phase_bins, summed_profile = pulse_folding(truncated_t,T,0,pulse_pars[0],pulse_pars[1],pulse_pars[2],no_phase_bins)
    event_header = fits.open(eventfile)[1].header
    obj_name = event_header['OBJECT']
    obsid = event_header['OBS_ID']
    if mode != 'overlap':
        plt.figure()
        plt.title('Pulse profile for ' + obj_name + ', ObsID ' + str(obsid)+ '\n Time interval: ' + str(t1) + 's - ' + str(t2) + 's'+ '\n Energy range: ' + str(E1) + 'keV - ' + str(E2) + 'keV',fontsize=12)
    plt.step(phase_bins[:-1],summed_profile*(times[-1]-times[0])/T)
    plt.xlabel('Phase', fontsize=12)
    plt.ylabel('Count/' + str(tbin_size) + 's',fontsize=12)
    if mode == 'show':
        plt.show()
    elif mode == 'save':
        filename = 'pp_' + obsid + '_bin' + str(tbin_size) + 's_' + str(t1) + 's-' + str(t2) + '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_tE ( eventfile , par_list , tbin_size , Ebin_size , pulse_pars , shift , no_phase_bins , t1 , t2 , E1 , E2 , mode ) : if type ( eventfile ) != str : raise TypeError ( "eventfile should be a string!" ) if type ( pulse_pars ) != list and type ( pulse_pars ) != np . ndarray : raise TypeError ( "pulse_pars should either be a list or an array!" ) 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 t2 < t1 : raise ValueError ( "t2 should be greater than t1!" ) if mode != 'show' and mode != 'save' : raise ValueError ( "Mode should either be 'show' or 'save'!" ) parent_folder = str ( pathlib . Path ( eventfile ) . parent ) data_dict = Lv0_fits2dict . fits2dict ( eventfile , 1 , par_list ) gtis = Lv0_fits2dict . fits2dict ( eventfile , 2 , [ 'START' , 'STOP' ] ) T = sum ( [ ( gtis [ 'STOP' ] [ i ] - gtis [ 'START' ] [ i ] ) for i in range ( len ( gtis [ 'START' ] ) ) ] ) if pulse_pars [ 1 ] == 0 and pulse_pars [ 2 ] == 0 : truncated_t , truncated_t_counts , truncated_E , truncated_E_counts = Lv1_data_bin . binning_tE ( eventfile , par_list , tbin_size , Ebin_size , t1 , t2 , E1 , E2 ) phases , phase_bins , summed_profile = pulse_profile ( pulse_pars [ 0 ] , truncated_t [ : - 1 ] , truncated_t_counts , shift , no_phase_bins ) else : phase_bins , summed_profile = pulse_folding ( truncated_t , T , 0 , pulse_pars [ 0 ] , pulse_pars [ 1 ] , pulse_pars [ 2 ] , no_phase_bins ) event_header = fits . open ( eventfile ) [ 1 ] . header obj_name = event_header [ 'OBJECT' ] obsid = event_header [ 'OBS_ID' ] if mode != 'overlap' : plt . figure ( ) plt . title ( 'Pulse profile for ' + obj_name + ', ObsID ' + str ( obsid ) + '\n Time interval: ' + str ( t1 ) + 's - ' + str ( t2 ) + 's' + '\n Energy range: ' + str ( E1 ) + 'keV - ' + str ( E2 ) + 'keV' , fontsize = 12 ) plt . step ( phase_bins [ : - 1 ] , summed_profile * ( times [ - 1 ] - times [ 0 ] ) / T ) plt . xlabel ( 'Phase' , fontsize = 12 ) plt . ylabel ( 'Count/' + str ( tbin_size ) + 's' , fontsize = 12 ) if mode == 'show' : plt . show ( ) elif mode == 'save' : filename = 'pp_' + obsid + '_bin' + str ( tbin_size ) + 's_' + str ( t1 ) + 's-' + str ( t2 ) + '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 time interval and desired energy range.
Plot the pulse profile for a desired time interval and desired energy range .
"""
    Plot the pulse profile for a desired time interval and desired energy range.

    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!
    pulse_pars - parameters corresponding to 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
    t1 - lower time boundary
    t2 - upper time boundary
    E1 - lower energy boundary
    E2 - upper energy boundary
    mode - whether we want to show or save the plot

    pulse_pars will have [f,fdot,fdotdot]
    """ #    plt.plot(phase_bins[:-1], summed_profile*(times[-1]-times[0])/T)
eventfile
par_list
tbin_size
Ebin_size
pulse_pars
shift
no_phase_bins
t1
t2
E1
E2
mode