当前位置: 首页>>代码示例>>Python>>正文


Python JLA_library.survey方法代码示例

本文整理汇总了Python中JLA_library.survey方法的典型用法代码示例。如果您正苦于以下问题:Python JLA_library.survey方法的具体用法?Python JLA_library.survey怎么用?Python JLA_library.survey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JLA_library的用法示例。


在下文中一共展示了JLA_library.survey方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: compute_diag

# 需要导入模块: import JLA_library [as 别名]
# 或者: from JLA_library import survey [as 别名]
def compute_diag(SNe):
    lens = 0.055
    #c = 3e5 #km/s
    sigma_lens = 0.055 * SNe['zcmb']
    sigma_pecvel = 5*8.33e-4/(np.log(10) *SNe['zcmb']) # See eq. 13 in B14
    sigma_coh = np.array([coh_dict[JLA.survey(sn)] for sn in SNe])
    return np.column_stack((sigma_coh, sigma_lens, sigma_pecvel))
开发者ID:dessn,项目名称:Covariance,代码行数:9,代码来源:jla_compute_diag_terms.py

示例2: apply

# 需要导入模块: import JLA_library [as 别名]
# 或者: from JLA_library import survey [as 别名]
    def apply(self, SNe, to_write=False):
        """ correction to SNe"""
        z_value, z_err = [], []

        for sn in SNe:
            c = SkyCoord(sn['ra']*u.degree, sn['dec']*u.degree)
            gc = c.galactic
            vpec = self.lookup_velocity(sn['zhel'], gc.l.degree, gc.b.degree)
            z_c = self.correct_redshift(sn['zhel'], vpec, gc.l.degree, gc.b.degree)
            z_plus = self.correct_redshift(sn['zhel'], self.r_plus*vpec,
                                           gc.l.degree, gc.b.degree)
            z_minus = self.correct_redshift(sn['zhel'], self.r_minus*vpec,
                                            gc.l.degree, gc.b.degree)
            if JLA.survey(sn) == 'nearby':
                z_value.append(z_c)
                z_err.append(np.mean([z_plus - z_c, z_c - z_minus]))
            else:
                z_value.append(sn['zcmb'])
                z_err.append(0)
                
        if to_write:
            np.savetxt('z_CMB_corrected.txt', np.array(z_value))
        return z_value, z_err
开发者ID:clidman,项目名称:Covariance,代码行数:25,代码来源:jla_compute_Cpecvel.py

示例3: compute_bias

# 需要导入模块: import JLA_library [as 别名]
# 或者: from JLA_library import survey [as 别名]

#.........这里部分代码省略.........
                                  dtype='S10,f8,f8,f8',
                                  names=['sample', 'redshift', 'bias', 'e_bias'])

    if options.plot:
        fig=plt.figure()
        ax=fig.add_subplot(111)
        colour={'nearby':'b','SNLS':'r','SDSS':'g','DES':'k'}

    for sample in numpy.unique(bias['sample']):
        selection=(bias['sample']==sample)
        guess=[0,0,0]

        print bias[selection]
        plsq=leastsq(residuals, guess, args=(bias[selection]['bias'],
                                             bias[selection]['redshift'],
                                             bias[selection]['e_bias'],
                                             'poly'), full_output=1)

        if plsq[4] in [1,2,3,4]:
            print 'Solution for %s found' % (sample)

        if options.plot:
            ax.errorbar(bias[selection]['redshift'],
                    bias[selection]['bias'],
                    yerr=bias[selection]['e_bias'],
                    ecolor='k',
                    color=colour[sample],
                    fmt='o',
                    label=sample)
            z=numpy.arange(numpy.min(bias[selection]['redshift']),numpy.max(bias[selection]['redshift']),0.001)
            ax.plot(z,poly(z,plsq[0]),color=colour[sample])

        # For each SNe, determine the uncerainty in the correction. We use the approach descibed in
        # https://www.astro.rug.nl/software/kapteyn/kmpfittutorial.html
        
        # Compute the chi-sq.
        chisq=(((bias[selection]['bias']-poly(bias[selection]['redshift'],plsq[0]))/bias[selection]['e_bias'])**2.).sum()
        dof=selection.sum()-len(guess)
        print "Reduced chi-square value for sample %s is %5.2e" % (sample, chisq / dof)

        alpha=0.315 # Confidence interval is 100 * (1-alpha)
        # Compute the upper alpha/2 value for the student t distribution with dof
        thresh=t.ppf((1-alpha/2.0), dof)
        
        if options.plot and sample!='nearby':
            # The following is only valid for polynomial fitting functions, and we do not compute it for the nearby sample
            upper_curve=[]
            lower_curve=[]
            for x in z:
                vect=numpy.matrix([1,x,x**2.])
                offset=thresh * numpy.sqrt(chisq / dof * (vect*numpy.matrix(plsq[1])*vect.T)[0,0])
                upper_curve.append(poly(x,plsq[0])+offset)
                lower_curve.append(poly(x,plsq[0])-offset)

            ax.plot(z,lower_curve,'--',color=colour[sample])
            ax.plot(z,upper_curve,'--',color=colour[sample])

        # Compute the error in the bias
        # We increase the absolute value
        # In other words, if the bias is negative, we subtract the error to make it even more negative
        # This is to get the correct sign in the off diagonal elements
        # We assume 100% correlation between SNe
        for i,SN in enumerate(SNe):
            if SN['zcmb'] > 0:
                redshift = SN['zcmb']
            else:
                redshift = SN['zhel']
            if JLA.survey(SN) == sample:
                # For the nearby SNe, the uncertainty in the bias correction is the bias correction itself
                if sample=='nearby':
                    SNe['e_bias'][i]=poly(redshift,plsq[0])
                    #print SN['name'],redshift, SNe['e_bias'][i]
                else:
                    vect = numpy.matrix([1,redshift,redshift**2.])
                    if poly(redshift,plsq[0]) > 0:
                        sign = 1
                    else:
                        sign = -1

                    SNe['e_bias'][i] = sign * thresh * numpy.sqrt(chisq / dof * (vect*numpy.matrix(plsq[1])*vect.T)[0,0])

                # We are getting some unrealistcally large values

    date = JLA.get_date()

    if options.plot:
        ax.legend()
        plt.savefig('C_bias_%s.png' % (date))
        plt.close()

    # Compute the bias matrix
    # 

    Zero=numpy.zeros(nSNe)
    H=numpy.concatenate((SNe['e_bias'],Zero,Zero)).reshape(3,nSNe).ravel(order='F')
    C_bias = numpy.matrix(H).T * numpy.matrix(H)

    fits.writeto('C_bias_%s.fits' % (date),C_bias,clobber=True) 

    return None
开发者ID:dessn,项目名称:Covariance,代码行数:104,代码来源:jla_compute_Cbias.py


注:本文中的JLA_library.survey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。