Exemple #1
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")
def plot(stars, GMCs):
    figure = figure_frame("X [kpc]", "Y [kpc]", xsize=8, ysize=8)
    colors = get_distinct(2)

    print(numpy.mean(stars.mass.value_in(units.MSun)))
    print(numpy.mean(GMCs.mass.value_in(units.MSun)))
    size = stars.mass / (0.1 | units.MSun)
    pyplot.scatter(stars.x.value_in(units.kpc),
                   stars.y.value_in(units.kpc),
                   s=size,
                   c=colors[0])
    size = numpy.sqrt(GMCs.mass / (100 | units.MSun))
    pyplot.scatter(GMCs.x.value_in(units.kpc),
                   GMCs.y.value_in(units.kpc),
                   s=size,
                   alpha=0.5,
                   lw=0,
                   c=colors[1])

    pyplot.scatter([0], [0], marker="+", s=300, c='r')
    pyplot.scatter([-8.4], [0], marker="o", s=100, c='g')
    pyplot.axis("equal")
    pyplot.xlim(-10, 10)
    pyplot.ylim(-10, 10)
    pyplot.show()
Exemple #3
0
def plot_mass_function(masses, ximf):
    Mmin = masses.min()
    Mmax = masses.max()
    lm = math.log10(0.5 * Mmin.value_in(units.MSun))
    lM = math.log10(1.5 * Mmax.value_in(units.MSun))
    bins = 10**numpy.linspace(lm, lM, 51)
    Nbin, bin_edges = numpy.histogram(masses.value_in(units.MSun), bins=bins)
    y = Nbin / (bin_edges[1:] - bin_edges[:-1])
    x = (bin_edges[1:] + bin_edges[:-1]) / 2.0
    for i in range(len(y)):
        y[i] = max(y[i], 1.e-10)

    fig, ax = figure_frame("M$_\odot$", "N", xsize=12, ysize=8)
    colors = get_distinct(2)
    pyplot.scatter(x, y, s=100, c=colors[0], lw=0)

    c = ((Mmax.value_in(units.MSun)**(ximf+1)) \
          - (Mmin.value_in(units.MSun)**(ximf+1))) / (ximf+1)
    pyplot.plot(x, len(masses) / c * (x**ximf), c=colors[1])
    pyplot.loglog()

    save_file = "salpeter.png"
    pyplot.savefig(save_file)
    print('\nSaved figure in file', save_file, '\n')
    pyplot.show()
Exemple #4
0
def plot_mass_function(masses, ximf):
    Mmin = masses.min()
    Mmax = masses.max()
    lm = math.log10(0.5*Mmin.value_in(units.MSun))
    lM = math.log10(1.5*Mmax.value_in(units.MSun))
    bins = 10**numpy.linspace(lm, lM, 51)
    Nbin, bin_edges= numpy.histogram(masses.value_in(units.MSun), bins=bins)
    y = Nbin / (bin_edges[1:] - bin_edges[:-1])
    x = (bin_edges[1:] + bin_edges[:-1]) / 2.0
    for i in range(len(y)):
        y[i] = max(y[i], 1.e-10)

    fig, ax = figure_frame("M$_\odot$", "N", xsize=12, ysize=8)
    colors = get_distinct(2)
    pyplot.scatter(x, y, s=100, c=colors[0], lw=0)

    c = ((Mmax.value_in(units.MSun)**(ximf+1)) \
         	- (Mmin.value_in(units.MSun)**(ximf+1))) / (ximf+1)
    pyplot.plot(x, len(masses)/c * (x**ximf), c=colors[1])
    pyplot.loglog()
    
    save_file = "salpeter.png"
    pyplot.savefig(save_file)
    print '\nSaved figure in file', save_file,'\n'
    pyplot.show()
Exemple #5
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()
Exemple #6
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()
Exemple #7
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()
Exemple #8
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()
Exemple #9
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 plot(stars, GMCs):
    figure = figure_frame("X [kpc]", "Y [kpc]", xsize=8, ysize=8)
    colors = get_distinct(2)

    print numpy.mean(stars.mass.value_in(units.MSun))
    print numpy.mean(GMCs.mass.value_in(units.MSun))
    size = stars.mass/(0.1 |units.MSun)
    pyplot.scatter(stars.x.value_in(units.kpc), stars.y.value_in(units.kpc),
                   s=size, c=colors[0])
    size = numpy.sqrt(GMCs.mass/(100 |units.MSun))
    pyplot.scatter(GMCs.x.value_in(units.kpc), GMCs.y.value_in(units.kpc),
                   s=size, alpha =  0.5, lw=0, c=colors[1])

    pyplot.scatter([0], [0], marker="+", s=300, c='r')
    pyplot.scatter([-8.4], [0], marker="o", s=100, c='g')    
    pyplot.axis("equal")
    pyplot.xlim(-10, 10)
    pyplot.ylim(-10, 10)
    pyplot.show()
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")
Exemple #12
0
def integrate_solar_system(particles, end_time):

    convert_nbody = nbody_system.nbody_to_si(particles.mass.sum(), particles[1].position.length())

    gravity = Huayno(convert_nbody)
    gravity.particles.add_particles(particles)

    SunEarth = Particles()
    SunEarth.add_particle(particles[0])
    SunEarth.add_particle(particles[3])
    channel_from_to_SunEarth = gravity.particles.new_channel_to(SunEarth)

    from matplotlib import pyplot, rc
    x_label = "$a-a_0$ [AU]"
    y_label = "eccentricty"
    figure = single_frame(x_label, y_label, xsize=14, ysize=10)

    from amuse.plot import scatter
    from matplotlib import pyplot, rc
    kep = Kepler(convert_nbody)
    kep.initialize_from_particles(SunEarth)
    a, e = kep.get_elements()
    a0 = a
    color = get_distinct(1)
    scatter((a-a0).in_(units.AU), e, c=color[0], lw=0)
    pyplot.text((a-a0).value_in(units.AU)-0.0003, e, "{0:.0f}".format(0.001*gravity.model_time.value_in(units.yr))+"kyr")


    dt = 100 | units.yr
    dt_dia = 10000 |units.yr
    while gravity.model_time < end_time:

        kep.initialize_from_particles(SunEarth)
        a, e = kep.get_elements()
        scatter((a-a0).in_(units.AU), e, c=color[0], lw=0)
        if gravity.model_time> dt_dia:
            dt_dia += 10000 |units.yr
            if gravity.model_time<=(100|units.yr):
                pyplot.text(-0.0006, e, "{0:.0f}".format(0.001*gravity.model_time.value_in(units.yr))+"kyr")
            elif gravity.model_time<=(15000|units.yr):
                pyplot.text(0.0003, e, "{0:.0f}".format(0.001*gravity.model_time.value_in(units.yr))+"kyr")
            elif gravity.model_time<=(25000|units.yr):
                pyplot.text(0.0017, e, "{0:.0f}".format(0.001*gravity.model_time.value_in(units.yr))+"kyr")
            elif gravity.model_time<=(35000|units.yr):
                pyplot.text(0.0031, e, "{0:.0f}".format(0.001*gravity.model_time.value_in(units.yr))+"kyr")
            elif gravity.model_time<=(45000|units.yr):
                pyplot.text(0.0028, e, "{0:.0f}".format(0.001*gravity.model_time.value_in(units.yr))+"kyr")
            elif gravity.model_time<=(55000|units.yr):
                pyplot.text(0.0021, e, "{0:.0f}".format(0.001*gravity.model_time.value_in(units.yr))+"kyr")
            elif gravity.model_time<=(65000|units.yr):
                pyplot.text(0.0017, e+0.002, "{0:.0f}".format(0.001*gravity.model_time.value_in(units.yr))+"kyr")
            elif gravity.model_time<=(75000|units.yr):
                pyplot.text(0.0014, e-0.002, "{0:.0f}".format(0.001*gravity.model_time.value_in(units.yr))+"kyr")
            elif gravity.model_time<=(85000|units.yr):
                pyplot.text(0.0014, e, "{0:.0f}".format(0.001*gravity.model_time.value_in(units.yr))+"kyr")
            else:
                pyplot.text((a-a0).value_in(units.AU), e, "{0:.0f}".format(0.001*gravity.model_time.value_in(units.yr))+"kyr")


        gravity.evolve_model(gravity.model_time + dt)
        channel_from_to_SunEarth.copy()
    gravity.stop()

    pyplot.xlabel(x_label)
    pyplot.ylabel(y_label)
#    pyplot.show()
    pyplot.savefig("EarthOrbitVariation")

    return
def integrate_solar_system(particles, end_time):

    convert_nbody = nbody_system.nbody_to_si(particles.mass.sum(), particles[1].position.length())

    gravity = Huayno(convert_nbody)
    gravity.particles.add_particles(particles)

    SunEarth = Particles()
    SunEarth.add_particle(particles[0])
    SunEarth.add_particle(particles[3])
    channel_from_to_SunEarth = gravity.particles.new_channel_to(SunEarth)

    from matplotlib import pyplot, rc
    x_label = "$a-a_0$ [AU]"
    y_label = "eccentricty"
    figure = single_frame(x_label, y_label, xsize=14, ysize=10)

    from amuse.plot import scatter
    from matplotlib import pyplot, rc
    kep = Kepler(convert_nbody)
    kep.initialize_from_particles(SunEarth)
    a, e = kep.get_elements()
    a0 = a
    color = get_distinct(1)
    scatter((a-a0).in_(units.AU), e, c=color[0], lw=0)
    pyplot.text((a-a0).value_in(units.AU)-0.0003, e, "{0:.0f}".format(0.001*gravity.model_time.value_in(units.yr))+"kyr")


    dt = 100 | units.yr
    dt_dia = 10000 |units.yr
    while gravity.model_time < end_time:

        kep.initialize_from_particles(SunEarth)
        a, e = kep.get_elements()
        scatter((a-a0).in_(units.AU), e, c=color[0], lw=0, s=80)
        if gravity.model_time> dt_dia:
            dt_dia += 10000 |units.yr
            if gravity.model_time<=(100|units.yr):
                pyplot.text(-0.0006, e, "{0:.0f}".format(0.001*gravity.model_time.value_in(units.yr))+"kyr")
            elif gravity.model_time<=(15000|units.yr):
                pyplot.text(0.0003, e, "{0:.0f}".format(0.001*gravity.model_time.value_in(units.yr))+"kyr")
            elif gravity.model_time<=(25000|units.yr):
                pyplot.text(0.0017, e, "{0:.0f}".format(0.001*gravity.model_time.value_in(units.yr))+"kyr")
            elif gravity.model_time<=(35000|units.yr):
                pyplot.text(0.0031, e, "{0:.0f}".format(0.001*gravity.model_time.value_in(units.yr))+"kyr")
            elif gravity.model_time<=(45000|units.yr):
                pyplot.text(0.0028, e, "{0:.0f}".format(0.001*gravity.model_time.value_in(units.yr))+"kyr")
            elif gravity.model_time<=(55000|units.yr):
                pyplot.text(0.0021, e, "{0:.0f}".format(0.001*gravity.model_time.value_in(units.yr))+"kyr")
            elif gravity.model_time<=(65000|units.yr):
                pyplot.text(0.0017, e+0.002, "{0:.0f}".format(0.001*gravity.model_time.value_in(units.yr))+"kyr")
            elif gravity.model_time<=(75000|units.yr):
                pyplot.text(0.0014, e-0.002, "{0:.0f}".format(0.001*gravity.model_time.value_in(units.yr))+"kyr")
            #elif gravity.model_time<=(85000|units.yr):
            #    pyplot.text(0.0014, e, "{0:.0f}".format(0.001*gravity.model_time.value_in(units.yr))+"kyr")
            else:
                pass
            #    pyplot.text((a-a0).value_in(units.AU), e, "{0:.0f}".format(0.001*gravity.model_time.value_in(units.yr))+"kyr")


        gravity.evolve_model(gravity.model_time + dt)
        channel_from_to_SunEarth.copy()
    gravity.stop()

    pyplot.xlabel(x_label)
    pyplot.ylabel(y_label)
    pyplot.xlim(-0.001, 0.004)
#    pyplot.show()
    pyplot.savefig("EarthOrbitVariation")

    return