예제 #1
0
    
#     TrendLine0 =  Axis1.plot(TrendX, out.beta[0]*TrendX+out.beta[1], '--', color = ListofElements[i][3], label='Real Error regresion')
    plt.errorbar(Metal_Abund, Y_Mass, xerr=Metal_Error, yerr=Y_Mass_Error, linestyle='None', marker='x', color = Colors[2][i+1])
    
#     A = np.vstack([Metal_Abund, np.ones(len(Metal_Abund))]).T
#     cHBeta_Old, n_Old = np.linalg.lstsq(A, Y_Mass)[0]        
#     TrendLine_NoError = Axis1.plot(TrendX, cHBeta_Old*TrendX+n_Old, ':', color=ListofElements[i][3])
    
    
#     data2 = RealData(Metal_Abund, Y_Mass, sx=Metal_Error_10, sy=Y_Mass_Error_10)
#     odr2 = ODR(data2, linear_model, beta0=[0., 1.])
#     out2 = odr2.run()
#     TrendLine1 =  Axis1.plot(TrendX, out2.beta[0]*TrendX+out2.beta[1], ':', color = ListofElements[i][3], label='10 % Error regression')
    
    #New method
    Regression_Fit, Uncertainty_Matrix, Red_Chi_Sq, Residuals = linfit(np.array(Metal_Abund), np.array(Y_Mass), np.array(Y_Mass_Error), cov=True, relsigma=False, chisq=True, residuals=True)
    m_n_error = [np.sqrt(Uncertainty_Matrix[t,t]) for t in range(2)] 
    R_Factor = Uncertainty_Matrix[0,1]/(m_n_error[0]*m_n_error[1])

    cHbeta, cHbeta_error = Regression_Fit[0], m_n_error[0]
    n, n_error = Regression_Fit[1], m_n_error[1]
    print len(Metal_Abund)
    print len(Regression_Fit[0]*np.array(Metal_Abund))
    TrendLine2 = Axis1.plot(TrendX, Regression_Fit[0]*TrendX + Regression_Fit[1], color=Colors[2][i+1], label=ListofElements[i][3], linestyle='--')

#    Nesmen method
    a,b,aerr,berr,covab=RN.bces(Metal_Abund,Metal_Error,Y_Mass,Y_Mass_Error,cov)
    
    for k in range(len(Object_Vector)):
        Label_point = Object_Vector[k]
        Axis1.annotate(Label_point, xy=(Metal_Abund[k],Y_Mass[k]), xytext = (Metal_Abund[k],Y_Mass[k]+0.01), textcoords= 'data',fontsize=8, color = Colors[1])
                            marker='x',
                            color=Colors[2][0 + 1])
# NitrogenLine = AxHor1.errorbar(ElementsResults[1][0], ElementsResults[1][2], xerr=ElementsResults[1][1], yerr=ElementsResults[1][3], linestyle='None', marker='x', color = Colors[2][0+2])
SulphurLine = AxHor2.errorbar(ElementsResults[2][0],
                              ElementsResults[2][2],
                              xerr=ElementsResults[2][1],
                              yerr=ElementsResults[2][3],
                              linestyle='None',
                              marker='x',
                              color=Colors[2][0 + 3])

# Oxygen
O_Regression_Fit, O_Uncertainty_Matrix, Red_Chi_Sq, Residuals = linfit(
    np.array(ElementsResults[0][0]),
    np.array(ElementsResults[0][2]),
    np.array(ElementsResults[0][3]),
    cov=True,
    relsigma=False,
    chisq=True,
    residuals=True)
O_m_n_error = [np.sqrt(O_Uncertainty_Matrix[t, t]) for t in range(2)]
O_n, O_n_error = O_Regression_Fit[1], O_m_n_error[1]

# Nitrogen
N_Regression_Fit, N_Uncertainty_Matrix, Red_Chi_Sq, Residuals = linfit(
    np.array(ElementsResults[1][0]),
    np.array(ElementsResults[1][2]),
    np.array(ElementsResults[1][3]),
    cov=True,
    relsigma=False,
    chisq=True,
    residuals=True)
예제 #3
0
# AxHor1.xaxis.set_ticks_position('bottom')
# AxHor1.xaxis.set_label_position('bottom')
# AxHor1.spines['bottom'].set_position(('outward', 45))

AxHor2.set_frame_on(True)
AxHor2.patch.set_visible(False)
AxHor2.xaxis.set_ticks_position('bottom')
AxHor2.xaxis.set_label_position('bottom')
AxHor2.spines['bottom'].set_position(('outward', 45))

OxygenLine = Axis1.errorbar(ElementsResults[0][0], ElementsResults[0][2], xerr=ElementsResults[0][1], yerr=ElementsResults[0][3], linestyle='None', marker='x', color = Colors[2][0+1])
# NitrogenLine = AxHor1.errorbar(ElementsResults[1][0], ElementsResults[1][2], xerr=ElementsResults[1][1], yerr=ElementsResults[1][3], linestyle='None', marker='x', color = Colors[2][0+2])
SulphurLine = AxHor2.errorbar(ElementsResults[2][0], ElementsResults[2][2], xerr=ElementsResults[2][1], yerr=ElementsResults[2][3], linestyle='None', marker='x', color = Colors[2][0+3])

# Oxygen
O_Regression_Fit, O_Uncertainty_Matrix, Red_Chi_Sq, Residuals = linfit(np.array(ElementsResults[0][0]), np.array(ElementsResults[0][2]), np.array(ElementsResults[0][3]), cov=True, relsigma=False, chisq=True, residuals=True)
O_m_n_error = [np.sqrt(O_Uncertainty_Matrix[t,t]) for t in range(2)] 
O_n, O_n_error = O_Regression_Fit[1], O_m_n_error[1]

# Nitrogen
N_Regression_Fit, N_Uncertainty_Matrix, Red_Chi_Sq, Residuals = linfit(np.array(ElementsResults[1][0]), np.array(ElementsResults[1][2]), np.array(ElementsResults[1][3]), cov=True, relsigma=False, chisq=True, residuals=True)
N_m_n_error = [np.sqrt(N_Uncertainty_Matrix[t,t]) for t in range(2)] 
N_n, N_n_error = N_Regression_Fit[1], N_m_n_error[1]

# Sulphur
S_Regression_Fit, S_Uncertainty_Matrix, Red_Chi_Sq, Residuals = linfit(np.array(ElementsResults[2][0]), np.array(ElementsResults[2][2]), np.array(ElementsResults[2][3]), cov=True, relsigma=False, chisq=True, residuals=True)
S_m_n_error = [np.sqrt(S_Uncertainty_Matrix[t,t]) for t in range(2)] 
S_n, S_n_error = S_Regression_Fit[1], S_m_n_error[1]

Axis1.set_ylim(0.10, 0.50)
Axis1.set_xlim(0, np.max(ElementsResults[0][0])*1.10)
예제 #4
0
        for o in range(NumberRecombinationRatios):
            x[o] = f_lambda[o] - f_Beta
            y[o] = math.log10(TheoRatio[o]/ObsRatio[o])
                
        y_and_error = unumpy.log10(TheoRatio / (FluxEL_and_error/HBeta_and_Error))
        y_err=unumpy.std_devs(y_and_error)  
        
        y_err = y_err[0]
        
        #Old method   
        A = np.vstack([x, np.ones(len(x))]).T
        cHBeta_Old, n_Old = np.linalg.lstsq(A, y)[0]
        TrendLine =  Axis1.plot(x, cHBeta_Old*x+n_Old, color=Colors[2][1], label='Fitted line')

        #New method
        Regression_Fit, Uncertainty_Matrix, Red_Chi_Sq, Residuals = linfit(x, y, y_err, cov=True, relsigma=False, chisq=True, residuals=True)
        m_n_error = [np.sqrt(Uncertainty_Matrix[t,t]) for t in range(2)] 
        R_Factor = Uncertainty_Matrix[0,1]/(m_n_error[0]*m_n_error[1])
    
        cHbeta, cHbeta_error = Regression_Fit[0], m_n_error[0]
        n, n_error = Regression_Fit[1], m_n_error[1]
        TrendLine2 = Axis1.plot(x, Regression_Fit[0]*x+Regression_Fit[1], color=Colors[2][2], label='Fitted line 2')
        
#       gs = gridspec.GridSpec(2, 1, height_ratios=[1.5, 8])
# 
#       Axis1 = Fig1.add_subplot(gs[1])
#       Axis2 = Fig1.add_subplot(gs[0])
                
#       Plotting axis

        PlotVector = mp.LinePlotter(Axis1, x, y, "Coefficients", PlotVector, Colors[2][0], LineFormat=None, MarkerFormat = 'o' , YError=list(y_err), ErrorBarsColor = Colors[1])