コード例 #1
0
ファイル: cosmicsfr.py プロジェクト: zpace/stellarmass_pca
def make_cosmic_sfr(CSP_dir):
    SFHs_fnames = glob.glob(os.path.join(CSP_dir, 'SFHs_*.fits'))
    nsubpersfh = fits.getval(SFHs_fnames[0], ext=0, keyword='NSUBPER')
    SFHs = np.row_stack(
        [fits.getdata(fn_, 'allsfhs') / fits.getdata(fn_, 'mformed')[::nsubpersfh, None]
         for fn_ in SFHs_fnames])
    ts = fits.getdata(SFHs_fnames[0], 'allts')
    zs, zmasks = zip(*[masked_z_at_value(WMAP9.age, t_ * u.Gyr) for t_ in ts])
    zs = np.ma.array(zs, mask=zmasks)

    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)

    SFRDmean = SFHs.mean(axis=0) / WMAP9.scale_factor(zs)**3.

    ax.plot(1. / WMAP9.scale_factor(zs), SFRDmean / SFRDmean.max())
    ax.set_xlim([1., 1. / WMAP9.scale_factor(10.)])
    ax.set_yscale('log')
    ax.set_ylim([.009, 1.05])
    ax.set_xlabel(r'$\frac{1}{a}$', size='x-small')
    ax.set_ylabel(r'$\log{\psi}$', size='x-small')
    ax.tick_params(labelsize='x-small', which='both')

    ax_ = ax.twiny()
    ax_.set_xlim(ax.get_xlim())
    zticks = np.linspace(0., 10., 11)
    inv_sf_ticks = 1. / WMAP9.scale_factor(zticks)
    ax_.set_xticks(inv_sf_ticks, minor=False)
    ax_.set_xticklabels(zticks)
    ax_.tick_params(labelsize='x-small')
    ax_.set_xlabel(r'$z$', size='x-small')

    fig.suptitle('``Cosmic" SFR', size='small')

    savefig(fig, 'CosmicSFR.png', CSP_dir, close=True)
コード例 #2
0
def grid(Nage=80, NZ=20, nebular=True, dust=False):
    """
    Generate grid of spectra with FSPS

    Returns:
        spec (array, float) spectra, dimensions NZ*Nage
        metallicities (array, float) metallicity array, units Z / Zsol
        scale_factors (array, flota) age array in units of the scale factor
        wl (array, float) wavelength array in Angstroms
    """

    if dust:
        sp = fsps.StellarPopulation(zcontinuous=1,
                                    sfh=0,
                                    logzsol=0.0,
                                    add_neb_emission=nebular,
                                    dust_type=2,
                                    dust2=0.2,
                                    cloudy_dust=True,
                                    dust1=0.0)
    else:
        sp = fsps.StellarPopulation(zcontinuous=1,
                                    sfh=0,
                                    cloudy_dust=True,
                                    logzsol=0.0,
                                    add_neb_emission=nebular)

    wl = np.array(sp.get_spectrum(tage=13, peraa=True)).T[:, 0]

    ages = np.logspace(-3.5,
                       np.log10(cosmo.age(0).value - 0.4),
                       num=Nage,
                       base=10)

    scale_factors = cosmo.scale_factor(
        [z_at_value(cosmo.lookback_time, age * u.Gyr) for age in ages])
    metallicities = np.linspace(-3, 1, num=NZ)  # log(Z / Zsol)

    spec = np.zeros((len(metallicities), len(ages), len(wl)))

    for i, Z in enumerate(metallicities):
        for j, a in enumerate(ages):

            sp.params['logzsol'] = Z
            if nebular: sp.params['gas_logz'] = Z

            spec[i, j] = sp.get_spectrum(tage=a, peraa=True)[1]  # Lsol / AA

    return spec, scale_factors, metallicities, wl
コード例 #3
0
ファイル: cosmicsfr.py プロジェクト: CSwigg/stellarmass_pca
def make_cosmic_sfr(CSP_dir):
    SFHs_fnames = glob.glob(os.path.join(CSP_dir, 'SFHs_*.fits'))
    nsubpersfh = fits.getval(SFHs_fnames[0], ext=0, keyword='NSUBPER')
    SFHs = np.row_stack([
        fits.getdata(fn_, 'allsfhs') /
        fits.getdata(fn_, 'mformed')[::nsubpersfh, None] for fn_ in SFHs_fnames
    ])
    ts = fits.getdata(SFHs_fnames[0], 'allts')
    zs, zmasks = zip(*[masked_z_at_value(WMAP9.age, t_ * u.Gyr) for t_ in ts])
    zs = np.ma.array(zs, mask=zmasks)

    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)

    SFRDmean = SFHs.mean(axis=0) / WMAP9.scale_factor(zs)**3.

    ax.plot(1. / WMAP9.scale_factor(zs), SFRDmean / SFRDmean.max())
    ax.set_xlim([1., 1. / WMAP9.scale_factor(10.)])
    ax.set_yscale('log')
    ax.set_ylim([.009, 1.05])
    ax.set_xlabel(r'$\frac{1}{a}$', size='x-small')
    ax.set_ylabel(r'$\log{\psi}$', size='x-small')
    ax.tick_params(labelsize='x-small', which='both')

    ax_ = ax.twiny()
    ax_.set_xlim(ax.get_xlim())
    zticks = np.linspace(0., 10., 11)
    inv_sf_ticks = 1. / WMAP9.scale_factor(zticks)
    ax_.set_xticks(inv_sf_ticks, minor=False)
    ax_.set_xticklabels(zticks)
    ax_.tick_params(labelsize='x-small')
    ax_.set_xlabel(r'$z$', size='x-small')

    fig.suptitle('``Cosmic" SFR', size='small')

    savefig(fig, 'CosmicSFR.png', CSP_dir, close=True)