コード例 #1
0
def gettmat():
    # Partial derivatives with respect to av and ebv
    av = 0.1
    ebv = 0.1 / 2.5
    A1 = f99_band.A_X(r_v=av / ebv, ebv=ebv)
    A2 = f99_band.A_X(r_v=(av + 0.01) / ebv, ebv=ebv)
    dAdAv = (A2 - A1) / 0.01

    A3 = f99_band.A_X(r_v=av / (ebv + 0.001), ebv=ebv + 0.001)
    dAdebv = (A3 - A1) / 0.001

    # print 'f99 derivatives'
    # print '{0[0]:6.2f}, {0[1]:6.2f}, {0[2]:6.2f}, {0[3]:6.2f}, {0[4]:6.2f}'.format(dAdAv)
    # print '{0[0]:6.2f}, {0[1]:6.2f}, {0[2]:6.2f}, {0[3]:6.2f}, {0[4]:6.2f}'.format(dAdebv)

    # The equation of interest is
    # gammma0 = ans00 F0 + ans01 F1 + res
    # gammma1 = ans10 F0 + ans11 F1 + res
    # where F are the Fitzpatrick vectors (partial derivatives above) and
    # the residues are perpendicular to a and b
    # Note that the gammas are really gamma_X/(gamma_B-gamma_V)

    norm_dAdebv = numpy.dot(dAdebv, dAdebv)
    norm_dAdAv = numpy.dot(dAdAv, dAdAv)
    cross = numpy.dot(dAdebv, dAdAv)

    a = numpy.array([[norm_dAdAv, cross], [cross, norm_dAdebv]])

    tmat = []
    res = []
    # c_n = []
    cs = []
    for s in ['gamma', 'rho1']:
        c, cmin, cmax = numpy.percentile(
            fit[s] / ((fit[s][:, 1] - fit[s][:, 2])[:, None]),
            (50, 50 - 34, 50 + 34),
            axis=0)
        # print s,
        # print "{:6.2f}, {:6.2f}, {:6.2f}, {:6.2f}, {:6.2f}".format(c[0],c[1],c[2],c[3],c[4])
        cs.append(c)
        # c_norm = numpy.linalg.norm(c)
        # c_n.append(c_norm)

        y = numpy.array([numpy.dot(c, dAdAv), numpy.dot(c, dAdebv)])
        ans = numpy.linalg.solve(a, y)

        tmat.append(ans)
        ans = c - ans[1] * dAdebv - ans[0] * dAdAv
        res.append(ans)

    tmat = numpy.array(tmat)
    gvec = numpy.array([[4.8, 3.89, 2.89, 2.22, 1.59],
                        [-3.83, -4.42, -5.42, -5.15, -4.71]])
    avec = numpy.array([[0.96, 1, 1, 0.97, 0.77],
                        [1.77, 0.98, 0.12, -0.50, -0.53]])
    return tmat
コード例 #2
0
        FancyArrowPatch.draw(self, renderer)


mpl.rcParams['font.size'] = 14

# Get the data
f = open('temp11.pkl', 'rb')
(fit, _) = pickle.load(f)
f.close()

# Determine the plane approximaion for Fitzpatrick

# Partial derivatives with respect to av and ebv
av = 0.1
ebv = 0.1 / 2.5
A1 = f99_band.A_X(r_v=av / ebv, ebv=ebv)

# pkl_file = open('fitz.pkl', 'r')
# a=pickle.load(pkl_file)
# pkl_file.close()

# AX = a[0]* av + a[1] * av**2 \
#   + a[2]* ebv+ a[3] * ebv**2 \
#   + a[4] * av* ebv \
#   + a[5]* av**3 \
#   + a[6] * ebv**3 \
#   + a[7] * (av**2) * ebv \
#   + a[8] * av * (ebv**2)

# plt.plot(A1-AX)
コード例 #3
0
import sncosmo
import scipy
from matplotlib.backends.backend_pdf import PdfPages
import matplotlib.pyplot as plt
import f99_band
import emcee
import matplotlib as mpl

mpl.rcParams['font.size'] = 14

# Determine the plane approximaion for Fitzpatrick

# Partial derivatives with respect to av and ebv
av = 0.1
ebv = 0.1 / 2.5
A1 = f99_band.A_X(r_v=av / ebv, ebv=ebv)

# pkl_file = open('fitz.pkl', 'r')
# a=pickle.load(pkl_file)
# pkl_file.close()

# AX = a[0]* av + a[1] * av**2 \
#   + a[2]* ebv+ a[3] * ebv**2 \
#   + a[4] * av* ebv \
#   + a[5]* av**3 \
#   + a[6] * ebv**3 \
#   + a[7] * (av**2) * ebv \
#   + a[8] * av * (ebv**2)

# plt.plot(A1-AX)
コード例 #4
0



correction = [fit['Delta']+ fit['c'][:,i][:,None] + fit['alpha'][:,i][:,None]*fit['EW'][:,:, 0] \
    + fit['beta'][:,i][:,None]*fit['EW'][:,:, 1] + fit['eta'][:,i][:,None]*fit['sivel']
    for i in xrange(5)]

correction = numpy.array(correction)
# correction = correction - correction[2,:,:]
# correction_median = numpy.median(correction,axis=1)
cind = [0, 1, 2, 3, 4]
cname = ['U', 'B', 'V', 'R', 'I']
mpl.rcParams['font.size'] = 14
import f99_band
A_X = f99_band.A_X(r_v=2.44, ebv=0.2 / 2.44)
A_X26 = A_X / (A_X[1] - A_X[2])
A_X = f99_band.A_X(r_v=2.1, ebv=0.2 / 2.1)
A_X21 = A_X / (A_X[1] - A_X[2])

fig, axes = plt.subplots(nrows=5)
for i in xrange(5):
    (y, ymin, ymax) = numpy.percentile(correction[cind[i], :, :],
                                       (50, 50 - 34, 50 + 34),
                                       axis=0)
    err = numpy.sqrt(color_cov[:, 1, 1] + ((ymax - ymin) / 2)**2)
    #axes[i,0].errorbar(y,y-color_obs[:,i],xerr=[((ymax-ymin)/2),((ymax-ymin)/2)], yerr=[err,err],fmt='.',alpha=0.4)
    #axes[i,0].errorbar(color_obs[:,i],y-color_obs[:,i],xerr=[numpy.sqrt(color_cov[:,i,i]),numpy.sqrt(color_cov[:,i,i])], yerr=[err,err],fmt='.',alpha=0.4)
    # axes[i,0].errorbar(color_obs[:,i],y,xerr=[numpy.sqrt(color_cov[:,i,i]),numpy.sqrt(color_cov[:,i,i])], yerr=[((ymax-ymin)/2),((ymax-ymin)/2)],fmt='.',alpha=0.4)
    axes[i].errorbar(
        mag_obs[:, 1] - mag_obs[:, 2],
コード例 #5
0
# gvec = numpy.array([[4.8,3.89,2.89,2.22,1.59],[-3.83,-4.42,-5.42,-5.15,-4.71]])
# avec = numpy.array([[0.96,1,1,0.97,0.77],[1.77,0.98,0.12,-0.50,-0.53]])
# # print avec[0]
# # print avec[1]
# # print tmat[0,0],tmat[0,1]
# print tmat[0,0]*avec[0]+tmat[0,1]*avec[1]
# print tmat[1,0]*avec[0]+tmat[1,1]*avec[1]
# test= gvec[0]*Egamma[0]+ gvec[1]*Egamma[1]
# print  test
# test= avec[0]*myavebv[0]+ avec[1]*myavebv[1]
# print test
# wwefwe

draw = numpy.random.multivariate_normal(myavebv, newmat, 100)

fidA1 = f99_band.A_X(r_v=myavebv[0] / myavebv[1], ebv=myavebv[1])
# fidA1 = numpy.delete(fidA1-fidA1[2],2)
temp = []
for a in draw:
    A1 = f99_band.A_X(r_v=a[0] / a[1], ebv=a[1])
    A1 = numpy.delete(A1 - A1[2], 2)
    # A1 = fidA1 + (A1-fidA1)*2
    temp.append(A1)
temp = numpy.array(temp)
tempperc = numpy.percentile(temp, (50, 50 - 34, 50 + 34), axis=0)

# wefwe
import sncosmo
# def lnprob(p, x, y ,yerr):
#    # p is ebv and r_v
#    f99 = sncosmo.F99Dust(r_v =p[1])