Lv1_spectra_txt.py
def plot_fit_table(tablefile,pars):
    """
    Plot the results from the fit_$MODEL.table tables

    table - the path to the table, which includes the model name
    pars - model parameters, in the form of a list
    """
    par_dict = {}
    error_dict = {}
    sigma_dict = {}

    filenames = np.genfromtxt(tablefile,dtype='str',usecols=(0),unpack=True)
    mjds = np.array([float(filenames[i][-25:-20]) for i in range(len(filenames))])
    no_cols = 1 + 4*len(pars) + 8

    counter = 0 #to keep track of the variable index; of the same order as in "pars"!
    for i in range(1,no_cols-8,4): #for the parameter value
        data_array = np.genfromtxt(tablefile,dtype='float',usecols=(i),unpack=True)
        par_dict[pars[counter]] = data_array
        counter += 1
    counter = 0 #to keep track of the variable index
    for i in range(2,no_cols-8,4): #for the sigma value
        data_array = np.genfromtxt(tablefile,dtype='float',usecols=(i),unpack=True)
        sigma_dict[pars[counter]] = data_array
        counter += 1
    counter = 0 #to keep track of the variable index
    for i in range(3,no_cols-8,4): #for the error value
        error_low, error_high = np.genfromtxt(tablefile,dtype='float',usecols=(i,i+1),unpack=True) #two arrays for lower and upper bound!
        error_dict[pars[counter]] = np.array([(error_low[j],error_high[j]) for j in range(len(error_low)) ])
        counter += 1

    cstat = np.genfromtxt(tablefile,dtype='float',usecols=(no_cols-8),unpack=True)
    dof = np.genfromtxt(tablefile,dtype='float',usecols=(no_cols-7),unpack=True)
    flux,flux_low,flux_high = np.genfromtxt(tablefile,dtype='float',usecols=(no_cols-6,no_cols-5,no_cols-4),unpack=True)
    lumin,lumin_low,lumin_high = np.genfromtxt(tablefile,dtype='float',usecols=(no_cols-3,no_cols-2,no_cols-1),unpack=True)*1e44

    ##### Plotting
    fig,axs = plt.subplots(len(pars)+3,sharex=True,gridspec_kw={'hspace':0})
    fig.suptitle('Total C-stat: ' + str(round(sum(cstat),4)) + '/' + str(sum(dof)))

    for i in range(len(pars)):
        axs[i].errorbar(x=mjds,y=par_dict[pars[i]],yerr=sigma_dict[pars[i]],color='r',fmt='x')
        axs[i].set_ylabel(pars[i])
    axs[2].set_yscale('log')
    axs[len(pars)].plot(mjds,lumin/1e39,'rx')
    axs[len(pars)].set_yscale('log')
    axs[len(pars)+1].plot(mjds,flux/1e-12,'rx')
    axs[len(pars)+1].set_yscale('log')
    axs[len(pars)+2].plot(mjds,cstat/dof,'rx')
    axs[len(pars)+2].axhline(y=1.0,lw=0.5,alpha=0.5)

    axs[len(pars)].set_ylabel('Luminosity \n 1e39 \n ergs/s)')
    axs[len(pars)+1].set_ylabel('Flux \n 1e-12 \n ergs/cm^2/s')
    axs[len(pars)+2].set_ylabel('Reduced \n C-stat')

    axs[len(pars)+2].set_xlabel('Time (MJD)',fontsize=12)

    plt.show()

    Plot the results from the fit_$MODEL.table tables

    table - the path to the table, which includes the model name
    pars - model parameters, in the form of a list
    
Plot the results from the fit_$MODEL.table tables
table - the path to the table, which includes the model name
pars - model parameters, in the form of a list
Plot the results from the fit_$MODEL . table tables table - the path to the table which includes the model name pars - model parameters in the form of a list
def plot_fit_table(tablefile,pars):
    par_dict = {}
    error_dict = {}
    sigma_dict = {}
    filenames = np.genfromtxt(tablefile,dtype='str',usecols=(0),unpack=True)
    mjds = np.array([float(filenames[i][-25:-20]) for i in range(len(filenames))])
    no_cols = 1 + 4*len(pars) + 8
    counter = 0 
    for i in range(1,no_cols-8,4): 
        data_array = np.genfromtxt(tablefile,dtype='float',usecols=(i),unpack=True)
        par_dict[pars[counter]] = data_array
        counter += 1
    counter = 0 
    for i in range(2,no_cols-8,4): 
        data_array = np.genfromtxt(tablefile,dtype='float',usecols=(i),unpack=True)
        sigma_dict[pars[counter]] = data_array
        counter += 1
    counter = 0 
    for i in range(3,no_cols-8,4): 
        error_low, error_high = np.genfromtxt(tablefile,dtype='float',usecols=(i,i+1),unpack=True) 
        error_dict[pars[counter]] = np.array([(error_low[j],error_high[j]) for j in range(len(error_low)) ])
        counter += 1
    cstat = np.genfromtxt(tablefile,dtype='float',usecols=(no_cols-8),unpack=True)
    dof = np.genfromtxt(tablefile,dtype='float',usecols=(no_cols-7),unpack=True)
    flux,flux_low,flux_high = np.genfromtxt(tablefile,dtype='float',usecols=(no_cols-6,no_cols-5,no_cols-4),unpack=True)
    lumin,lumin_low,lumin_high = np.genfromtxt(tablefile,dtype='float',usecols=(no_cols-3,no_cols-2,no_cols-1),unpack=True)*1e44
    fig,axs = plt.subplots(len(pars)+3,sharex=True,gridspec_kw={'hspace':0})
    fig.suptitle('Total C-stat: ' + str(round(sum(cstat),4)) + '/' + str(sum(dof)))
    for i in range(len(pars)):
        axs[i].errorbar(x=mjds,y=par_dict[pars[i]],yerr=sigma_dict[pars[i]],color='r',fmt='x')
        axs[i].set_ylabel(pars[i])
    axs[2].set_yscale('log')
    axs[len(pars)].plot(mjds,lumin/1e39,'rx')
    axs[len(pars)].set_yscale('log')
    axs[len(pars)+1].plot(mjds,flux/1e-12,'rx')
    axs[len(pars)+1].set_yscale('log')
    axs[len(pars)+2].plot(mjds,cstat/dof,'rx')
    axs[len(pars)+2].axhline(y=1.0,lw=0.5,alpha=0.5)
    axs[len(pars)].set_ylabel('Luminosity \n 1e39 \n ergs/s)')
    axs[len(pars)+1].set_ylabel('Flux \n 1e-12 \n ergs/cm^2/s')
    axs[len(pars)+2].set_ylabel('Reduced \n C-stat')
    axs[len(pars)+2].set_xlabel('Time (MJD)',fontsize=12)
    plt.show()
def plot_fit_table ( tablefile , pars ) : par_dict = { } error_dict = { } sigma_dict = { } filenames = np . genfromtxt ( tablefile , dtype = 'str' , usecols = ( 0 ) , unpack = True ) mjds = np . array ( [ float ( filenames [ i ] [ - 25 : - 20 ] ) for i in range ( len ( filenames ) ) ] ) no_cols = 1 + 4 * len ( pars ) + 8 counter = 0 for i in range ( 1 , no_cols - 8 , 4 ) : data_array = np . genfromtxt ( tablefile , dtype = 'float' , usecols = ( i ) , unpack = True ) par_dict [ pars [ counter ] ] = data_array counter += 1 counter = 0 for i in range ( 2 , no_cols - 8 , 4 ) : data_array = np . genfromtxt ( tablefile , dtype = 'float' , usecols = ( i ) , unpack = True ) sigma_dict [ pars [ counter ] ] = data_array counter += 1 counter = 0 for i in range ( 3 , no_cols - 8 , 4 ) : error_low , error_high = np . genfromtxt ( tablefile , dtype = 'float' , usecols = ( i , i + 1 ) , unpack = True ) error_dict [ pars [ counter ] ] = np . array ( [ ( error_low [ j ] , error_high [ j ] ) for j in range ( len ( error_low ) ) ] ) counter += 1 cstat = np . genfromtxt ( tablefile , dtype = 'float' , usecols = ( no_cols - 8 ) , unpack = True ) dof = np . genfromtxt ( tablefile , dtype = 'float' , usecols = ( no_cols - 7 ) , unpack = True ) flux , flux_low , flux_high = np . genfromtxt ( tablefile , dtype = 'float' , usecols = ( no_cols - 6 , no_cols - 5 , no_cols - 4 ) , unpack = True ) lumin , lumin_low , lumin_high = np . genfromtxt ( tablefile , dtype = 'float' , usecols = ( no_cols - 3 , no_cols - 2 , no_cols - 1 ) , unpack = True ) * 1e44 fig , axs = plt . subplots ( len ( pars ) + 3 , sharex = True , gridspec_kw = { 'hspace' : 0 } ) fig . suptitle ( 'Total C-stat: ' + str ( round ( sum ( cstat ) , 4 ) ) + '/' + str ( sum ( dof ) ) ) for i in range ( len ( pars ) ) : axs [ i ] . errorbar ( x = mjds , y = par_dict [ pars [ i ] ] , yerr = sigma_dict [ pars [ i ] ] , color = 'r' , fmt = 'x' ) axs [ i ] . set_ylabel ( pars [ i ] ) axs [ 2 ] . set_yscale ( 'log' ) axs [ len ( pars ) ] . plot ( mjds , lumin / 1e39 , 'rx' ) axs [ len ( pars ) ] . set_yscale ( 'log' ) axs [ len ( pars ) + 1 ] . plot ( mjds , flux / 1e-12 , 'rx' ) axs [ len ( pars ) + 1 ] . set_yscale ( 'log' ) axs [ len ( pars ) + 2 ] . plot ( mjds , cstat / dof , 'rx' ) axs [ len ( pars ) + 2 ] . axhline ( y = 1.0 , lw = 0.5 , alpha = 0.5 ) axs [ len ( pars ) ] . set_ylabel ( 'Luminosity \n 1e39 \n ergs/s)' ) axs [ len ( pars ) + 1 ] . set_ylabel ( 'Flux \n 1e-12 \n ergs/cm^2/s' ) axs [ len ( pars ) + 2 ] . set_ylabel ( 'Reduced \n C-stat' ) axs [ len ( pars ) + 2 ] . set_xlabel ( 'Time (MJD)' , fontsize = 12 ) plt . show ( )
Plot the results from the fit_$MODEL.table tables
table - the path to the table, which includes the model name
pars - model parameters, in the form of a list
Plot the results from the fit_$MODEL . table tables table - the path to the table which includes the model name pars - model parameters in the form of a list
"""
    Plot the results from the fit_$MODEL.table tables

    table - the path to the table, which includes the model name
    pars - model parameters, in the form of a list
    """ #to keep track of the variable index; of the same order as in "pars"! #for the parameter value #to keep track of the variable index #for the sigma value #to keep track of the variable index #for the error value #two arrays for lower and upper bound! ##### Plotting
tablefile
pars