Пример #1
0
def test_spec_resolution():
    """Plot the velocity widths for different spectral resolutions"""
    halo = myname.get_name(7)
    #Higher resolution spectrum
    hspec = ps.VWPlotSpectra(3, halo, savefile="grid_spectra_DLA.hdf5")
    hspec2 = ps.VWPlotSpectra(3, halo, savefile="grid_spectra_DLA_res.hdf5")
    plot_check(hspec, hspec2, "specres")
Пример #2
0
def test_big_box():
    """Plot the velocity widths for different size boxes"""
    halo = myname.get_name(0)
    halobig = path.expanduser("~/data/Illustris")
    hspec = ps.VWPlotSpectra(3, halo, label="DEF")
    hspec2 = ps.VWPlotSpectra(59, halobig, label="ILLUS")
    plot_check(hspec, hspec2, "bigbox")
Пример #3
0
def test_min_wind():
    """Plot the velocity widths for minimum wind velocity"""
    halo = myname.get_name(7)
    halo10 = myname.get_name(5)
    zz = 3
    hspec = ps.VWPlotSpectra(zz, halo, label="DEF")
    hspec2 = ps.VWPlotSpectra(zz, halo10, label="SLIKE")
    plot_check(hspec, hspec2, "minwind", zz)
Пример #4
0
def test_shield():
    """Plot velocity width for spectra using self-shielding like in Tescari 2009"""
    halo = myname.get_name(7)
    hspec = ps.VWPlotSpectra(3, halo)
    hspec2 = ps.VWPlotSpectra(3,
                              halo,
                              savefile="grid_spectra_DLA_noshield.hdf5")
    plot_check(hspec, hspec2, "no_shield")
Пример #5
0
def test_vel_abswidth():
    """Plot the velocity widths for different minimum absorber widths"""
    halo = myname.get_name(7)
    #Higher resolution spectrum
    hspec = ps.VWPlotSpectra(3, halo)
    hspec2 = ps.VWPlotSpectra(3, halo)
    hspec2.minwidth = 250.
    plot_check(hspec, hspec2, "abswidth")
Пример #6
0
def test_metal():
    """Plot the velocity widths for metal enrichment"""
    halo = myname.get_name(7)
    halo10 = myname.get_name(8)
    zz = 3
    hspec = ps.VWPlotSpectra(zz, halo, label="DEF")
    hspec2 = ps.VWPlotSpectra(zz, halo10, label="ENRICH")
    plot_check(hspec, hspec2, "enrich", zz)
Пример #7
0
def test_box_resolution():
    """Plot the velocity widths for different size boxes"""
    halo = myname.get_name(7)
    halo10 = myname.get_name(5, box=10)
    #     for zz in (1,3,5):
    zz = 3
    hspec = ps.VWPlotSpectra(zz, halo, label="DEF")
    hspec2 = ps.VWPlotSpectra(zz, halo10, label="SMALL")
    plot_check(hspec, hspec2, "box", zz)
Пример #8
0
def test_atten():
    """Plot the effect of the self-shielding correction"""
    halo = myname.get_name(7)
    hspec = ps.VWPlotSpectra(3, halo, label="ATTEN")
    hspec2 = ps.VWPlotSpectra(3,
                              halo,
                              savefile="grid_spectra_DLA_no_atten.hdf5",
                              label="NOATTEN")
    plot_check(hspec, hspec2, "no_atten")
Пример #9
0
def test_gfm_shield():
    """Plot the velocity widths for dynamical self-shielding vs post-processed self-shielding."""
    halo = myname.get_name(7)
    halo2 = myname.get_name('B')
    hspec = ps.VWPlotSpectra(3, halo, label="2xUV")
    hspec2 = ps.VWPlotSpectra(3, halo2, label="NOSHIELD")
    plot_check(hspec, hspec2, "gfm_shield")
    hspec = ps.VWPlotSpectra(5, halo, label="2xUV")
    hspec2 = ps.VWPlotSpectra(5, halo2, label="NOSHIELD")
    plot_check(hspec, hspec2, "gfm_shield", snap=5)
Пример #10
0
def plot_vel_width_SiII_keating(sim, snap):
    """
       Plot the change in velocity widths between the full calculation and
       setting n(Si+)/n(Si) = n(HI)/n(H)
    """
    halo = myname.get_name(sim)
    #Load from a save file only
    hspec = ps.VWPlotSpectra(snap, halo)
    hspecSi2 = ps.VWPlotSpectra(snap, halo, savefile="si_colden_spectra.hdf5")
    plot_check(hspec, hspecSi2, "SiHI_keating")
Пример #11
0
def test_tophat():
    """Plot the velocity widths with and with top hat vs SPH"""
    halo = myname.get_name(7)
    #Higher resolution spectrum
    hspec = ps.VWPlotSpectra(3, halo, savefile="grid_spectra_DLA.hdf5")
    hspec2 = ps.VWPlotSpectra(3,
                              halo,
                              None,
                              None,
                              savefile="grid_spectra_DLA_tophat.hdf5")
    plot_check(hspec, hspec2, "tophat")
Пример #12
0
def test_pecvel():
    """Plot the velocity widths with and without peculiar velocities"""
    halo = myname.get_name(7)
    #Higher resolution spectrum
    hspec = ps.VWPlotSpectra(3, halo, savefile="grid_spectra_DLA.hdf5")
    hspec2 = ps.VWPlotSpectra(3,
                              halo,
                              None,
                              None,
                              savefile="grid_spectra_DLA_pecvel.hdf5")
    plot_check(hspec, hspec2, "pecvel")
Пример #13
0
def test_lowres():
    """Plot the velocity widths with and with top hat vs SPH"""
    halo = myname.get_name(0)
    halolow = myname.get_name(0, ff=False)
    #Higher resolution spectrum
    hspec = ps.VWPlotSpectra(3, halo, savefile="grid_spectra_DLA.hdf5")
    hspec2 = ps.VWPlotSpectra(60,
                              halolow,
                              None,
                              None,
                              savefile="rand_spectra_DLA.hdf5")
    plot_check(hspec, hspec2, "lowres")
Пример #14
0
def plot_vel_widths_sims(sim):
    """Plot some velocity width data at a particular redshift"""
    #Load sims
    halo = "modified_128_a" + str(sim) + "_b1"
    hspec0 = ps.VWPlotSpectra(17, base + halo)
    hspec2 = ps.VWPlotSpectra(25, base + halo)
    hspec3 = ps.VWPlotSpectra(36, base + halo)
    #Make abs. plot
    hspec0.plot_vel_width("Si", 2, color="blue", ls="-")
    hspec2.plot_vel_width("Si", 2, color="orange", ls="--")
    hspec3.plot_vel_width("Si", 2, color="red", ls="-.")
    vel_data.plot_prochaska_2008_data()
    save_figure(path.join(outdir, "cosmo_velw_" + str(sim) + "_metal_zz"))
    plt.clf()
Пример #15
0
def plot_vel_width_SiII(sim, snap):
    """
       Plot the change in velocity widths between the full calculation and
       setting n(Si+)/n(Si) = n(HI)/n(H)
    """
    #Load from a save file only
    halo = myname.get_name(5, box=10)
    hspec_tesc = ps.VWPlotSpectra(
        snap, halo, savefile="halo_spectra_2.hdf5"
    )  #,cdir=path.expanduser("~/codes/cloudy_tables/ion_out_no_atten/"))
    hspec_tesc.plot_vel_width("Si", 2, color="green", ls="-.")
    halo = myname.get_name(sim)
    hspec = ps.VWPlotSpectra(snap, halo)
    hspecSi = ps.VWPlotSpectra(snap, halo, savefile="SiHI_spectra.hdf5")
    plot_check(hspec, hspecSi, "SiHI")
Пример #16
0
def get_hspec(sim, snap, box=25):
    """Get a spectra object, possibly from the cache"""
    halo = myname.get_name(sim, True, box=box)
    #Load from a save file only
    try:
        hspec = hspec_cache[(halo, snap)]
    except KeyError:
        hspec = ps.VWPlotSpectra(snap, halo, label=labels[sim])
        hspec_cache[(halo, snap)] = hspec
    return hspec
Пример #17
0
def plot_vel_widths_cloudy():
    """Plot some velocity width data for different cloudy models"""
    #Load sims
    hspec0 = ps.VWPlotSpectra(3, myname.get_name(0, True))
    hspec1 = ps.VWPlotSpectra(3,
                              myname.get_name(0, True),
                              savefile="rand_spectra_DLA_fancy_atten.hdf5")
    #Make abs. plot
    hspec0.plot_vel_width("Si", 2, color="blue", ls="--")
    hspec1.plot_vel_width("Si", 2, color="red", ls="-")
    vel_data.plot_prochaska_2008_data()
    save_figure(path.join(outdir, "cosmo_feedback_cloudy_z3"))
    plt.clf()
    #Make rel plot
    (vbin, vels0) = hspec0.vel_width_hist("Si", 2)
    (vbin, vels2) = hspec1.vel_width_hist("Si", 2)
    mm = np.min((np.size(vels2), np.size(vels0)))
    plt.semilogx(vbin[:mm], vels0[:mm] / vels2[:mm], color="blue", ls="-")
    plt.xlim(1, 1000)
    save_figure(path.join(outdir, "cosmo_rel_vel_cloudy_z3"))
    plt.clf()
Пример #18
0
def test_tescari_halos(sim, snap):
    """Plot velocity width for spectra through the center of halos, like in Tescari 2009"""
    halo = myname.get_name(sim, box=10)
    hspec = ps.VWPlotSpectra(
        snap,
        halo,
        savefile="halo_spectra_2.hdf5",
        cdir=path.expanduser("~/codes/cloudy_tables/ion_out_no_atten/"))
    hspec.plot_vel_width("Si", 2, color="red")
    vel_data.plot_prochaska_2008_data()
    save_figure(path.join(outdir, "cosmo_tescari_halos"))
    plt.clf()
Пример #19
0
def plot_vel_widths_metal():
    """Plot some velocity width data at a particular redshift"""
    #Load sims
    colorss = {1: "blue", 4: "purple", 3: "orange", 5: "red"}
    for sim in (1, 4, 5):
        halo = "modified_128_a" + str(sim) + "_b1"
        hspec0 = ps.VWPlotSpectra(25, base + halo)
        #Make abs. plot
        hspec0.plot_vel_width("Si", 2, color=colorss[sim], ls="-")
    vel_data.plot_prochaska_2008_data()
    save_figure(path.join(outdir, "cosmo_velw_metal_load"))
    plt.clf()
Пример #20
0
def plot_vel_metals(sim, snap, ff=True):
    """Plot the correlation between metallicity and velocity width"""
    halo = myname.get_name(sim, ff)
    #Load from a save file only
    hspec = ps.VWPlotSpectra(snap, halo)
    met = hspec.get_metallicity()
    vel = hspec.vel_width("Si", 2)
    (H, xedges, yedges) = np.histogram2d(np.log10(met),
                                         np.log10(vel),
                                         bins=30,
                                         normed=True)
    extent = [yedges[0], yedges[-1], xedges[-1], xedges[0]]
    plt.imshow(H, extent=extent, aspect="auto")
    plt.colorbar()
Пример #21
0
def plot_max_den(sim, snap, ff=True):
    """Load a simulation and plot the max metal density vs the max HI density"""
    halo = myname.get_name(sim, ff)
    #Load from a save file only
    hspec = ps.VWPlotSpectra(snap, halo, None, None)
    metal_den = np.max(hspec.get_density("Si", 2), axis=1)
    HI_den = np.max(hspec.get_density("H", 1), axis=1)
    ind = hspec.get_filt("Si", 2)
    (H, xedges, yedges) = np.histogram2d(np.log10(metal_den[ind]),
                                         np.log10(HI_den[ind]),
                                         bins=30,
                                         normed=True)
    extent = [yedges[0], yedges[-1], xedges[-1], xedges[0]]
    plt.imshow(H, extent=extent, aspect="auto", vmax=0.15)
    plt.colorbar()
Пример #22
0
def plot_vel_HI_col_den(sim, snap, ff=True):
    """Load a simulation and plot the HI column density vs the velocity width"""
    halo = myname.get_name(sim, ff)
    #Load from a save file only
    hspec = ps.VWPlotSpectra(snap, halo, None, None)
    HI_den = np.sum(hspec.get_col_density("H", 1), axis=1)
    vel = hspec.vel_width("Si", 2)
    ind = hspec.get_filt("Si", 2)
    (H, xedges, yedges) = np.histogram2d(np.log10(HI_den[ind]),
                                         np.log10(vel[ind]),
                                         bins=30,
                                         normed=True)
    extent = [yedges[0], yedges[-1], xedges[-1], xedges[0]]
    plt.imshow(H, extent=extent, aspect="auto")
    plt.colorbar()
Пример #23
0
def plot_metallicity(sim, snap):
    """Plot a spectrum"""
    halo = "modified_128_a" + str(sim) + "_b1"
    out = "cosmo" + str(sim) + "_metallicity_z" + str(snap)
    #Load from a save file only
    hspec = ps.VWPlotSpectra(snap, base + halo, None, None)
    hspec.plot_metallicity()
    vel_data.plot_alpha_metal_data(zrange[snap])
    save_figure(path.join(outdir, out))
    plt.clf()
    out = "cosmo" + str(sim) + "_correlation_z" + str(snap)
    hspec.plot_Z_vs_vel_width()
    vel_data.plot_prochaska_2008_correlation()
    save_figure(path.join(outdir, out))
    hspec.save_file()
    plt.clf()
Пример #24
0
def plot_metal_ion_corr(sim, snap, species="Si", ion=2):
    """Plot metallicity from Z/H vs from a single species for computing ionisation corrections"""
    halo = myname.get_name(sim)
    hspec = ps.VWPlotSpectra(snap, halo)
    hspec.plot_metallicity(color="red", ls="-")
    hspec.plot_species_metallicity(species, ion, color="blue", ls="-")
    vel_data.plot_alpha_metal_data((3.5, 2.5))
    save_figure(
        path.join(outdir,
                  "cosmo_metallicity" + str(sim) + "_ion_corr" + str(snap)))
    plt.clf()
    hspec.plot_ion_corr(species, ion)
    save_figure(
        path.join(outdir, "cosmo_metallicity" + str(sim) + "_rel_ion_corr" +
                  str(snap)))
    plt.clf()
Пример #25
0
def plot_corr_as_points():
    """Plot the correlation as points"""
    halo = myname.get_name(7)
    hspec = ps.VWPlotSpectra(3, halo)
    vel = hspec.vel_width("Si", 2)
    met = hspec.get_metallicity()
    #Ignore objects too faint to be seen
    ind2 = np.where(met > 1e-4)
    met = met[ind2]
    vel = vel[ind2]
    plt.loglog(vel, met, 'o', color="blue")
    plt.xlim(10, 2e3)
    plt.ylabel(r"$\mathrm{Z} / \mathrm{Z}_\odot$")
    plt.xlabel(r"$v_\mathrm{90}$ (km s$^{-1}$)")
    save_figure(path.join(outdir, "cosmo_corr_as_points"))
    plt.clf()
Пример #26
0
def plot_met_mass(sim, snap, ff=True):
    """Load a simulation and plot the halo mass vs the velocity width"""
    halo = myname.get_name(sim, ff)
    #Load from a save file only
    hspec = ps.VWPlotSpectra(snap, halo)
    ind = hspec.get_filt("Si", 2)
    met = hspec.get_metallicity()[ind]
    (halos, _) = hspec.find_nearest_halo()
    mass = hspec.sub_mass[halos][ind]
    (H, xedges, yedges) = np.histogram2d(np.log10(mass),
                                         np.log10(met),
                                         bins=30,
                                         normed=True)
    extent = [yedges[0], yedges[-1], xedges[-1], xedges[0]]
    plt.imshow(H, extent=extent, aspect="auto")
    plt.colorbar()
Пример #27
0
def plot_Si_metals(sim, snap, ff=True):
    """Plot the correlation between metallicity and velocity width"""
    halo = myname.get_name(sim, ff)
    #Load from a save file only
    hspec = ps.VWPlotSpectra(snap, halo)
    met = hspec.get_metallicity()
    MM = hspec.get_density("Si", 2)
    HH = hspec.get_density("H", -1)
    mms = np.sum(MM, axis=1)
    hhs = np.sum(HH, axis=1)
    Simet = mms / hhs / 0.0133
    (H, xedges, yedges) = np.histogram2d(np.log10(met),
                                         np.log10(Simet),
                                         bins=30,
                                         normed=True)
    extent = [yedges[0], yedges[-1], xedges[-1], xedges[0]]
    plt.imshow(H, extent=extent, aspect="auto")
    plt.colorbar()
Пример #28
0
def plot_vel_redshift_evo(sim):
    """Plot the evolution with redshift of a simulation"""
    halo = myname.get_name(sim, True)
    vels = {}
    for snap in (1, 3, 5):
        hspec0 = ps.VWPlotSpectra(snap, halo)
        (vbin, vels[snap]) = hspec0.vel_width_hist("Si", 2)
    mm = np.min([np.size(vel) for vel in vels.values()])
    #Normalised by z=3
    plt.semilogx(vbin[:mm],
                 vels[5][:mm] / vels[3][:mm],
                 color="black",
                 ls="--")
    plt.semilogx(vbin[:mm], vels[1][:mm] / vels[3][:mm], color="grey", ls="-")
    plt.xlim(10, 1000)
    plt.ylim(0.5, 1.5)
    save_figure(path.join(outdir, "cosmo" + str(sim) + "_zz_evol"))
    plt.clf()
Пример #29
0
def do_statistics(sim, snap):
    """Compute statistics"""
    #Get Observational data
    (_, met, vel) = vel_data.load_data(zrange[snap])
    vel = np.log10(vel)
    #Get Simulated data
    halo = myname.get_name(sim, True)
    hspec = ps.VWPlotSpectra(snap, halo)
    svel = hspec.vel_width("Si", 2)
    smet = hspec.get_metallicity()
    #Ignore objects too faint to be seen
    ind2 = np.where(smet > 1e-4)
    smet = np.log10(smet[ind2])
    svel = np.log10(svel[ind2])
    #Fit to both datasets
    (obs_intercept, obs_slope, obs_var) = ls.leastsq(vel, met)
    (s_intercept, s_slope, s_var) = ls.leastsq(svel, smet)
    print("obs fit: ", obs_intercept, obs_slope, np.sqrt(obs_var))
    print("sim fit: ", s_intercept, s_slope, np.sqrt(s_var))
    #Find correlations
    print("obs pearson r: ", ls.pearson(vel, met, obs_intercept, obs_slope))
    print("sim pearson r: ", ls.pearson(svel, smet, s_intercept, s_slope))
    print("obs kstest: ", ls.kstest(vel, met, obs_intercept, obs_slope))
    print("sim kstest: ", ls.kstest(svel, smet, s_intercept, s_slope))
    #Now test whether they come from the same population
    kss = hspec.kstest(10**met, 10**vel)
    print("KS test between simulated and observed samples: ", kss)
    #Do 200 trials and see how many times the KS test is worse
    ntrials = 50
    count = 0
    for _ in range(ntrials):
        rand = np.random.randint(0, np.size(svel), np.size(vel))
        if kss <= hspec.kstest(10**smet[rand], 10**svel[rand]):
            count += 1
    print("Prob KS test between simulated samples was larger: ",
          count * 1. / ntrials)
Пример #30
0
def test_noise():
    """Plot the effect of noise on the spectrum"""
    halo = myname.get_name(7)
    hspec = ps.VWPlotSpectra(3, halo, snr=0., label="No Noise")
    hspec2 = ps.VWPlotSpectra(3, halo, snr=20., label="Noise")
    plot_check(hspec, hspec2, "noise")