Beispiel #1
0
def make_plots(all_particles, disk_only, i=0):
    for j, particles in enumerate([all_particles, disk_only]):
        if HAS_PYNBODY:
            temp_particles = particles.copy()
            temp_particles.u = 1 | units.ms**2
            temp = Gadget2()
            temp.gas_particles.add_particles(temp_particles)
            temp.commit_particles()
            pynbody_column_density_plot(temp.gas_particles,
                                        width=300 | units.kpc,
                                        units='m_p cm^-2',
                                        vmin=17,
                                        vmax=23)
            temp.stop()
        else:
            native_plot.gca().set_aspect("equal")
            native_plot.xlim(-150, 150)
            native_plot.ylim(-150, 150)
            plot(particles.x.as_quantity_in(units.kpc),
                 particles.y.as_quantity_in(units.kpc), 'r.')

        native_plot.savefig(
            os.path.join(
                "plots", "plot_galaxy_merger_{0}_{1:=04}.png".format(
                    "disk" if j else "total", i)))
        native_plot.close()
Beispiel #2
0
def make_plots(all_particles, disk_only, i=0):
    for j, particles in enumerate([all_particles, disk_only]):
        if HAS_PYNBODY:
            temp_particles = particles.copy()
            temp_particles.u = 1 | units.ms**2
            temp = Gadget2()
            temp.gas_particles.add_particles(temp_particles)
            temp.commit_particles()
            pynbody_column_density_plot(
                temp.gas_particles, width=300 | units.kpc, units='m_p cm^-2',
                vmin=17, vmax=23)
            temp.stop()
        else:
            native_plot.gca().set_aspect("equal")
            native_plot.xlim(-150, 150)
            native_plot.ylim(-150, 150)
            plot(particles.x.as_quantity_in(units.kpc),
                 particles.y.as_quantity_in(units.kpc), 'r.')

        native_plot.savefig(
                os.path.join(
                    "plots",
                    "plot_galaxy_merger_{0}_{1:=04}.png".format(
                        "disk" if j else "total", i)
                    )
                )
        native_plot.close()
Beispiel #3
0
def group_plot(groups, no_group, figname="group_plot.png"):
    colors = ["r", "g", "b", "y", "k", "w"]*100
    for group, color in zip(groups, colors):
        scatter(group.x, group.y, c=color)
    
    if len(no_group):
        scatter(no_group.x, no_group.y, c="m", marker="s")
    
    native_plot.gca().set_aspect("equal", adjustable = "datalim")
    native_plot.savefig(figname)
    native_plot.clf()
def group_plot(groups, no_group, figname="group_plot.png"):
    colors = ["r", "g", "b", "y", "k", "w"] * 100
    for group, color in zip(groups, colors):
        scatter(group.x, group.y, c=color)

    if len(no_group):
        scatter(no_group.x, no_group.y, c="m", marker="s")

    native_plot.gca().set_aspect("equal", adjustable="datalim")
    native_plot.savefig(figname)
    native_plot.clf()
Beispiel #5
0
def monitor_density_profile(system, i_step, time, n_steps, memory=Memory()):
    if i_step == 0:
        memory.xlimits = (None, None)
        memory.ylimits = (None, None)
    position = system.gas_particles.position - system.gas_particles.center_of_mass()
    loglog(position.lengths_squared(), system.gas_particles.density, 'gs')
    native_plot.title("{0}: t={1}".format(i_step, time.as_quantity_in(units.yr)))
    native_plot.xlim(memory.xlimits)
    native_plot.ylim(memory.ylimits)
    native_plot.pause(0.0001)
    memory.xlimits = native_plot.gca().get_xlim()
    memory.ylimits = native_plot.gca().get_ylim()
    if i_step == n_steps-1:
        native_plot.show(block=True)
    native_plot.cla()
def planetplot():
    sun, planets = new_solar_system_for_mercury()

    initial = 12.2138 | units.Gyr
    final = 12.3300 | units.Gyr
    step = 10000.0 | units.yr

    timerange = VectorQuantity.arange(initial, final, step)
    gd = MercuryWayWard()
    gd.initialize_code()
    # gd.stopping_conditions.timeout_detection.disable()
    gd.central_particle.add_particles(sun)
    gd.orbiters.add_particles(planets)
    gd.commit_particles()

    se = SSE()
    # se.initialize_code()
    se.commit_parameters()
    se.particles.add_particles(sun)
    se.commit_particles()
    channelp = gd.orbiters.new_channel_to(planets)
    channels = se.particles.new_channel_to(sun)

    for time in timerange:
        err = gd.evolve_model(time-initial)
        channelp.copy()
        # planets.savepoint(time)
        err = se.evolve_model(time)
        channels.copy()
        gd.central_particle.mass = sun.mass
        print(
                sun[0].mass.value_in(units.MSun),
                time.value_in(units.Myr),
                planets[4].x.value_in(units.AU),
                planets[4].y.value_in(units.AU),
                planets[4].z.value_in(units.AU)
                )

    gd.stop()
    se.stop()

    for planet in planets:
        t, x = planet.get_timeline_of_attribute_as_vector("x")
        t, y = planet.get_timeline_of_attribute_as_vector("y")
        plot(x, y, '.')
        native_plot.gca().set_aspect('equal')

    native_plot.show()
Beispiel #7
0
def polyevolve():
    sun, planets = Solarsystem.new_solarsystem()

    gd, se = setup_codes(sun, planets)

    channelp = gd.orbiters.new_channel_to(planets)
    channels = se.particles.new_channel_to(sun)

    prev_mass = sun[0].mass

    massrange = units.MSun(numpy.arange(0.9, 0.89999, -1e-9))
    masses = [] | units.MSun
    timerange = [] | units.Myr

    for i, mass in enumerate(massrange):
        time, dummymass = se.evolve_mass(mass)
        if i == 0:
            initialtime = time
        print(time, mass, "evolving gd")
        gdtime = time - initialtime
        print(gdtime)
        err = gd.evolve_model(gdtime)
        channelp.copy()
        planets.savepoint(time)
        channels.copy()
        gd.central_particle.mass = sun[0].mass
        print(sun[0].mass)
        print(
            sun[0].mass.value_in(units.MSun),
            time.value_in(units.Myr),
            planets[4].x.value_in(units.AU),
            planets[4].y.value_in(units.AU),
            planets[4].z.value_in(units.AU),
        )

    gd.stop()
    se.stop()

    for planet in planets:
        t, x = planet.get_timeline_of_attribute_as_vector("x")
        t, y = planet.get_timeline_of_attribute_as_vector("y")
        t, z = planet.get_timeline_of_attribute_as_vector("z")
        plot3(x, y, z, '.')
        native_plot.gca().set_aspect('equal')

    native_plot.show()
def polyevolve():
    sun, planets = Solarsystem.new_solarsystem()

    gd, se = setup_codes(sun, planets)

    channelp = gd.orbiters.new_channel_to(planets)
    channels = se.particles.new_channel_to(sun)

    prev_mass = sun[0].mass

    massrange = units.MSun(numpy.arange(0.9, 0.89999, -1e-9))
    masses = [] | units.MSun
    timerange = [] | units.Myr

    for i, mass in enumerate(massrange):
        time, dummymass = se.evolve_mass(mass)
        if i == 0:
            initialtime = time
        print time, mass, "evolving gd"
        gdtime = time-initialtime
        print gdtime
        err = gd.evolve_model(gdtime)
        channelp.copy()
        planets.savepoint(time)
        channels.copy()
        gd.central_particle.mass = sun[0].mass
        print sun[0].mass
        print(
                sun[0].mass.value_in(units.MSun),
                time.value_in(units.Myr),
                planets[4].x.value_in(units.AU),
                planets[4].y.value_in(units.AU),
                planets[4].z.value_in(units.AU),
                )

    gd.stop()
    se.stop()

    for planet in planets:
        t, x = planet.get_timeline_of_attribute_as_vector("x")
        t, y = planet.get_timeline_of_attribute_as_vector("y")
        t, z = planet.get_timeline_of_attribute_as_vector("z")
        plot3(x, y, z, '.')
        native_plot.gca().set_aspect('equal')

    native_plot.show()
Beispiel #9
0
def monitor_density_profile(system, i_step, time, n_steps, memory=Memory()):
    if i_step == 0:
        memory.xlimits = (None, None)
        memory.ylimits = (None, None)
    position = system.gas_particles.position - system.gas_particles.center_of_mass(
    )
    loglog(position.lengths_squared(), system.gas_particles.density, 'gs')
    native_plot.title("{0}: t={1}".format(i_step,
                                          time.as_quantity_in(units.yr)))
    native_plot.xlim(memory.xlimits)
    native_plot.ylim(memory.ylimits)
    native_plot.pause(0.0001)
    memory.xlimits = native_plot.gca().get_xlim()
    memory.ylimits = native_plot.gca().get_ylim()
    if i_step == n_steps - 1:
        native_plot.show(block=True)
    native_plot.cla()
Beispiel #10
0
def planetplot():
    sun, planets = new_solar_system_for_mercury()

    initial = 12.2138 | units.Gyr
    final = 12.3300 | units.Gyr
    step = 10000.0 | units.yr

    timerange = VectorQuantity.arange(initial, final, step)
    gd = MercuryWayWard()
    gd.initialize_code()
    # gd.stopping_conditions.timeout_detection.disable()
    gd.central_particle.add_particles(sun)
    gd.orbiters.add_particles(planets)
    gd.commit_particles()

    se = SSE()
    # se.initialize_code()
    se.commit_parameters()
    se.particles.add_particles(sun)
    se.commit_particles()
    channelp = gd.orbiters.new_channel_to(planets)
    channels = se.particles.new_channel_to(sun)

    for time in timerange:
        err = gd.evolve_model(time - initial)
        channelp.copy()
        # planets.savepoint(time)
        err = se.evolve_model(time)
        channels.copy()
        gd.central_particle.mass = sun.mass
        print(
            (sun[0].mass.value_in(units.MSun), time.value_in(units.Myr),
             planets[4].x.value_in(units.AU), planets[4].y.value_in(units.AU),
             planets[4].z.value_in(units.AU)))

    gd.stop()
    se.stop()

    for planet in planets:
        t, x = planet.get_timeline_of_attribute_as_vector("x")
        t, y = planet.get_timeline_of_attribute_as_vector("y")
        plot(x, y, '.')
        native_plot.gca().set_aspect('equal')

    native_plot.show()