コード例 #1
0
def test_star():
    os.chdir(os.path.join(home, "data/star"))
    specs = ['HD102070_spectra.fits', "HD102070_noflux.fits"]
    a = np.zeros((2,25))
    cs = ["k", "r"]
    fs = []
    for i, spec in enumerate(specs):
        star = pf.getdata(spec)
        w = wavelength_array(spec)
        # plt.plot(w, star/np.nanmedian(star), "-{0}".format(cs[i]))
        # check_ppxf(spec, velscale) # Velocity of stars is zero
        flux = lector.broad2lick(w, star, 2.1, vel=0.)
        sn = snr(flux)
        noise = np.ones_like(flux) * np.median(flux) / sn
        lick, lickerrs = lector.lector(w, flux, noise, bands,
                 vel = 0., cols=(0,8,2,3,4,5,6,7))
        a[i] = lick
        fs.append(interp1d(w, star/np.nanmedian(star), bounds_error=False, fill_value=0))
    # plt.show()
    # plt.clf()
    w = np.linspace(4850, 5780, 1000)
    p = np.poly1d(np.polyfit(w, fs[0](w) / fs[1](w), 20))
    # plt.plot(w, fs[0](w) / fs[1](w), "-k" )
    # plt.plot(w, p(w), "-r")
    # plt.show()
    cols = ["Index       ", "Calib", "Raw", "Sch07", "Delta", "%", "offset"]
    cols = ["{0:10s}".format(x) for x in cols]
    sch = data_schiavon07()
    model_table = os.path.join(tables_dir, \
                               "models_thomas_2010_metal_extrapolated.dat")
    lims, ranges = get_model_lims(model_table, factor=0)
    lims = np.diff(lims).T[0]
    print "Results for the test on standard star HD 102070"
    print "".join(cols)
    for j,index in enumerate(indices):
        if j < 12 or j>20:
            continue
        print "{0:6s}{1:10.2f}{2:10.2f}{6:10.2f}{3:10.2f}{4:10.2f}{5:10.2f}".format(index, \
                a[0][j],  a[1][j], (a[0][j] - a[1][j]),
                (a[0][j] - a[1][j])/ a[0][j], offset[j], sch[j])
    return w,p
コード例 #2
0
    for cols in lims:
        v = [x[cols[0]-1:cols[1]-1] for x in table]
        print v
    
if __name__ == "__main__":
    spectype = "single2"
    table = os.path.join(home, spectype, "results.tab")
    spec = np.genfromtxt(table, dtype=None, usecols=(0,))
    ids = [x.split("n3311")[-1].replace(".fits", "").replace("_", " ") for x \
           in spec]
    sns =  np.loadtxt(table, usecols=(14,))
    rs, pas = np.loadtxt(table, usecols=(3,4)).T
    # idx = np.where(sns > sn_cut)[0]
    cols = np.array([39,41,47,49,51,53,55])
    model_table = os.path.join(tables_dir, "models_thomas_2010.dat")
    lims, ranges = get_model_lims(model_table)
    idx = np.array([12,13,16,17,18,19])
    cols2 = np.array([69,72,75])
    lims = lims[idx]
    data = np.loadtxt(table, usecols=cols)
    errs = np.loadtxt(table, usecols=cols+1)
    pop = np.loadtxt(table, usecols=cols2)
    popm = pop - np.loadtxt(table, usecols=cols2 + 1)
    popp = np.loadtxt(table, usecols=cols2 + 2) - pop
    pstring = pm_string(pop, popm, popp)
    for i in range(len(data)):
        for j in range(len(lims)):
            if data[i,j] < lims[j,0] or data[i,j] > lims[j,1]:
                data[i,j] = np.nan
    results = []
    cds_table = []
コード例 #3
0
 else:
     idx3311 = np.where(r <= 10 ** (r_tran))[0]
     idxhalo = np.where(r > 10 ** (r_tran))[0]
 r3311 = r[idx3311]
 rhalo = r[idxhalo]
 lick3311 = lick[:, idx3311]
 lickhalo = lick[:, idxhalo]
 errs1_3311 = lickerr[:, idx3311]
 errs_halo = lickerr[:, idxhalo]
 #########################################################################
 # First figure, simple indices
 app = "_pa" if restrict_pa else ""
 mkfig1 = True
 gray = "0.75"
 ##########################################################################
 lims, ranges = get_model_lims(os.path.join(tables_dir, "models_thomas_2010_metal_extrapolated.dat"))
 idx = np.array([12, 13, 16, 17, 18, 19, 20])
 lims = lims[idx]
 # Setting the colormap properties for the scatter plots
 cmap = brewer2mpl.get_map("Blues", "sequential", 9).mpl_colormap
 cmap = nc.cmap_discretize(cmap, 3)
 color = cm.get_cmap(cmap)
 norm = Normalize(vmin=0, vmax=45)
 if mkfig1:
     plt.figure(1, figsize=(6, 14))
     gs = gridspec.GridSpec(7, 1)
     gs.update(left=0.15, right=0.95, bottom=0.1, top=0.94, wspace=0.1, hspace=0.09)
     tex = []
     for j, ll in enumerate(lick):
         # print indices[j], ranges[j], ssp.fn(9.,0.12,.4)[ii[j]]
         if j == 0:
コード例 #4
0
ファイル: plot_lick_radius.py プロジェクト: cebarbosa/hydra1
 else:
     idx3311 = np.where(r <= 10**(r_tran))[0]
     idxhalo = np.where(r > 10**(r_tran))[0]
 r3311 = r[idx3311]
 rhalo = r[idxhalo]
 lick3311 = lick[:, idx3311]
 lickhalo = lick[:, idxhalo]
 errs1_3311 = lickerr[:, idx3311]
 errs_halo = lickerr[:, idxhalo]
 #########################################################################
 # First figure, simple indices
 app = "_pa" if restrict_pa else ""
 mkfig1 = True
 gray = "0.75"
 ##########################################################################
 lims, ranges = get_model_lims(
     os.path.join(tables_dir, "models_thomas_2010_metal_extrapolated.dat"))
 idx = np.array([12, 13, 16, 17, 18, 19, 20])
 lims = lims[idx]
 # Setting the colormap properties for the scatter plots
 cmap = brewer2mpl.get_map('Blues', 'sequential', 9).mpl_colormap
 cmap = nc.cmap_discretize(cmap, 3)
 color = cm.get_cmap(cmap)
 norm = Normalize(vmin=0, vmax=45)
 if mkfig1:
     plt.figure(1, figsize=(6, 14))
     gs = gridspec.GridSpec(7, 1)
     gs.update(left=0.15,
               right=0.95,
               bottom=0.1,
               top=0.94,
               wspace=0.1,
コード例 #5
0
"""
import os

import numpy as np
import matplotlib.pyplot as plt

from config import *
from mcmc_model import get_model_lims

if __name__ == "__main__":
    os.chdir(os.path.join(home, "single2"))
    data1 = np.loadtxt("populations.txt",
                       usecols=(1, 2, 3, 5, 6, 7, 9, 10, 11))
    data2 = np.loadtxt("populations_miles.txt",
                       usecols=(1, 2, 3, 5, 6, 7, 9, 10, 11))
    lims, ranges = get_model_lims(os.path.join(tables_dir, "MILESII.txt"))
    ranges[0] = [9.8, 10.2]
    ranges[1] = [-1.5, 0.6]
    err_cut = np.array([0.2, 0.7, 0.22])
    fig = plt.figure(1, figsize=(14, 4.5))
    labels = [r"$\log$ Age (yr)", r"[Z/H]", r"[$\alpha$/Fe]"]
    plt.subplots_adjust(left=0.065,
                        right=0.98,
                        bottom=0.13,
                        top=0.97,
                        wspace=0.25)
    for i, j in enumerate([0, 3, 6]):
        idx1 = np.intersect1d(
            np.where(data1[:, j] >= ranges[i, 0])[0],
            np.where(data1[:, j] <= ranges[i, 1])[0])
        merr1 = 0.5 * np.abs((data1[:, j + 1] - data1[:, j + 2]))
コード例 #6
0
"""
import os

import numpy as np
import matplotlib.pyplot as plt

from config import *
from mcmc_model import get_model_lims



if __name__ == "__main__":
    os.chdir(os.path.join(home, "single2"))
    data1 = np.loadtxt("populations.txt", usecols=(1,2,3,5,6,7,9,10,11))
    data2 = np.loadtxt("populations_miles.txt", usecols=(1,2,3,5,6,7,9,10,11))
    lims, ranges = get_model_lims(os.path.join(tables_dir, "MILESII.txt"))
    ranges[0] = [9.8,10.2]
    ranges[1] = [-1.5, 0.6]
    err_cut = np.array([0.2, 0.7, 0.22])
    fig = plt.figure(1, figsize=(14, 4.5))
    labels = [r"$\log$ Age (yr)", r"[Z/H]", r"[$\alpha$/Fe]"]
    plt.subplots_adjust(left=0.065, right=0.98, bottom=0.13, top=0.97,
                        wspace=0.25)
    for i,j in enumerate([0,3,6]):
        idx1 = np.intersect1d(np.where(data1[:,j] >= ranges[i,0])[0],
                             np.where(data1[:,j] <= ranges[i,1])[0])
        merr1 = 0.5 * np.abs((data1[:,j+1] - data1[:,j+2]))
        merr2 = 0.5 * np.abs((data2[:,j+1] - data2[:,j+2]))
        merr = np.maximum(merr1, merr2)
        idx2 = np.where(merr <= err_cut[i])[0]
        idx = np.intersect1d(idx1, idx2)
コード例 #7
0
        if j < 12 or j>20:
            continue
        print indices[j],
        # print aflux[j],
        # print araw[j],
        # print lims[j]
        print "{0:10.2f}".format(np.median(aflux[j])),
        print "{0:10.2f}".format(np.median(araw[j])),
        print "{0:10.2f}".format(np.median((aflux[j] - araw[j])/(aflux[j])))

        # print "{0:6s}{1:10.2f}{2:10.2f}{6:10.2f}{3:10.2f}{4:10.2f}{5:10.2f}".format(index, \
        #         a[0][j],  a[1][j], (a[0][j] - a[1][j]),
        #         (a[0][j] - a[1][j])/ a[0][j], offset[j], sch[j])




if __name__ == "__main__":
    bands = os.path.join(tables_dir, "BANDS")
    offset = np.loadtxt(os.path.join(tables_dir,"LICK_OFFSETS.dat"),
                        usecols=(1,)).T
    indices = np.loadtxt(bands, usecols=(0,), dtype=str)
    model_table = os.path.join(tables_dir, \
                               "models_thomas_2010_metal_extrapolated.dat")
    lims, ranges = get_model_lims(model_table, factor=0)
    w,p = test_star()
    test_galaxy(w,p)



コード例 #8
0
ファイル: latex_lick_table.py プロジェクト: cebarbosa/hydra1
    for cols in lims:
        v = [x[cols[0]-1:cols[1]-1] for x in table]
        print v
    
if __name__ == "__main__":
    spectype = "single2"
    table = os.path.join(home, spectype, "results.tab")
    spec = np.genfromtxt(table, dtype=None, usecols=(0,))
    ids = [x.split("n3311")[-1].replace(".fits", "").replace("_", " ") for x \
           in spec]
    sns =  np.loadtxt(table, usecols=(14,))
    rs, pas = np.loadtxt(table, usecols=(3,4)).T
    # idx = np.where(sns > sn_cut)[0]
    cols = np.array([39,41,47,49,51,53,55])
    model_table = os.path.join(tables_dir, "models_thomas_2010.dat")
    lims, ranges = get_model_lims(model_table)
    idx = np.array([12,13,16,17,18,19])
    cols2 = np.array([69,72,75])
    lims = lims[idx]
    data = np.loadtxt(table, usecols=cols)
    errs = np.loadtxt(table, usecols=cols+1)
    pop = np.loadtxt(table, usecols=cols2)
    popm = pop - np.loadtxt(table, usecols=cols2 + 1)
    popp = np.loadtxt(table, usecols=cols2 + 2) - pop
    pstring = pm_string(pop, popm, popp)
    for i in range(len(data)):
        for j in range(len(lims)):
            if data[i,j] < lims[j,0] or data[i,j] > lims[j,1]:
                data[i,j] = np.nan
    results = []
    cds_table = []