Beispiel #1
0
def get_mhalo_mstar_fit(sim, mstar_min=9., order=1):
    gal_mstar = np.log10(
        np.array([i.masses['stellar'].in_units('Msun') for i in sim.galaxies]))
    gal_mhalo = np.log10(
        np.array(
            [i.halo.masses['total'].in_units('Msun') for i in sim.galaxies]))
    gal_cent = np.array([i.central for i in sim.galaxies])
    mstar_mask = gal_mstar > mstar_min

    mhalo_bins, median, lower, upper, ngals = runningmedian(
        gal_mhalo[gal_cent * mstar_mask], gal_mstar[gal_cent * mstar_mask])

    mhalo_bins = mhalo_bins[~np.isnan(median)]
    lower = lower[~np.isnan(median)]
    upper = upper[~np.isnan(median)]
    median = median[~np.isnan(median)]

    dof = len(mhalo_bins) - order
    coeffs = np.polyfit(mhalo_bins, median, order)

    model_vals = np.polyval(coeffs, mhalo_bins)
    chi_r = reduced_chi_squared(median, model_vals, np.minimum(lower, upper),
                                dof)
    print(f'Reduced Chi Squared = {chi_r}')
    print(f'Coefficients: {coeffs}')

    plot_model_fit(mhalo_bins, median, lower, upper, model_vals,
                   np.round(coeffs, 4),
                   f'plots/{model}_{wind}_{snap}_mhalo_mstar_deg_{order}.png')
    return coeffs
                        print('%d logM*= %.3f c= [%.3f,%.3f] rh2d= %.3f %.3f %.3f rh3d= %.3f' % \
                        (igal,np.log10(ms[igal]),cent[0],cent[1],rhalf_l[0][igal],rhalf_l[1][igal],rhalf_l[2][igal],mygals[igal].radii['stellar_half_mass']))
                    del mass, age, sZ, pos, lum
                    gc.collect()
            #print len(ms),len(sigv3d),len(sigmastar)
            rad_l = (rhalf_l[0] + rhalf_l[1] + rhalf_l[2]) / 3.
            rad_m = (rhalf_m[0] + rhalf_m[1] + rhalf_m[2]) / 3.

            with h5py.File(
                    data_dir + MODEL + '_' + WIND[0] + '_' + str(SNAP) +
                    '_data.h5', 'w') as hf:
                hf.create_dataset('halflight', data=np.array(rad_l))
                hf.create_dataset('halfmass', data=np.array(rad_m))

        condition = (central)
        massbin, cvecbin, ebinlo, ebinhi = pm.runningmedian(
            np.log10(ms[condition]), ssfr[condition])
        cvec = ssfr - np.interp(np.log10(ms), massbin, cvecbin)
        cmap = plt.get_cmap('jet_r')

        # plot half light radius against stellar mass

        print 'Plotting half light radius against stellar mass'

        fig, ax = plt.subplots()
        xvec = np.log10(ms[rad_l > 0])
        yvec = np.log10(rad_l[rad_l > 0])
        cvec = cvec[rad_l > 0]
        pixsize = 3 * (xvec / min(xvec) + 1)
        im = ax.scatter(xvec,
                        yvec,
                        c=cvec,
Beispiel #3
0
area = get_area(dr, n)
area_phys = gal_rad_tile**2.  * area 
area_total = np.sum(area_phys[:, :n], axis=1)
h1_mass = h1_surf_dens[:, :n] * area_phys
h2_mass = h2_surf_dens[:, :n] * area_phys
sfr = sfr_surf_dens[:, :n] * area_phys

gas_mass_total = np.sum(h1_mass, axis=1) + np.sum(h2_mass, axis=1)
sigma_h2 = np.log10(np.sum(h2_mass, axis=1) / area_total) - 6.
sigma_gas = np.log10(gas_mass_total / area_total) - 6.
sfr_total = np.sum(sfr, axis=1)
sigma_sfr = np.log10((sfr_total / area_total) + 10**-4.5) 

condition = (sigma_gas > 0.)

bin_cent,ymean,ysiglo,ysighi = pm.runningmedian(sigma_gas[condition], sigma_sfr[condition], stat='mean')

fig, ax = plt.subplots(figsize=(5, 4))

if snap == '151':
    plot_kennicutt(ax, labels=[r'$\Sigma_{\textrm{SFR}} \propto \Sigma_{\textrm{HI} + \textrm{H}_2}^{1.4}$'])
    ax.plot(bigiel_contour_1[0], bigiel_contour_1[1] * bigiel_imf_factor, c='k', lw=1, label='Bigiel+08')
    ax.plot(bigiel_contour_2[0], bigiel_contour_2[1] * bigiel_imf_factor, c='k', lw=1)
    ax.plot(bigiel_contour_3[0], bigiel_contour_3[1] * bigiel_imf_factor, c='k', lw=1)
    ax.plot(bigiel_contour_4[0], bigiel_contour_4[1] * bigiel_imf_factor, c='k', lw=1)
#ax.scatter(spirals_kennicutt_98[0], spirals_kennicutt_98[1] * bigiel_imf_factor, c='k', marker='o', s=10, label='Spirals, Kennicutt 98')
#ax.scatter(m51_kennicutt_07[0], m51_kennicutt_07[1], c='k', marker='+', s=14, label='M51, Kennicutt+07')

ax.plot(bin_cent, ymean, c='dodgerblue', lw=2.5, ls='--', label=r'$\textrm{HI} + \textrm{H}_2$')
im = ax.scatter(sigma_gas[gal_ssfr>-1.8], sigma_sfr[gal_ssfr> -1.8], c=gal_ssfr[gal_ssfr>-1.8], s=0.5, cmap =new_cmap)
cbar = fig.colorbar(im,ax=ax, label=r'$ \textrm{log} (sSFR / Gyr^{-1})$')
Beispiel #4
0
            f.create_dataset('stellar_mass', data=np.array(ms))
            f.create_dataset('sfr', data=np.array(sfr))
    else:
        with h5py.File(caesar_data, 'r') as f:
            central = f['central'][:]
            ms = f['stellar_mass'][:]
            sfr = f['sfr'][:]

    ssfr = np.log10(1.e9 * sfr / ms)
    ssfrlim = -1.8 + 0.3 * simba_z

    with h5py.File(rhalf_file, 'r') as r:
        rhalf = r[mtype + '_' + model + '_' + wind + '_' + snap][:]
    rhalf = np.sum(rhalf, axis=0) / 3.

    bin_cent, ymean, ysiglo, ysighi = pm.runningmedian(
        np.log10(ms[ssfr > ssfrlim]), np.log10(rhalf[ssfr > ssfrlim]))
    ax.plot(bin_cent, ymean, lines[i], lw=2, color='blue')
    bin_cent, ymean, ysiglo, ysighi = pm.runningmedian(
        np.log10(ms[ssfr < ssfrlim]), np.log10(rhalf[ssfr < ssfrlim]))
    ax.plot(bin_cent, ymean, lines[i], lw=2, color='m')

res_line = np.log10(2.8 * 0.5 / ((1 + simba_z) * 0.68))
ax.axhline(
    res_line,
    linestyle='--',
    color='k',
    lw=1.5,
)
plt.annotate('z=%g' % (np.round(simba_z, 1)),
             xy=(0.05, 0.93),
             xycoords='axes fraction',
        sfr = f['sfr'].value

if simba_z == 0.:
    rhalf_file = '/home/sapple/simba_sizes/sizes/data/pyloser_sdss_r.h5'
else:
    rhalf_file = '/home/sapple/simba_sizes/sizes/data/pyloser_v.h5'
with h5py.File(rhalf_file, 'r') as r:
    rhalf = r[mtype+'_'+model+'_'+wind+'_'+snap].value
rhalf = np.sum(rhalf, axis=0) / 3
	
ssfr = 1.e9*sfr/ms
ssfr = np.log10(ssfr)
ssfrlim = -1.8+0.3*simba_z

# plot simba galaxy points
massbin,cvecbin,ebinlo,ebinhi = pm.runningmedian(np.log10(ms[central]),ssfr[central])
simba_x = np.log10(ms[rhalf>0])  
simba_y = np.log10(rhalf[rhalf>0])
simba_c = ssfr - np.interp(np.log10(ms),massbin,cvecbin)
simba_c = ssfr
simba_c[simba_c < -2.5] = -2.5
simba_c[simba_c > 1.] = 1.

pixsize = 1*(simba_x-min(simba_x))+0.5
	
im = ax.scatter(simba_x, simba_y, c=simba_c, s=pixsize, lw=0, cmap=cmap)
		
# plot simba red and blue/ all galaxies
if simba_z <= 2.5:
    bin_cent,ymean,ysiglo,ysighi = pm.runningmedian(np.log10(ms[ssfr>ssfrlim]),np.log10(rhalf[ssfr>ssfrlim]))
    ax.plot(bin_cent,ymean,'--',lw=4,color='dodgerblue', label='Star forming')   
Beispiel #6
0
    plt.axhline(1., linestyle='--', color='m')
    plt.ylabel(r'$\textrm{HI surface density}$')
    plt.xlabel(r'$R (\textrm{kpc})$')
    plt.title(title)
    plt.xlim(0, )
    plt.savefig(results_dir + '/profiles/h1_profile_gal_' + str(gal_ids[i]) +
                '.png')
    plt.clf()

with h5py.File(
        results_dir + '/' + model + '_' + wind + '_' + snap + '_h1_data.h5',
        'a') as f:
    f.create_dataset('gal_ids', data=np.array(gal_ids))
    f.create_dataset('h1_radii', data=np.array(h1_radii))
    f.create_dataset('h1_mass', data=np.array(gal_h1m[mask]))

bin_cent, ymean, ysiglo, ysighi = pm.runningmedian(np.log10(gal_h1m[mask]),
                                                   h1_radii)
plt.scatter(np.log10(gal_h1m[mask]),
            h1_radii,
            c=richness[mask],
            s=1.,
            cmap='jet_r')
plt.colorbar(label=r'$\textrm{log} (M_{HI} / M_*)$')
plt.plot(bin_cent, ymean, '--', lw=3, color='g')
plt.xlabel(r'$\textrm{log} (M_{HI} / M_{\odot})$')
plt.ylabel(r'$R_{HI} (\textrm{kpc})$')
plt.savefig(results_dir + '/' + model + '_' + wind + '_' + snap +
            '_h1_size_mass.png')
plt.clf()
Beispiel #7
0
    pixsize = 1 * (np.log10(ms) - min(np.log10(ms))) + 0.5

    ax = fig.add_subplot(3, 2, i + 1)
    im = ax.scatter(np.log10(ms),
                    conc,
                    c=simba_c,
                    s=pixsize,
                    lw=0,
                    cmap=cmap,
                    label='Simba')
    cbar = fig.colorbar(
        im, ax=ax, label=r'$\textrm{log} (\textrm{sSFR} / \textrm{Gyr}^{-1})$')
    cbar.ax.tick_params(labelsize=10)

    if simba_z[i] <= 1.5:
        bin_cent, ymean, ysiglo, ysighi = pm.runningmedian(
            np.log10(ms[ssfr > ssfrlim]), conc[ssfr > ssfrlim])
        ax.plot(bin_cent, ymean, '--', lw=4, color='c', label='Star forming')
        bin_cent, ymean, ysiglo, ysighi = pm.runningmedian(
            np.log10(ms[ssfr < ssfrlim]), conc[ssfr < ssfrlim])
        ax.plot(bin_cent, ymean, '--', lw=4, color='m', label='Passive')

    else:
        bin_cent, ymean, ysiglo, ysighi = pm.runningmedian(np.log10(ms), conc)
        ax.plot(bin_cent, ymean, '--', lw=4, color='b', label='Simba')

    ax.annotate('z=%g' % (np.round(simba_z[i], 1)),
                xy=(0.1, 0.9),
                xycoords='axes fraction',
                size=16,
                bbox=dict(boxstyle="round", fc="w"))
    ax.minorticks_on()
Beispiel #8
0
    #print len(ms),len(sigv3d),len(sigmastar)
    logms = np.log10(ms)
    logmbh = np.log10(mbh)
    logsig = np.log10(np.asarray(sigv3d))
    logms_sat = np.log10(ms_sat)
    logmbh_sat = np.log10(mbh_sat)
    logsig_sat = np.log10(sigmastar)
    Zmet = np.log10(met/0.0189+1.e-6)
    ssfr = 1.e9*sfr/ms
    ssfr = np.log10(ssfr+10**(-2.5+0.3*redshift))
    pixcolor = np.log10(rad)
    pixsize = 4*(np.log10(ms/min(ms))+1)

    cvec = np.log10(rad)
    cvec_sat = np.log10(rad_sat)
    massbin,cvecbin,ebinlo,ebinhi = pm.runningmedian(np.log10(ms[sfr>0]),np.log10(rad[sfr>0]))
    cvec = cvec - np.interp(np.log10(ms),massbin,cvecbin)
    cvec_sat = cvec_sat - np.interp(np.log10(ms_sat),massbin,cvecbin)

    if iwind==0: 
        #ax.plot(logms,logsig_sat, 'x', c='grey', ms=1, label='Sats')
        im = ax.scatter(logms,logsig, c=cvec, s=pixsize, lw=0, cmap=plt.cm.jet_r, label='Centrals')
        fig.colorbar(im,ax=ax,label=r'$\Delta r_*$ (kpc)')
        im.set_clim(-0.2,0.2)
    else: im = ax.scatter(logms_sat, logsig_sat, c='k', s=pixsize, lw=0)
    #plt.plot(logms,Zmet,ms=1,lw=0,c='r')
    #print logms,Zmet

#plot_data(0)
#plot_data(0,'.')
Beispiel #9
0
with h5py.File(profs_file, 'r') as f:
    h1_h2_m = np.log10(f['h2_m'].value[mask] +
                       f['h1_m'].value[mask]) - 6.  # go from kpc to pc
    sfr = np.log10(f['sfr'].value[mask] + 1.e-6)

n = sfr.shape[1]
dr = 0.2
factor = dr * n
bins = np.arange(0., factor, dr)
rplot = bins + (dr * 0.5)
rplot = np.tile(rplot, len(sfr))

h1_h2_m = h1_h2_m.flatten()
sfr = sfr.flatten()
bin_cent, ymean, ysiglo, ysighi = pm.runningmedian(h1_h2_m[h1_h2_m > -1],
                                                   sfr[h1_h2_m > -1],
                                                   stat='mean')

fig, ax = plt.subplots()
plot_kennicutt(ax, labels=['Kennicutt 1998', 'Bigiel 2008'])
ax.plot(bin_cent, ymean, c='m', lw=2.5, ls='--')
im = ax.scatter(h1_h2_m.flatten(),
                sfr.flatten(),
                c=rplot,
                s=0.5,
                cmap=new_cmap)
cbar = fig.colorbar(im, ax=ax, label=r'$ R / R_{half}$')
ax.set_xlabel(
    r'$ \textrm{log} (\Sigma _{HI + H2}/ M_{\odot}\textrm{pc}^{-2}) $')
ax.set_ylabel(
    r'$ \textrm{log} (\Sigma _{\textrm{SFR}}/ M_{\odot}\textrm{yr}^{-1} \textrm{kpc}^{-2}) $'