Exemplo n.º 1
0
def plot_galaxy_and_stars(galaxy, stars):

    colors = get_distinct(3)
    single_frame('X [pc]', 'Y [pc]')
    xlim = 60
    pyplot.xlim(-xlim, xlim)
    pyplot.ylim(-xlim, xlim)
    ax = pyplot.gca()

    import numpy as np
    import pandas as pd
    from scipy import stats, integrate
    import matplotlib.pyplot as plt
    import seaborn as sns
    sns.set(color_codes=True)

    p = galaxy.select(lambda x: x < 60 | units.parsec, ["x"])
    p = p.select(lambda x: x > -60 | units.parsec, ["x"])
    p = p.select(lambda y: y < 60 | units.parsec, ["y"])
    p = p.select(lambda y: y > -60 | units.parsec, ["y"])
    x = p.x.value_in(units.parsec)
    y = p.y.value_in(units.parsec)
    sns.kdeplot(x, y, ax=ax)
    m = 100 * numpy.sqrt(stars.mass / stars.mass.max())
    pyplot.scatter(stars.x.value_in(units.parsec),
                   stars.y.value_in(units.parsec),
                   c=colors[0],
                   s=m,
                   lw=0)
    #    pyplot.show()
    pyplot.savefig("Fujii_Comparison_Figure")
Exemplo n.º 2
0
def  plot_galaxy_and_stars(galaxy, stars):
    
    colors = get_distinct(3)
    single_frame('X [pc]', 'Y [pc]')
    xlim = 60
    pyplot.xlim(-xlim, xlim)
    pyplot.ylim(-xlim, xlim)
    ax = pyplot.gca()

    import numpy as np
    import pandas as pd
    from scipy import stats, integrate
    import matplotlib.pyplot as plt
    import seaborn as sns
    sns.set(color_codes=True)

    p = galaxy.select(lambda x: x<60|units.parsec,["x"])
    p = p.select(lambda x: x>-60|units.parsec,["x"])
    p = p.select(lambda y: y<60|units.parsec,["y"])
    p = p.select(lambda y: y>-60|units.parsec,["y"])
    x = p.x.value_in(units.parsec)
    y = p.y.value_in(units.parsec)
    sns.kdeplot(x, y, ax=ax)
    m = 100*numpy.sqrt(stars.mass/stars.mass.max())
    pyplot.scatter(stars.x.value_in(units.parsec), stars.y.value_in(units.parsec), c=colors[0], s=m, lw=0)
#    pyplot.show()
    pyplot.savefig("Fujii_Comparison_Figure")
Exemplo n.º 3
0
def plot_galaxy_and_stars(galaxy, stars):

    colors = get_distinct(3)
    single_frame('X [kpc]', 'Y [kpc]')
    xlim = 10
    pyplot.xlim(-xlim, xlim)
    pyplot.ylim(-xlim, xlim)
    ax = pyplot.gca()

    import numpy as np
    import pandas as pd
    from scipy import stats, integrate
    import matplotlib.pyplot as plt
    import seaborn as sns
    sns.set(color_codes=True)

    lim = 10 | units.kpc
    p = galaxy.select(lambda x: x < lim, ["x"])
    p = p.select(lambda x: x > -lim, ["x"])
    p = p.select(lambda y: y < lim, ["y"])
    p = p.select(lambda y: y > -lim, ["y"])
    p = p.select(lambda r: r.length() > 5 | units.kpc, ["position"])
    x = p.x.value_in(units.kpc)
    y = p.y.value_in(units.kpc)
    sns.kdeplot(x, y, ax=ax, shade=True, n_levels=20, shade_lowest=False)
    m = 100 * numpy.sqrt(stars.mass / stars.mass.max())
    pyplot.scatter(stars.x.value_in(units.kpc),
                   stars.y.value_in(units.kpc),
                   c=colors[0],
                   s=m,
                   lw=0)
    pyplot.savefig("SolarSiblings_life_galaxy")
Exemplo n.º 4
0
def energy_plot(time, E_kin, E_pot, E_therm, figname):
    if not HAS_MATPLOTLIB:
        return
    x_label = 'Time [hour]'
    y_label = 'Energy [foe]'
    single_frame(x_label,
                 y_label,
                 logx=False,
                 logy=False,
                 xsize=14,
                 ysize=10,
                 ymin=-1,
                 ymax=-1)
    cols = get_distinct(4)

    FOE = 1.e+51 | units.erg
    hour = 1 | units.hour
    pyplot.plot(time / hour, E_kin / FOE, label='E_kin', c=cols[0])
    pyplot.plot(time / hour, E_pot / FOE, label='E_pot', c=cols[1])
    pyplot.plot(time / hour, E_therm / FOE, label='E_therm', c=cols[2])
    pyplot.plot(time / hour, (E_kin + E_pot + E_therm) / FOE,
                label='E_total',
                c=cols[3])
    pyplot.legend(loc='best')
    pyplot.savefig(figname)

    print('\nSaved energy evolution figure in file', figname, '\n')
    pyplot.show()
    pyplot.close()
def  plot_galaxy_and_stars(galaxy, stars):
    
    colors = get_distinct(3)
    single_frame('X [kpc]', 'Y [kpc]')
    xlim = 10
    pyplot.xlim(-xlim, xlim)
    pyplot.ylim(-xlim, xlim)
    ax = pyplot.gca()

    import numpy as np
    import pandas as pd
    from scipy import stats, integrate
    import matplotlib.pyplot as plt
    import seaborn as sns
    sns.set(color_codes=True)

    lim = 10|units.kpc
    p = galaxy.select(lambda x: x<lim,["x"])
    p = p.select(lambda x: x>-lim,["x"])
    p = p.select(lambda y: y<lim,["y"])
    p = p.select(lambda y: y>-lim,["y"])
    p = p.select(lambda r: r.length()>5|units.kpc,["position"])
    x = p.x.value_in(units.kpc)
    y = p.y.value_in(units.kpc)
    sns.kdeplot(x, y, ax=ax, shade=True, n_levels=20, shade_lowest=False)
    m = 100*numpy.sqrt(stars.mass/stars.mass.max())
    pyplot.scatter(stars.x.value_in(units.kpc), stars.y.value_in(units.kpc), c=colors[0], s=m, lw=0)
    pyplot.savefig("SolarSiblings_life_galaxy")
Exemplo n.º 6
0
def main(N, t_end, z, C="SeBa", plot=False):
    if "SeBa" not in C:
        x_label = "T [K]"
        y_label = "L [L$_\odot$]"
        figure = single_frame(x_label, y_label, logx=True, logy=True, xsize=14, ysize=10)
        color = get_distinct(4)
        pyplot.xlim(1.e+5, 1.e+3)
        pyplot.ylim(1.e-4, 1.e+4)
        filename = "Stellar_"+"SeBa"+".h5"
        plot_HRD(filename, color[0])
        filename = "Stellar_"+C+".h5"
        plot_HRD(filename, color[1])
        pyplot.savefig("HRD_N3000at4500Myr")
    elif not plot:
        numpy.random.seed(1)
        masses = new_salpeter_mass_distribution(N)
        stars = Particles(mass=masses)
        get_stellar_temperature_and_luminosity(stars, C=C, z=z, t_end=t_end, write=True)
    else:
        x_label = "T [K]"
        y_label = "L [L$_\odot$]"
        figure = single_frame(x_label, y_label, logx=True, logy=True, xsize=14, ysize=10)
        color = get_distinct(4)
        pyplot.xlim(1.e+5, 1.e+3)
        pyplot.ylim(1.e-4, 1.e+4)
        filename = "Stellar_"+C+".h5"
        plot_HRD(filename, color[0])
#        pyplot.show()
        pyplot.savefig("HRD_N3000at4500Myr")
Exemplo n.º 7
0
def plot_ionization_fraction(pos, xion):
    r = [] | units.parsec
    x = []
    for pi, xi in zip(pos, xion):
        r.append(pi.length())
        x.append(xi)
    r, x = list(zip(*sorted(zip(r.value_in(units.parsec), x))))

    R, X = binned_mean_data(r, x)

    from matplotlib import pyplot
    x_label = "r [pc]"
    y_label = r'$\xi_{\rm ion}$'
    figure = single_frame(x_label,
                          y_label,
                          logx=False,
                          logy=False,
                          xsize=14,
                          ysize=8)
    pyplot.scatter(r, x, c=get_distinct(1), lw=0, s=100)
    pyplot.plot(R, X, c=get_distinct(2)[1], lw=2)
    pyplot.xlim(0, 6)
    pyplot.ylim(-0.04, 1.19)
    pyplot.savefig("fig_ionization_of_GMC")
    pyplot.show()
Exemplo n.º 8
0
def main(N, t_end):
    t_end = t_end | nbody_system.time
    Q_init = 0.2
    particles = new_plummer_model(N)
    codes = [ph4, Huayno, BHTree]
    cols = get_distinct(3)
    ci = 0
    x_label = "time [N-body units]"
    #    y_label = "$Q [\equiv -E_{\rm kin}/E_{\rm pot}]$"
    y_label = "virial ratio $Q$"
    figure = single_frame(x_label, y_label, xsize=14, ysize=10)
    ax1 = pyplot.gca()
    ax1.set_xlim(0, t_end.value_in(t_end.unit))
    ax1.set_ylim(0, 0.65)
    pyplot.plot([0, t_end.value_in(t_end.unit)], [0.5, 0.5],
                lw=1,
                ls='--',
                c='k')
    for code in codes:
        time, Q = virial_ratio_evolution(code, particles, Q_init, t_end)
        pyplot.plot(time.value_in(t_end.unit), Q, c=cols[ci])
        ci += 1


#    pyplot.show()
    pyplot.savefig("gravity_to_virial")
def plot_hydro(time, sph, i, L=10):
    x_label = "x [pc]"
    y_label = "y [pc]"
    fig = single_frame(x_label, y_label, logx=False, logy=False,
                       xsize=12, ysize=12)
    rho = make_map(sph,N=200,L=L)
    cax = pyplot.imshow(numpy.log10(1.e-5+rho.value_in(units.amu/units.cm**3)),
                        cmap="jet",
                        extent=[-L/2,L/2,-L/2,L/2],vmin=2,vmax=5)
    if i==5:
        cbar = fig.colorbar(cax, ticks=[2, 3, 4, 5], orientation='vertical', fraction=0.05)
        cbar.ax.set_yticklabels([2, " ", " ", 5])  # horizontal colorbar
        cbar.set_label('log projected density [$amu/cm^3$]', rotation=270)

    """
    rhomin = numpy.log10(rho.value_in(units.amu/units.cm**3)).min()
    rhomax = numpy.log10(rho.value_in(units.amu/units.cm**3)).max()
    cax = pyplot.imshow(numpy.log10(1.e-5+rho.value_in(units.amu/units.cm**3)),
                        extent=[-L/2,L/2,-L/2,L/2],vmin=rhomin,vmax=rhomax)
    rhomid = 0.5*(rhomin + rhomax)
    print rhomin, rhomid, rhomax
    cbar = fig.colorbar(cax, ticks=[rhomin, rhomid, rhomax], orientation='vertical', fraction=0.045)
#    cbar.ax.set_yticklabels(['Low', ' ', 'High'])  # horizontal colorbar
    low = "%.2f" % rhomin
    mid = "%.1f" % rhomid
    mx = "%.2f" % rhomax
    cbar.ax.set_yticklabels([low, mid, mx])  # horizontal colorbar
    cbar.set_label('projected density [$amu/cm^3$]', rotation=270)
    """
    
    pyplot.savefig("GMC_"+str(i)+".png")
Exemplo n.º 10
0
def plot_sph(time, sph, gas, i=1, L=10):
    x_label = "x [R$_\odot$]"
    y_label = "y [R$_\odot$]"
    fig = single_frame(x_label,
                       y_label,
                       logx=False,
                       logy=False,
                       xsize=12,
                       ysize=12)

    #    rho=make_map(sph,N=200,L=L)
    rho_e = make_e_map(sph, N=200, L=L)
    #    pyplot.hist(numpy.log10(rho_e.value_in(units.erg/units.RSun**3)))
    #    pyplot.show()
    print "extrema:", rho_e.value_in(
        units.erg / units.RSun**3).min(), rho_e.value_in(units.erg /
                                                         units.RSun**3).max()
    #    pyplot.imshow(numpy.log10(1.e-8+rho.value_in(units.amu/units.cm**3)), extent=[-L/2,L/2,-L/2,L/2],vmin=1,vmax=5)
    pyplot.imshow(numpy.log10(rho_e.value_in(units.erg / units.RSun**3)),
                  extent=[-L / 2, L / 2, -L / 2, L / 2],
                  vmin=23,
                  vmax=40)
    #    pyplot.imshow(numpy.log10(1.e-5+rho.value_in(units.amu/units.cm**3)), extent=[-L/2,L/2,-L/2,L/2],vmin=1,vmax=5)
    #pyplot.scatter(gas.x.value_in(units.RSun), gas.y.value_in(units.RSun))#, alpha=0.05)

    t = int(0.5 + sph.model_time.value_in(units.s))
    filename = "supernova_sph_T" + str(t) + ".pdf"
    pyplot.savefig(filename)
Exemplo n.º 11
0
def main(M1, M2, M3, ain, aout, ein, eout, t_end, nsteps):

    from matplotlib import pyplot
    x_label = "$a/a_{0}$"
    #    x_label = "$t [Myr]$"
    y_label = "ecc, $a/a_{0}$"
    fig = single_frame(x_label,
                       y_label,
                       logx=False,
                       logy=False,
                       xsize=14,
                       ysize=12)
    color = get_distinct(4)

    time, ain, ein, aout, eout = evolve_triple_with_wind(
        M1, M2, M3, ain, aout, ein, eout, t_end, nsteps)
    pyplot.plot(ain, ein, c=color[0], label='inner')
    pyplot.plot(aout, eout, c=color[1], label='outer')
    """
    pyplot.plot(time, ein, c=color[0], label= '$e_{inner}$')
    pyplot.plot(time, ain, c=color[1], label= '$a_{inner}$')
    pyplot.plot(time, eout, c=color[2], label= '$e_{outer}$')
    pyplot.plot(time, aout, c=color[3], label= '$a_{outer}$')
    """
    pyplot.legend(loc="upper left", ncol=1, shadow=False, fontsize=24)

    #    pyplot.show()
    pyplot.savefig("evolve_triple_with_wind")
Exemplo n.º 12
0
def main(filename=None, lim=-1):

    if filename is None: return

    try:
        amusedir = os.environ['AMUSE_DIR']
        dir = amusedir + '/examples/textbook/'
    except:
        print('Environment variable AMUSE_DIR not set')
        dir = './'

    filename = dir + filename

    from matplotlib import pyplot, rc
    x_label = "N"
    y_label = "$t_{wall} [s]$"
    figure = single_frame(x_label,
                          y_label,
                          logx=True,
                          logy=True,
                          xsize=14,
                          ysize=10)

    npp = [12, 512]
    ntc = [1024, 2000 * 1024]
    tpp = [0.01 * x * x for x in npp]
    ttc = [1.e-6 * (x * math.log(x)) for x in ntc]
    pyplot.plot(npp, tpp, c='k', ls='-', lw=4)
    pyplot.plot(ntc, ttc, c='k', ls='-', lw=4)
    pyplot.text(12, 8, '$N^2$')
    pyplot.text(2.e+3, 0.005, '$N \log (N)$')

    for ii, I in enumerate(Integrator):

        # sample line:	I= Hermite T= 1 time N= 4 M= 1.0 mass \
        #		E=  -0.250000002735 mass * length**2 * time**-2 \
        #		Q=  -0.451489790632 dE= -1.09402279371e-08 \
        #		Time= 2.04415297508 0.000992059707642

        x = read_file(filename, 6, I)
        y1 = read_file(filename, 22, I)
        y2 = read_file(filename, 23, I)
        for i in range(len(y1)):
            y1[i] *= 0.1
            y2[i] *= 0.1
        if len(x) > 0:
            pyplot.plot(x,
                        y2,
                        label=I,
                        c=color[ii],
                        lw=lwidth[ii],
                        ls=lstyles[ii])
            pyplot.scatter(x, y2, c=color[ii], lw=0, s=200)

    pyplot.legend(loc="lower right", fontsize=18)

    save_file = "Nbody_performance.png"
    pyplot.savefig(save_file)
    print("\nSaved figure in file", save_file, '\n')
    pyplot.show()
Exemplo n.º 13
0
def plot_hydro(time, sph, L=10):
    x_label = "x [pc]"
    y_label = "y [pc]"
    fig = single_frame(x_label,
                       y_label,
                       logx=False,
                       logy=False,
                       xsize=12,
                       ysize=12)

    gas = sph.code.gas_particles
    dmp = sph.code.dm_particles
    rho = make_map(sph, N=200, L=L)
    pyplot.imshow(numpy.log10(1.e-5 + rho.value_in(units.amu / units.cm**3)),
                  extent=[-L / 2, L / 2, -L / 2, L / 2],
                  vmin=1,
                  vmax=5,
                  origin="lower")
    if len(dmp):
        m = 10.0 * dmp.mass / dmp.mass.max()
        pyplot.scatter(-dmp.x.value_in(units.parsec),
                       -dmp.y.value_in(units.parsec),
                       c='k',
                       s=m)
    pyplot.show()
Exemplo n.º 14
0
def evolve_cluster_in_galaxy(N, W0, Rinit, tend, timestep, M, R):

    Rgal=1. | units.kpc
    Mgal=1.6e10 | units.MSun
    alpha=1.2
    galaxy_code=GalacticCenterGravityCode(Rgal, Mgal, alpha)

    cluster_code=make_king_model_cluster(BHTree,N,W0, M,R,
        parameters=[("epsilon_squared", (0.01 | units.parsec)**2)])
    
    stars=cluster_code.particles.copy()    
    stars.x += Rinit
    stars.vy = 0.8*galaxy_code.circular_velocity(Rinit)
    channel=stars.new_channel_to(cluster_code.particles)
    channel.copy_attributes(["x","y","z","vx","vy","vz"])

    system=bridge(verbose=False)
    system.add_system(cluster_code, (galaxy_code,))

    times=numpy.arange(0|units.Myr, tend, timestep)
    for i,t in enumerate(times):
        system.evolve_model(t,timestep=timestep)
          
    x=system.particles.x.value_in(units.parsec)
    y=system.particles.y.value_in(units.parsec)
    cluster_code.stop()

    from prepare_figure import single_frame, get_distinct
    colors = get_distinct(1)     
    f = single_frame('X [pc]', 'Y [pc]')
    pyplot.xlim(-60, 60)
    pyplot.ylim(-60, 60)
        
    pyplot.scatter(x,y, c=colors[0], s=50, lw=0)
    pyplot.savefig("Arches")
Exemplo n.º 15
0
def plot_tracks(temperatures_original, luminosities_original,
                temperatures_helium, luminosities_helium):

    x_label = "T [K]"
    y_label = "L [$L_\odot$]"
    figure = single_frame(x_label, y_label, logx=True, logy=True,
                          xsize=14, ysize=10)
    colors = get_distinct(2)
    
    loglog(temperatures_original, luminosities_original, label='progenitor',
           c=colors[0])
    loglog(temperatures_helium, luminosities_helium, label='helium star',
           c=colors[1])
    scatter(temperatures_helium[-1], luminosities_helium[-1], marker='*',
            s=400, c=colors[1])
    xlabel('Effective Temperature')
    ylabel('Luminosity')
    pyplot.xlim(1.0e5, 4000)
    pyplot.ylim(1.0,1.0e5)
    pyplot.legend(loc=4, fontsize=24)

    save_file = 'HertzsprungRussel_HeliumStar.png'
    pyplot.savefig(save_file)
    print '\nSaved figure in file', save_file,'\n'
    pyplot.show()
Exemplo n.º 16
0
def make_hydromap_and_show_picture(sph_particles, N=100, L=10):
    x_label = "x [R$_\odot$]"
    y_label = "y [R$_\odot$]"
    fig = single_frame(x_label,
                       y_label,
                       logx=False,
                       logy=False,
                       xsize=12,
                       ysize=12)

    hydro = Gadget2(converter)
    hydro.gas_particles.add_particles(sph_particles)
    x, y, z, vx, vy, vz = setup_grid(N, L)
    rho, rhovx, rhovy, rhovz, rhoe = hydro.get_hydro_state_at_point(
        x, y, z, vx, vy, vz)
    rho = rhoe.reshape((N + 1, N + 1))
    rho_e = make_map(hydro, N=50, L=L)
    hydro.stop()
    print("extrema:",
          rho_e.value_in(units.erg / units.RSun**3).min(),
          rho_e.value_in(units.erg / units.RSun**3).max())
    cax = pyplot.imshow(numpy.log10(rho_e.value_in(units.erg / units.RSun**3)),
                        extent=[-L / 2, L / 2, -L / 2, L / 2],
                        vmin=4,
                        vmax=11)
    cbar = fig.colorbar(cax,
                        ticks=[4, 7.5, 11],
                        orientation='vertical',
                        fraction=0.045)
    cbar.ax.set_yticklabels(['Low', ' ', 'High'])  # horizontal colorbar
    cbar.set_label('mid-plane energy-density', rotation=270)

    t = int(0.5 + gas.get_timestamp().value_in(units.s))
    filename = "supernova_sph_T" + str(t) + ".pdf"
    pyplot.savefig(filename)
Exemplo n.º 17
0
def plot_tracks(temperatures_original, luminosities_original,
                temperatures_helium, luminosities_helium):

    x_label = "T [K]"
    y_label = "L [$L_\odot$]"
    figure = single_frame(x_label, y_label, logx=True, logy=True,
                          xsize=14, ysize=10)
    colors = get_distinct(2)
    
    loglog(temperatures_original, luminosities_original, label='progenitor',
           c=colors[0])
    loglog(temperatures_helium, luminosities_helium, label='helium star',
           c=colors[1])
    scatter(temperatures_helium[-1], luminosities_helium[-1], marker='*',
            s=400, c=colors[1])
    xlabel('Effective Temperature')
    ylabel('Luminosity')
    pyplot.xlim(1.0e5, 4000)
    pyplot.ylim(1.0,1.0e5)
    pyplot.legend(loc=4, fontsize=24)

    save_file = 'HertzsprungRussel_HeliumStar.png'
    pyplot.savefig(save_file)
    print('\nSaved figure in file', save_file,'\n')
    pyplot.show()
Exemplo n.º 18
0
def plummer_model(N, x_label = 'x [length]', y_label='y [length]'):
    fig = single_frame(x_label, y_label, xsize=8, ysize=8)
    model = new_plummer_model(N)
    plot_projected_density(model, col=0)
    file = "plummer_model.png"
    pyplot.savefig(file)
    print('Saved figure in file', file)
Exemplo n.º 19
0
def plummer_model(N, x_label = 'x [length]', y_label='y [length]'):
    fig = single_frame(x_label, y_label, xsize=8, ysize=8)
    model = new_plummer_model(N)
    plot_projected_density(model, col=0)
    file = "plummer_model.png"
    pyplot.savefig(file)
    print 'Saved figure in file', file
Exemplo n.º 20
0
def plot_sph(time, sph, gas, i=1, L=10):
    max_dens = sph.rho.max()

    x_label = "X [R$_\odot$]"
    y_label = "Y [R$_\odot$]"
    fig = single_frame(x_label, y_label, logx=False, logy=False, xsize=12, ysize=12)

#    rho=make_map(sph,N=200,L=L)
    rho_e=make_e_map(sph,N=200,L=L)
    print "extrema:", rho_e.value_in(units.erg/units.RSun**3).min(), rho_e.value_in(units.erg/units.RSun**3).max()
#    pyplot.imshow(numpy.log10(rho_e.value_in(units.erg/units.RSun**3)), extent=[-L/2,L/2,-L/2,L/2],vmin=23,vmax=40)
    pyplot.imshow(numpy.log10(rho_e.value_in(units.erg/units.RSun**3)), extent=[-L/2,L/2,-L/2,L/2],vmin=23,vmax=40, interpolation='bicubic', origin = 'lower', cmap="hot")
#    cax = plot.imshow(rho, interpolation='bicubic', origin = 'lower', extent=[-5, 5, -5, 5], cmap="hot")
    cbar = figure.colorbar(cax, ticks=[1.e-8, 0.5*max_dens, max_dens], orientation='vertical', fraction=0.045)
    rmin = 0.0 
    rmid = "%.1f" % (0.5*max_dens)
    rmax = "%.1f" % (max_dens)
    cbar.ax.set_yticklabels([rmin, ' ', rmax])  # horizontal colorbar
    cbar.set_label('mid-plane density [$g/cm^3$]', rotation=270)
    pyplot.xlabel("x [R$_\odot$]")
    pyplot.ylabel("y [R$_\odot$]")

    t = int(0.5+sph.model_time.value_in(units.s))
    filename = "supernova_sph_T"+str(t)+".pdf"
    pyplot.savefig(filename)
Exemplo n.º 21
0
def plot_hydro(time, sph, i, L=10):
    x_label = "x [pc]"
    y_label = "y [pc]"
    fig = single_frame(x_label, y_label, logx=False, logy=False,
                       xsize=12, ysize=12)
    rho = make_map(sph,N=200,L=L)
    cax = pyplot.imshow(numpy.log10(1.e-5+rho.value_in(units.amu/units.cm**3)),
                        cmap="jet",
                        extent=[-L/2,L/2,-L/2,L/2],vmin=2,vmax=5)
    if i==5:
        cbar = fig.colorbar(cax, ticks=[2, 3, 4, 5], orientation='vertical', fraction=0.05)
        cbar.ax.set_yticklabels([2, " ", " ", 5])  # horizontal colorbar
        cbar.set_label('log projected density [$amu/cm^3$]', rotation=270)

    """
    rhomin = numpy.log10(rho.value_in(units.amu/units.cm**3)).min()
    rhomax = numpy.log10(rho.value_in(units.amu/units.cm**3)).max()
    cax = pyplot.imshow(numpy.log10(1.e-5+rho.value_in(units.amu/units.cm**3)),
                        extent=[-L/2,L/2,-L/2,L/2],vmin=rhomin,vmax=rhomax)
    rhomid = 0.5*(rhomin + rhomax)
    print rhomin, rhomid, rhomax
    cbar = fig.colorbar(cax, ticks=[rhomin, rhomid, rhomax], orientation='vertical', fraction=0.045)
#    cbar.ax.set_yticklabels(['Low', ' ', 'High'])  # horizontal colorbar
    low = "%.2f" % rhomin
    mid = "%.1f" % rhomid
    mx = "%.2f" % rhomax
    cbar.ax.set_yticklabels([low, mid, mx])  # horizontal colorbar
    cbar.set_label('projected density [$amu/cm^3$]', rotation=270)
    """
    
    pyplot.savefig("GMC_"+str(i)+".png")
Exemplo n.º 22
0
def main(N, W0, t_end, Rvir, Mmin, Mmax):
    bodies = generate_initial_conditions(N, W0, Rvir, Mmin, Mmax)

    x_label = "t [Myr]"
    y_label = "R [pc]"
    fig = single_frame(x_label, y_label, logx=False, logy=False, xsize=14, ysize=12)
    color = get_distinct(4)

    time, Lr25, Lr50, Lr75 = run_only_gravity(bodies.copy(), t_end)
    pyplot.plot(time.value_in(units.Myr), Lr25.value_in(units.parsec), c=color[0], label= 'without mass loss')
    pyplot.plot(time.value_in(units.Myr), Lr50.value_in(units.parsec), c=color[0])
    pyplot.plot(time.value_in(units.Myr), Lr75.value_in(units.parsec), c=color[0])

    time, Lr25, Lr50, Lr75 = run_sequential_gravity_and_stellar(bodies.copy(), t_end)
    pyplot.plot(time.value_in(units.Myr), Lr25.value_in(units.parsec), c=color[1], label= 'with mass loss')
    pyplot.plot(time.value_in(units.Myr), Lr50.value_in(units.parsec), c=color[1])
    pyplot.plot(time.value_in(units.Myr), Lr75.value_in(units.parsec), c=color[1])
    
    time, Lr25, Lr50, Lr75 = run_event_driven_gravity_and_stellar(bodies.copy(), t_end)
    pyplot.plot(time.value_in(units.Myr), Lr25.value_in(units.parsec), c=color[2], label= 'Event driven')
    pyplot.plot(time.value_in(units.Myr), Lr50.value_in(units.parsec), c=color[2])
    pyplot.plot(time.value_in(units.Myr), Lr75.value_in(units.parsec), c=color[2])

    pyplot.legend(loc="upper left", ncol=1, shadow=False, fontsize=24)

    #pyplot.show()
    pyplot.savefig("gravity_stellar_comparison")
Exemplo n.º 23
0
def plot_sph(sph, time):
    L = 10
    unit = units.g/units.cm**3
    max_dens = sph.gas_particles.rho.value_in(unit).max()
    print "Density extrema:", max_dens

    x_label = "X [R$_\odot$]"
    y_label = "Y [R$_\odot$]"
    figure = single_frame(x_label, y_label, logx=False, logy=False, xsize=12, ysize=12)

    rho_e=make_map(sph,N=50,L=L)
    max_dens = rho_e.value_in(unit).max()
    print "extrema:", rho_e.value_in(unit).min(), max_dens
    cax = pyplot.imshow(rho_e.value_in(unit), extent=[-L/2,L/2,-L/2,L/2], interpolation='bicubic', origin='lower', cmap="hot", vmin=0.0, vmax=max_dens)    
#    cbar = figure.colorbar(cax, ticks=[-0.4*max_dens, 0.0*max_dens, 0.5*max_dens], orientation='vertical', fraction=0.045)
    cbar = figure.colorbar(cax, ticks=[0.0, 0.5*max_dens, 0.99*max_dens], orientation='vertical', fraction=0.045)

    rmin = "0.0"
    rmid = "%.1f" % (0.5*max_dens)
    rmax = "%.1f" % (max_dens)
    print "min/max=", rmin, rmid, rmax
    cbar.ax.set_yticklabels([rmin, ' ', rmax])  # horizontal colorbar
#    cbar.ax.set_yticklabels(['a', 'b', 'c'])  # horizontal colorbar
    cbar.set_label('mid-plane density [$g/cm^3$]', rotation=270)
    pyplot.xlabel("x [R$_\odot$]")
    pyplot.ylabel("y [R$_\odot$]")

    t = int(0.5+time.value_in(units.s))
    filename = "supernova_sph_T"+str(t)+".pdf"
    pyplot.savefig(filename)
    pyplot.show()
Exemplo n.º 24
0
def plot_e_sph(sph, time):
#    pyplot.rcParams.update({'font.size': 30})
#    figure = pyplot.figure(figsize=(12, 12))

    L = 10
    max_dens = sph.gas_particles.rho.value_in(units.g/units.cm**3).max()
    print "Density extrema:", max_dens

    x_label = "X [R$_\odot$]"
    y_label = "Y [R$_\odot$]"
    figure = single_frame(x_label, y_label, logx=False, logy=False, xsize=12, ysize=12)


    rho_e=make_e_map(sph,N=20,L=L)
    cax = pyplot.imshow(rho_e.value_in(units.erg/units.MSun**3), extent=[-L/2,L/2,-L/2,L/2], interpolation='bicubic', origin = 'lower', cmap="hot")
    cbar = figure.colorbar(cax, ticks=[1.e-8, 0.5*max_dens, max_dens], orientation='vertical', fraction=0.045)
    rmin = 0.0 
    rmid = "%.1f" % (0.5*max_dens)
    rmax = "%.1f" % (max_dens)
    cbar.ax.set_yticklabels([rmin, ' ', rmax])  # horizontal colorbar
    cbar.set_label('mid-plane density [$erg/M_\odot^3$]', rotation=270)
    pyplot.xlabel("x [R$_\odot$]")
    pyplot.ylabel("y [R$_\odot$]")

    t = int(0.5+time.value_in(units.s))
    filename = "supernova_sph_T"+str(t)+".pdf"
    pyplot.savefig(filename)
    pyplot.show()
Exemplo n.º 25
0
def main():
    x_label = "$log_{10}[(t_{end}-t)/t_{MS}]$"
    y_label = "$\zeta$"
    figure = single_frame(x_label, y_label, logx=False, logy=False, xsize=14, ysize=10)
    color = get_distinct(12)

    pyplot.text(-2.2, 0.8, "giant branch")
    pyplot.text(-0.1, 0.8, "main sequence")
    pyplot.xlim(0.5, -4.)
    pyplot.ylim(-0.6, 1.2)
    fii = 0
    ti=0
    for dmi in dmdt:
        for fi in filenames:
            f = open(fi)
            for line in f:
                t, z, tms = process_file(f, dmi)
                #print t, z, tms
                for i in range(len(t)):
                    if z[i]<0:
                        ti = i
                        break
                for i in range(len(t)):
                    t[i] = numpy.log10((t[-1]-t[i])/tms)
                #            pyplot.scatter(t, z)
                pyplot.plot(t[ti:], z[ti:], c=color[fii], ls=ls[fii], lw=lw[fii])
            f.close()
        fii += 1
    pyplot.show()
Exemplo n.º 26
0
def main(N, t_end):
    t_end = t_end | nbody_system.time
    Q_init = 0.2
    particles = new_plummer_model(N)
    codes = [ph4, Huayno, BHTree]
    cols = get_distinct(3)
    ci = 0
    x_label = "time [N-body units]"
    y_label = "virial ratio $Q$"
    figure = single_frame(x_label, y_label, xsize=14, ysize=10)
    ax1 = pyplot.gca()
    ax1.set_xlim(0, t_end.value_in(t_end.unit))
    ax1.set_ylim(0, 0.65)
    pyplot.plot([0, t_end.value_in(t_end.unit)], [0.5, 0.5],
                lw=1,
                ls='--',
                c='k')
    for code in codes:
        time, Q = virial_ratio_evolution(code, particles, Q_init, t_end)
        pyplot.plot(time.value_in(t_end.unit), Q, c=cols[ci])
        ci += 1

    save_file = 'gravity_to_virial.png'
    pyplot.savefig(save_file)
    print("\nOutput saved in", save_file, '\n')
    pyplot.show()
Exemplo n.º 27
0
def fractal_model(N, F=1.6, x_label='x [length]', y_label='y [length]'):
    fig = single_frame(x_label, y_label, xsize=8, ysize=8)
    ax = pyplot.gca()
    model = new_fractal_cluster_model(N=N,
                                      fractal_dimension=1.6,
                                      random_seed=42)
    plot_projected_density(model, col=2)
    pyplot.savefig("fractal_model")
Exemplo n.º 28
0
def king_model(N, W=9, x_label = 'x [length]', y_label='y [length]'):
    fig = single_frame(x_label, y_label, xsize=8, ysize=8)
    ax = pyplot.gca()
    model = new_king_model(N, W)
    plot_projected_density(model, col=1)
    file = "king_model.png"
    pyplot.savefig(file)
    print('Saved figure in file', file)
Exemplo n.º 29
0
def galaxy_model(N, x_label = 'x [length]', y_label='y [length]'):
    fig = single_frame(x_label, y_label, xsize=8, ysize=8)
    ax = pyplot.gca()
    model = new_halogen_model(N, alpha=1., beta=5., gamma=0.5)
    plot_projected_density(model, col=3)
    file = "galaxy_model.png"
    pyplot.savefig(file)
    print 'Saved figure in file', file
Exemplo n.º 30
0
def galaxy_model(N, x_label = 'x [length]', y_label='y [length]'):
    fig = single_frame(x_label, y_label, xsize=8, ysize=8)
    ax = pyplot.gca()
    model = new_halogen_model(N, alpha=1., beta=5., gamma=0.5)
    plot_projected_density(model, col=3)
    file = "galaxy_model.png"
    pyplot.savefig(file)
    print('Saved figure in file', file)
Exemplo n.º 31
0
def king_model(N, W=9, x_label = 'x [length]', y_label='y [length]'):
    fig = single_frame(x_label, y_label, xsize=8, ysize=8)
    ax = pyplot.gca()
    model = new_king_model(N, W)
    plot_projected_density(model, col=1)
    file = "king_model.png"
    pyplot.savefig(file)
    print 'Saved figure in file', file
Exemplo n.º 32
0
def main(N, W0, t_end, Rvir, Mmin, Mmax):
    bodies = generate_initial_conditions(N, W0, Rvir, Mmin, Mmax)
    print(numpy.sort(bodies.mass.value_in(units.MSun)))

    x_label = "t [Myr]"
    y_label = "R [pc]"
    fig = single_frame(x_label,
                       y_label,
                       logx=False,
                       logy=False,
                       xsize=14,
                       ysize=12)
    color = get_distinct(4)

    time, Lr25, Lr50, Lr75 = run_only_gravity(bodies.copy(), t_end)
    pyplot.plot(time.value_in(units.Myr),
                Lr25.value_in(units.parsec),
                c=color[0],
                label='without mass loss')
    pyplot.plot(time.value_in(units.Myr),
                Lr50.value_in(units.parsec),
                c=color[0])
    pyplot.plot(time.value_in(units.Myr),
                Lr75.value_in(units.parsec),
                c=color[0])

    time, Lr25, Lr50, Lr75 \
            = run_sequential_gravity_and_stellar(bodies.copy(), t_end)
    pyplot.plot(time.value_in(units.Myr),
                Lr25.value_in(units.parsec),
                c=color[1],
                label='with mass loss')
    pyplot.plot(time.value_in(units.Myr),
                Lr50.value_in(units.parsec),
                c=color[1])
    pyplot.plot(time.value_in(units.Myr),
                Lr75.value_in(units.parsec),
                c=color[1])

    time, Lr25, Lr50, Lr75 \
            = run_event_driven_gravity_and_stellar(bodies.copy(), t_end)
    pyplot.plot(time.value_in(units.Myr),
                Lr25.value_in(units.parsec),
                c=color[2],
                label='event driven')
    pyplot.plot(time.value_in(units.Myr),
                Lr50.value_in(units.parsec),
                c=color[2])
    pyplot.plot(time.value_in(units.Myr),
                Lr75.value_in(units.parsec),
                c=color[2])

    pyplot.legend(loc="upper left", ncol=1, shadow=False, fontsize=24)

    save_file = 'gravity_stellar_comparison.png'
    pyplot.savefig(save_file)
    print('\nSaved figure in file', save_file, '\n')
    pyplot.show()
Exemplo n.º 33
0
def fractal_model(N, F=1.6, x_label = 'x [length]', y_label='y [length]'):
    fig = single_frame(x_label, y_label, xsize=8, ysize=8)
    ax = pyplot.gca()
    model = new_fractal_cluster_model(N=N, fractal_dimension=1.6,
                                      random_seed=42)
    plot_projected_density(model, col=2)
    file = "fractal_model.png"
    pyplot.savefig(file)
    print 'Saved figure in file', file
Exemplo n.º 34
0
def fractal_model(N, F=1.6, x_label = 'x [length]', y_label='y [length]'):
    fig = single_frame(x_label, y_label, xsize=8, ysize=8)
    ax = pyplot.gca()
    model = new_fractal_cluster_model(N=N, fractal_dimension=1.6,
                                      random_seed=42)
    plot_projected_density(model, col=2)
    file = "fractal_model.png"
    pyplot.savefig(file)
    print('Saved figure in file', file)
Exemplo n.º 35
0
def main(**options):
    print("calculating shock using exact solution")
    exact = CalculateExactSolutionIn1D()
    xpositions, rho, p, u = exact.get_solution_at_time(0.12 | time)

    print("calculating shock using code")
    model = CalculateSolutionIn3D(**options)
    grids = model.get_solution_at_time(0.12 | time)

    print("sampling grid")
    if model.name_of_the_code in model.sph_hydro_codes:
        samples = grids
    else:
        samplepoints = [(x, 0.5, 0.5) | length
                        for x in numpy.linspace(0.0, 1.0, 2000)]
        print(len(grids))
        samples = SamplePointsOnMultipleGrids(grids, samplepoints,
                                              SamplePointOnCellCenter)
        print(len(samples))
        samples.filterout_duplicate_indices()
        print(len(samples))

    print("saving data")
    filename = "riemann_shock_tube_rho_" + model.name_of_the_code
    store_attributes(xpositions, rho, u, p, filename=filename + "_exact.csv")
    store_attributes(samples.x,
                     samples.rho,
                     samples.rhovx,
                     samples.energy,
                     filename=filename + ".csv")

    if IS_PLOT_AVAILABLE:
        print("plotting solution")
        from prepare_figure import single_frame
        from distinct_colours import get_distinct
        x_label = "[length]"
        y_label = "[mass/length$^3$]"
        figure = single_frame(x_label,
                              y_label,
                              logx=False,
                              logy=True,
                              xsize=14,
                              ysize=10)
        color = get_distinct(2)

        plot.plot(xpositions, rho, c=color[0])
        plot.scatter(samples.x, samples.rho, c=color[1], s=100)
        #        pyplot.xlim(0.3,0.7)
        #        pyplot.ylim(0.5,4.5)
        pyplot.xlim(0.0, 1.0)
        #        pyplot.ylim(0.5,4.5)
        pyplot.xlabel("[length]")
        pyplot.ylabel("[mass/length$^3$]")
        #        pyplot.savefig("riemann_shock_tube_rho_"+model.name_of_the_code+".png")
        pyplot.savefig(filename)
        pyplot.show()
Exemplo n.º 36
0
def energy_plot(time, E_kin, E_pot, E_therm, figname):
    if not HAS_MATPLOTLIB:
        return
    x_label = 'Time [hour]'
    y_label = 'Energy [foe]'
    single_frame(x_label, y_label, logx=False, logy=False, xsize=14, ysize=10, ymin=-1, ymax=-1)
    cols = get_distinct(4)

    FOE = 1.e+51 | units.erg
    hour = 1|units.hour
    pyplot.plot(time/hour, E_kin/FOE, label='E_kin', c=cols[0])
    pyplot.plot(time/hour, E_pot/FOE, label='E_pot', c=cols[1])
    pyplot.plot(time/hour, E_therm/FOE, label='E_therm', c=cols[2])
    pyplot.plot(time/hour, (E_kin+E_pot+E_therm)/FOE, label='E_total', c=cols[3])

    pyplot.legend(loc=4)
    pyplot.savefig(figname)
    print "\nPlot of energy evolution was saved to: ", figname
    pyplot.close()
Exemplo n.º 37
0
def plot_hydro(time, sph, i, L=10):
    x_label = "x [pc]"
    y_label = "y [pc]"
    fig = single_frame(x_label, y_label, logx=False, logy=False, xsize=12, ysize=12)

#    fig=pyplot.figure(figsize=(12,12))

    rho=make_map(sph,N=200,L=L)
    pyplot.imshow(numpy.log10(1.e-5+rho.value_in(units.amu/units.cm**3)), extent=[-L/2,L/2,-L/2,L/2],vmin=1,vmax=5)
    pyplot.savefig("GMC_"+str(i)+".png")
Exemplo n.º 38
0
def plot_cluster(x, y):

    from prepare_figure import single_frame, get_distinct
    colors = get_distinct(1)     
    f = single_frame('X [kpc]', 'Y [kpc]')
    pyplot.xlim(-10, 10)
    pyplot.ylim(-10, 10)
        
    pyplot.scatter(x,y, c=colors[0], s=50, lw=0)
    pyplot.show()
Exemplo n.º 39
0
def plot_cluster(x, y):

    from prepare_figure import single_frame, get_distinct
    colors = get_distinct(1)
    f = single_frame('X [kpc]', 'Y [kpc]')
    pyplot.xlim(-10, 10)
    pyplot.ylim(-10, 10)

    pyplot.scatter(x, y, c=colors[0], s=50, lw=0)
    pyplot.show()
def main():

    """
    Mb = (2. + 1.) | units.MSun
    Mb = 2. | units.MSun
    a0 = 10. | units.AU
#    vs = 35. | units.kms
    vs = 30. | units.kms
    Mdot_donor = 0.11 |units.MSun/units.Myr
    Mdot = Bondi_Hoyle_Littleton_accretion_rate(Mb, vs, a0, Mdot_donor)
    print Mdot.in_(units.MEarth/units.yr)
    t = numpy.arange(0, 3, 0.1) | units.yr
    mdot = Mdot*t
    t += 4 | units.yr
    """
    Mb = (2. + 1.) | units.MSun
    Mb = 2. | units.MSun
    a0 = 10. | units.AU
    #vs = 30. | units.kms
#    vs = 18. | units.kms
    vs = 17.26 | units.kms
    vorb = numpy.sqrt(constants.G*Mb/a0)
    print "vorb=", vorb.in_(units.kms)
    k = vorb/vs
    m1 = 1.924785833858|units.MSun
    m2 = 1.|units.MSun
    mu = m2/(m1+m2)
    Mdot_donor  = 0.11 |units.MSun/units.Myr
    cvw = 0.
    print "k and mu:", k, mu
    Mdot = Mdot_donor  * mu**2 * k**4/(1 + k**2 + cvw**2)**(3./2.)
#    print "Mdot:", Mdot.in_(units.MEarth/units.yr)
    print "Mdot:", Mdot.in_(units.MSun/units.Myr)

    t = numpy.arange(0, 3, 0.1) | units.yr
    mdot = Mdot*t 
    t += 4.2 | units.yr

    c = get_distinct(3)

    x_label = 't [yr]'
    y_label = 'M [$10^{-9}$M$_{\odot}$]'
    figure = single_frame(x_label, y_label, logy=False, xsize=14, ysize=10)
    filename = "hydro_give_or_take.data"

    print t, mdot.value_in(units.MSun)
    mdot /= (1.e-9|units.MSun)
    pyplot.plot(t.value_in(units.yr), mdot, c=c[2])

    plot_accretion_from_wind(filename, c[0])
    filename = "hydro_give_or_take_gravity_NoG.data"
    plot_accretion_from_wind(filename, c[1])

    pyplot.savefig("hydro_accretion_from_windy_star")
Exemplo n.º 41
0
def hierarchical_king_model(N, W=9, x_label = 'x [length]', y_label='y [length]'):
    fig = single_frame(x_label, y_label, xsize=8, ysize=8)
    ax = pyplot.gca()
    model_com = new_king_model(6, W/3.)
    for i in range(6):
        model = new_king_model(int(N/4.), W)
        model.position += model_com[i].position
        plot_projected_density(model, col=1)
    file = "hierarchical_king_model.png"
    pyplot.savefig(file)
    print('Saved figure in file', file)
Exemplo n.º 42
0
def hierarchical_king_model(N, W=9, x_label = 'x [length]', y_label='y [length]'):
    fig = single_frame(x_label, y_label, xsize=8, ysize=8)
    ax = pyplot.gca()
    model_com = new_king_model(6, W/3.)
    for i in range(6):
        model = new_king_model(int(N/4.), W)
        model.position += model_com[i].position
        plot_projected_density(model, col=1)
    file = "hierarchical_king_model.png"
    pyplot.savefig(file)
    print 'Saved figure in file', file
def main():
    """
    Mb = (2. + 1.) | units.MSun
    Mb = 2. | units.MSun
    a0 = 10. | units.AU
#    vs = 35. | units.kms
    vs = 30. | units.kms
    Mdot_donor = 0.11 |units.MSun/units.Myr
    Mdot = Bondi_Hoyle_Littleton_accretion_rate(Mb, vs, a0, Mdot_donor)
    print Mdot.in_(units.MEarth/units.yr)
    t = numpy.arange(0, 3, 0.1) | units.yr
    mdot = Mdot*t
    t += 4 | units.yr
    """
    Mb = (2. + 1.) | units.MSun
    Mb = 2. | units.MSun
    a0 = 10. | units.AU
    #vs = 30. | units.kms
    #    vs = 18. | units.kms
    vs = 17.26 | units.kms
    vorb = numpy.sqrt(constants.G * Mb / a0)
    print "vorb=", vorb.in_(units.kms)
    k = vorb / vs
    m1 = 1.924785833858 | units.MSun
    m2 = 1. | units.MSun
    mu = m2 / (m1 + m2)
    Mdot_donor = 0.11 | units.MSun / units.Myr
    cvw = 0.
    print "k and mu:", k, mu
    Mdot = Mdot_donor * mu**2 * k**4 / (1 + k**2 + cvw**2)**(3. / 2.)
    #    print "Mdot:", Mdot.in_(units.MEarth/units.yr)
    print "Mdot:", Mdot.in_(units.MSun / units.Myr)

    t = numpy.arange(0, 3, 0.1) | units.yr
    mdot = Mdot * t
    t += 4.2 | units.yr

    c = get_distinct(3)

    x_label = 't [yr]'
    y_label = 'M [$10^{-9}$M$_{\odot}$]'
    figure = single_frame(x_label, y_label, logy=False, xsize=14, ysize=10)
    filename = "hydro_give_or_take.data"

    print t, mdot.value_in(units.MSun)
    mdot /= (1.e-9 | units.MSun)
    pyplot.plot(t.value_in(units.yr), mdot, c=c[2])

    plot_accretion_from_wind(filename, c[0])
    filename = "hydro_give_or_take_gravity_NoG.data"
    plot_accretion_from_wind(filename, c[1])

    pyplot.savefig("hydro_accretion_from_windy_star")
Exemplo n.º 44
0
def main(filename=None, lim=-1):

    if filename is None: return

    try:
        amusedir = os.environ['AMUSE_DIR']
        dir = amusedir+'/examples/textbook/'
    except:
        print 'Environment variable AMUSE_DIR not set'
        dir = './'

    filename = dir+filename

    from matplotlib import pyplot, rc
    x_label = "N"
    y_label = "$t_{wall} [s]$"
    figure = single_frame(x_label, y_label, logx=True, logy=True,
                          xsize=14, ysize=10)

    npp = [12, 512]
    ntc = [1024, 2000*1024]
    tpp = map(lambda x: 0.01*x*x, npp) 
    ttc = map(lambda x: 1.e-6*(x*math.log(x)), ntc) 
    pyplot.plot(npp, tpp, c='k', ls='-', lw=4)
    pyplot.plot(ntc, ttc, c='k', ls='-', lw=4)
    pyplot.text(12, 8, '$N^2$')
    pyplot.text(2.e+3, 0.005, '$N \log (N)$')

    for ii, I in enumerate(Integrator):

        # sample line:	I= Hermite T= 1 time N= 4 M= 1.0 mass \
        #		E=  -0.250000002735 mass * length**2 * time**-2 \
        #		Q=  -0.451489790632 dE= -1.09402279371e-08 \
        #		Time= 2.04415297508 0.000992059707642

        x = read_file(filename, 6, I)
        y1 = read_file(filename, 22, I)
        y2 = read_file(filename, 23, I)
        for i in range(len(y1)):
            y1[i] *= 0.1
            y2[i] *= 0.1
        if len(x) > 0:
            pyplot.plot(x, y2, label=I, c=color[ii],
                        lw=lwidth[ii], ls=lstyles[ii])
            pyplot.scatter(x, y2, c=color[ii], lw=0, s=200)

    pyplot.legend(loc="lower right", fontsize=18)

    save_file = "Nbody_performance.png"
    pyplot.savefig(save_file)
    print "\nSaved figure in file", save_file,'\n'
    pyplot.show()
Exemplo n.º 45
0
def plot_cluster(x, y):

    from prepare_figure import single_frame, get_distinct
    colors = get_distinct(1)     
    f = single_frame('X [pc]', 'Y [pc]')
    pyplot.xlim(-60, 60)
    pyplot.ylim(-60, 60)
    pyplot.scatter(x,y, c=colors[0], s=50, lw=0)

    save_file = 'Arches Fig. 7.1.png'
    pyplot.savefig(save_file)
    print '\nSaved figure in file', save_file, '\n'
    pyplot.show()
Exemplo n.º 46
0
def plot_cluster(x, y):

    from prepare_figure import single_frame, get_distinct
    colors = get_distinct(1)
    f = single_frame('X [pc]', 'Y [pc]')
    pyplot.xlim(-60, 60)
    pyplot.ylim(-60, 60)
    pyplot.scatter(x, y, c=colors[0], s=50, lw=0)

    save_file = 'Arches Fig. 7.1.png'
    pyplot.savefig(save_file)
    print('\nSaved figure in file', save_file, '\n')
    pyplot.show()
Exemplo n.º 47
0
def main(filename="NbodyAMUSE.test", lim=-1):

    #I= Hermite T= 1 time N= 4 M= 1.0 mass E=  -0.250000002735 mass * length**2 * time**-2 Q=  -0.451489790632 dE= -1.09402279371e-08 Time= 2.04415297508 0.000992059707642

    from matplotlib import pyplot, rc
    x_label = "N"
    y_label = "$t_{wall} [s]$"
    figure = single_frame(x_label,
                          y_label,
                          logx=True,
                          logy=True,
                          xsize=12,
                          ysize=10)

    npp = [12, 512]
    ntc = [1024, 2000 * 1024]
    tpp = map(lambda x: 0.01 * x * x, npp)
    ttc = map(lambda x: 1.e-6 * (x * math.log(x)), ntc)
    pyplot.plot(npp, tpp, c='k', ls='-', lw=4)
    pyplot.plot(ntc, ttc, c='k', ls='-', lw=4)
    pyplot.text(12, 8, '$N^2$')
    pyplot.text(2.e+3, 0.005, '$N \log (N)$')

    for ii, I in enumerate(Integrator):
        x = read_file(filename, 6, I)
        y1 = read_file(filename, 22, I)
        y2 = read_file(filename, 23, I)
        for i in range(len(y1)):
            y1[i] *= 0.1
            y2[i] *= 0.1
#        pyplot.plot(x, y1, label=I, c=color[ii], lw=1,ls=lstyles[ii])
#        pyplot.scatter(x, y1, c=color[ii])
        if len(x) > 0:
            pyplot.plot(x,
                        y2,
                        label=I,
                        c=color[ii],
                        lw=lwidth[ii],
                        ls=lstyles[ii])
            pyplot.scatter(x, y2, c=color[ii], lw=0, s=200)


#        pyplot.plot(x, y1, label=I, c=color[ii], lw=2,ls=lstyles[ii])
#        pyplot.plot(x, y2, c=color[ii], lw=3.0,ls=lstyles[ii])
#    pyplot.legend(loc="upper left")
######    pyplot.legend(loc="lower right")
#    pyplot.xlabel("N")
#    pyplot.ylabel("t$_{wall}$ [s]")
#    pyplot.loglog()
#    pyplot.show()
    pyplot.savefig("Nbody_performance")
Exemplo n.º 48
0
def make_plot(disk1, disk2, filename):
    x_label = "X [kpc]"
    y_label = "Y [kpc]"
    figure = single_frame(x_label, y_label, logy=False, xsize=14, ysize=14)
    from distinct_colours import get_distinct
    c = get_distinct(2)
    pyplot.xlim(-300, 300)
    pyplot.ylim(-300, 300)

    pyplot.scatter(disk1.x.value_in(units.kpc), disk1.y.value_in(units.kpc),
                   c=c[0], alpha=1, s=1, lw=0)
    pyplot.scatter(disk2.x.value_in(units.kpc), disk2.y.value_in(units.kpc),
                   c=c[1], alpha=1, s=1, lw=0)
    pyplot.savefig(filename)
Exemplo n.º 49
0
def plot_cloud(x, y):

    from prepare_figure import single_frame, get_distinct
    colors = get_distinct(1)
    frame = single_frame('X [pc]', 'Y [pc]')

    pyplot.title('Cloud particle positions')
    pyplot.xlim(-200, 200)
    pyplot.ylim(-200, 200)
    pyplot.scatter(x, y, c=colors[0], s=50, lw=0)

    save_file = 'positions_M1e5.png'
    pyplot.savefig(save_file)
    print '\nSaved figure in file', save_file, '\n'
    pyplot.show()
def main(filename="hydro.hdf5", lim=None, image_id=-1, nice_plot=1):
    x_label = 'x'
    y_label = 'y'
    figure = single_frame(x_label, y_label, logy=False, xsize=14, ysize=10)
    stars = read_set_from_file(filename, "hdf5")
    print stars
    snapshot_id = 0
    isgas = True
    snapshot_id = 0
    sinks = Particles(0)
    for si in stars.history:
        if isgas:
            gas = si
            isgas = False
        else:
            sinks = si
            isgas = True
        if not isgas:
            snapshot_id += 1
            time = gas.get_timestamp()
            if image_id < 0 or image_id == snapshot_id:
                pyplot.hist2d(gas.x.value_in(units.AU),
                              gas.y.value_in(units.AU), (200, 200),
                              cmap=plt.cm.jet)
                pyplot.scatter(gas.x.value_in(units.AU),
                               gas.y.value_in(units.AU),
                               c='y',
                               s=100)
                if False:
                    for gi in gas:
                        pyplot.arrow(gi.x.value_in(units.AU),
                                     gi.y.value_in(units.AU),
                                     gi.vx.value_in(units.AU / units.yr),
                                     gi.vy.value_in(units.AU / units.yr),
                                     head_width=0.05,
                                     head_length=0.1)


#                sph_particles_plot(gas, u_range=[min(gas.u), max(gas.u)], width=lim, alpha = 1)
#                if len(sinks):
#                    scatter(sinks.x.value_in(units.AU), sinks.y.value_in(units.AU), c='y', s=100)
                if image_id == snapshot_id:
                    break
    pyplot.xlabel("X [pc]")
    pyplot.ylabel("Y [pc]")
    pyplot.show()
Exemplo n.º 51
0
def main(t_end, mass, z, Tstar, Lstar):

    stellar_evolution_codes = [SeBa(), SSE(), MESA(), EVtwin()]
    label = ["SeBa", "SSE", "MESA", "EVtwin"]
    marker = ["o", "v", "<", ">"]
    #    color = [0, 1, 2, 3, 4]

    x_label = "$(T-T_\odot)/T_\odot)$"
    y_label = "$(L-L_\odot)/L_\odot)$"
    figure = single_frame(x_label, y_label, logy=False, xsize=14, ysize=10)
    pyplot.xlim(-0.008, 0.004)
    color = get_distinct(6)
    pyplot.scatter([0], [0], marker="o", c=color[3], label="Sun", s=400, lw=0)

    for si in range(len(stellar_evolution_codes)):
        stellar = stellar_evolution_codes[si]
        stellar.parameters.metallicity = z

        star = Particles(1)
        star.mass = mass
        stellar.particles.add_particles(star)
        stellar.evolve_model(t_end)

        T = (stellar.particles.temperature - Tstar) / Tstar
        L = (stellar.particles.luminosity - Lstar) / Lstar
        if si == 3:
            pyplot.scatter(T,
                           L,
                           marker=marker[si],
                           color=color[0],
                           label=label[si],
                           s=300,
                           lw=0)
        else:
            pyplot.scatter(T,
                           L,
                           marker=marker[si],
                           color=color[si],
                           label=label[si],
                           s=300,
                           lw=0)
        stellar.stop()

    pyplot.legend(scatterpoints=1, loc=2)
    #    pyplot.show()
    pyplot.savefig("fig_SunComparison")
Exemplo n.º 52
0
def XX_plot_sph(time, sph, gas, i=1, L=10):
    x_label = "x [R$_\odot$]"
    y_label = "y [R$_\odot$]"
    fig = single_frame(x_label, y_label, logx=False, logy=False, xsize=12, ysize=12)

#    rho=make_map(sph,N=200,L=L)
    rho_e=make_e_map(sph,N=200,L=L)
#    pyplot.hist(numpy.log10(rho_e.value_in(units.erg/units.RSun**3)))
#    pyplot.show()
    print "extrema:", rho_e.value_in(units.erg/units.RSun**3).min(), rho_e.value_in(units.erg/units.RSun**3).max()
#    pyplot.imshow(numpy.log10(1.e-8+rho.value_in(units.amu/units.cm**3)), extent=[-L/2,L/2,-L/2,L/2],vmin=1,vmax=5)
    pyplot.imshow(numpy.log10(rho_e.value_in(units.erg/units.RSun**3)), extent=[-L/2,L/2,-L/2,L/2],vmin=23,vmax=40)
#    pyplot.imshow(numpy.log10(1.e-5+rho.value_in(units.amu/units.cm**3)), extent=[-L/2,L/2,-L/2,L/2],vmin=1,vmax=5)
    #pyplot.scatter(gas.x.value_in(units.RSun), gas.y.value_in(units.RSun))#, alpha=0.05)

    t = int(0.5+sph.model_time.value_in(units.s))
    filename = "supernova_sph_T"+str(t)+".pdf"
    pyplot.savefig(filename)
Exemplo n.º 53
0
def main(M1, M2, M3, Pora, Pin, ain, aout, ein, eout,
         t_end, nsteps, scheme, dtse_fac):

    from matplotlib import pyplot
    
    x_label = "$a/a_{0}$"
    y_label = "$e/e_{0}$"
    fig = single_frame(x_label, y_label, logx=False, logy=False,
                       xsize=10, ysize=8)
    color = get_distinct(4)

    if scheme == 0:
        srange = [1,2,3]
    else:
        srange = [scheme]

    i = 0
    for s in srange:
        time, ai, ei, ao, eo = evolve_triple_with_wind(M1, M2, M3,
                                                       Pora, Pin,
                                                       ain, aout,
                                                       ein, eout,
                                                       t_end, nsteps,
                                                       s, dtse_fac)
        if i == 0:
            pyplot.plot(ai, ei, c=color[0], label='inner')
            pyplot.plot(ao, eo, c=color[1], label='outer')
            i = 1
        else:
            pyplot.plot(ai, ei, c=color[0])
            pyplot.plot(ao, eo, c=color[1])

    pyplot.legend(loc='best', ncol=1, shadow=False, fontsize=20)
    
    #save_file = 'evolve_triple_with_wind.png'
    save_file = 'evolve_triple_with_wind' \
                    +'_s={:d}_dtse={:.3f}'.format(scheme, dtse_fac) \
                    +'.png'
    pyplot.savefig(save_file)
    print '\nSaved figure in file', save_file,'\n'
    pyplot.show()
Exemplo n.º 54
0
def main(N, t_end):
    t_end = t_end | nbody_system.time
    Q_init = 0.2
    particles = new_plummer_model(N)
    codes = [ph4, Huayno, BHTree]
    cols = get_distinct(3)
    ci = 0
    x_label = "time [N-body units]"
#    y_label = "$Q [\equiv -E_{\rm kin}/E_{\rm pot}]$"
    y_label = "virial ratio $Q$"
    figure = single_frame(x_label, y_label, xsize=14, ysize=10)
    ax1 = pyplot.gca()
    ax1.set_xlim(0, t_end.value_in(t_end.unit))
    ax1.set_ylim(0, 0.65)
    pyplot.plot([0, t_end.value_in(t_end.unit)], [0.5, 0.5], lw=1, ls='--', c='k')
    for code in codes:
        time, Q = virial_ratio_evolution(code, particles, Q_init, t_end)
        pyplot.plot(time.value_in(t_end.unit), Q, c=cols[ci])
        ci+=1
#    pyplot.show()
    pyplot.savefig("gravity_to_virial")
Exemplo n.º 55
0
def make_hydromap_and_show_picture(sph_particles, N=100, L=10):
    x_label = "x [R$_\odot$]"
    y_label = "y [R$_\odot$]"
    fig = single_frame(x_label, y_label, logx=False, logy=False, xsize=12, ysize=12)

    hydro = Gadget2(converter)
    hydro.gas_particles.add_particles(sph_particles)
    x, y, z, vx, vy, vz = setup_grid(N, L)
    rho,rhovx,rhovy,rhovz,rhoe=hydro.get_hydro_state_at_point(x,y,z,vx,vy,vz)
    rho=rhoe.reshape((N+1,N+1))
    rho_e=make_map(hydro,N=50,L=L)
    hydro.stop()
    print "extrema:", rho_e.value_in(units.erg/units.RSun**3).min(), rho_e.value_in(units.erg/units.RSun**3).max()
    cax = pyplot.imshow(numpy.log10(rho_e.value_in(units.erg/units.RSun**3)), extent=[-L/2,L/2,-L/2,L/2],vmin=4,vmax=11)
    cbar = fig.colorbar(cax, ticks=[4, 7.5, 11], orientation='vertical', fraction=0.045)
    cbar.ax.set_yticklabels(['Low', ' ', 'High'])  # horizontal colorbar
    cbar.set_label('mid-plane energy-density', rotation=270)
    
    t = int(0.5+gas.get_timestamp().value_in(units.s))
    filename = "supernova_sph_T"+str(t)+".pdf"
    pyplot.savefig(filename)
Exemplo n.º 56
0
def plot_ionization_fraction(pos, xion):
    r = [] | units.parsec
    x = []
    for pi, xi in zip(pos, xion):
        r.append(pi.length())
        x.append(xi)
    r, x = zip(*sorted(zip(r.value_in(units.parsec), x)))

    R, X = binned_mean_data(r, x)
    
    from matplotlib import pyplot
    x_label = "r [pc]"
    y_label = r'$\xi_{\rm ion}$'
    figure = single_frame(x_label, y_label, logx=False, logy=False,
                          xsize=14, ysize=8)
    pyplot.scatter(r, x, c=get_distinct(1), lw=0, s=100)
    pyplot.plot(R, X, c=get_distinct(2)[1], lw=2)
    pyplot.xlim(0, 6)
    pyplot.ylim(-0.04, 1.19)
    pyplot.savefig("fig_ionization_of_GMC")
    pyplot.show()
def plot_hydro(time, sph, i, L=10):
    x_label = "x [pc]"
    y_label = "y [pc]"
    fig = single_frame(x_label, y_label, logx=False, logy=False, xsize=12, ysize=12)

    gas = sph.code.gas_particles
    dmp = sph.code.dm_particles
    #rho=make_map(sph,N=200,L=L)
#    pyplot.imshow(numpy.log10(1.e-5+rho.value_in(units.amu/units.cm**3)), extent=[-L/2,L/2,-L/2,L/2],vmin=1,vmax=5, origin="lower")
#    pyplot.hist2d(gas.x.value_in(units.parsec),
#                  gas.y.value_in(units.parsec),
#                  (100, 100), cmap=pyplot.cm.jet)
#    pyplot.scatter(gas.x.value_in(units.parsec),
#                   gas.y.value_in(units.parsec), s=500, lw=0, alpha=0.1, c='r')
    x = gas.x.value_in(units.parsec)
    y = gas.y.value_in(units.parsec)
    z = gas.rho.value_in(units.g/units.cm**3)
    #z = gas.u.value_in(units.g/units.cm**3),
    #cax = pyplot.tripcolor(gas.x.value_in(units.parsec),
    #                       gas.y.value_in(units.parsec),
    #                       z,
    #                       shading='flat') #, cmap=plt.cm.rainbow)
    #                       #shading='gouraud') #, cmap=plt.cm.rainbow)
    import matplotlib.tri as tri
    triang = tri.Triangulation(x, y)
    xmid = x[triang.triangles].mean(axis=1)
    ymid = y[triang.triangles].mean(axis=1)
    min_radius = 0.01
    mask = numpy.where(xmid*xmid + ymid*ymid < min_radius*min_radius, 1, 0)
    triang.set_mask(mask)
#    pyplot.tripcolor(triang, z, shading='gouraud', cmap=pyplot.cm.rainbow)
    pyplot.tripcolor(triang, z, cmap=pyplot.cm.rainbow)
    pyplot.xlim(-1, 1)
    pyplot.ylim(-1, 1)
    if len(dmp):
        m = 2.0*dmp.mass/dmp.mass.max()
        print m
        pyplot.scatter(dmp.x.value_in(units.parsec), dmp.y.value_in(units.parsec), c='k', s=m) 
    pyplot.savefig("GMCsink_"+str(i)+".png")
Exemplo n.º 58
0
def main(filename = "NbodyAMUSE.test", lim=-1):

#I= Hermite T= 1 time N= 4 M= 1.0 mass E=  -0.250000002735 mass * length**2 * time**-2 Q=  -0.451489790632 dE= -1.09402279371e-08 Time= 2.04415297508 0.000992059707642

    from matplotlib import pyplot, rc
    x_label = "N"
    y_label = "$t_{wall} [s]$"
    figure = single_frame(x_label, y_label, logx=True, logy=True, xsize=12, ysize=10)

    npp = [12, 512]
    ntc = [1024, 2000*1024]
    tpp = map(lambda x: 0.01*x*x, npp) 
    ttc = map(lambda x: 1.e-6*(x*math.log(x)), ntc) 
    pyplot.plot(npp, tpp, c='k', ls='-', lw=4)
    pyplot.plot(ntc, ttc, c='k', ls='-', lw=4)
    pyplot.text(12, 8, '$N^2$')
    pyplot.text(2.e+3, 0.005, '$N \log (N)$')

    for ii, I in enumerate(Integrator):
        x = read_file(filename, 6, I)
        y1 = read_file(filename, 22, I)
        y2 = read_file(filename, 23, I)
        for i in range(len(y1)):
            y1[i] *= 0.1
            y2[i] *= 0.1
#        pyplot.plot(x, y1, label=I, c=color[ii], lw=1,ls=lstyles[ii])
#        pyplot.scatter(x, y1, c=color[ii])
        if len(x)>0:
            pyplot.plot(x, y2, label=I, c=color[ii], lw=lwidth[ii], ls=lstyles[ii])
            pyplot.scatter(x, y2, c=color[ii], lw=0, s=200)
#        pyplot.plot(x, y1, label=I, c=color[ii], lw=2,ls=lstyles[ii])
#        pyplot.plot(x, y2, c=color[ii], lw=3.0,ls=lstyles[ii])
#    pyplot.legend(loc="upper left")
######    pyplot.legend(loc="lower right")
#    pyplot.xlabel("N")
#    pyplot.ylabel("t$_{wall}$ [s]")
#    pyplot.loglog()
#    pyplot.show()
    pyplot.savefig("Nbody_performance")