Exemplo n.º 1
0
def make_movie(input_filename, output_filename):
    cluster, gas = read_set_from_file(input_filename, 'amuse', 
            names=("cluster", "gas"))
    lim = abs(next(cluster.history).position).max()
    
    fig = pyplot.figure(figsize=[10,10])

    artists = []
    for cl, gas in zip(cluster.history, gas.history):
        print "Creating frame at time", cl.get_timestamp()
        points = aplot.scatter(cl.x, cl.y, c='black')
        gas_points = aplot.scatter(gas.x, gas.y, s=100, c='b', 
                edgecolors='none', alpha=0.3, rasterized=True)

        time_label = "t = {:.2f} Myr".format(
                cl.get_timestamp().value_in(units.Myr))
        text = aplot.text(-4./5.*lim, 4./5.*lim, time_label)
        aplot.xlabel("X")
        aplot.ylabel("Y")
        pyplot.axis('equal')
        aplot.xlim(-lim, lim)
        aplot.ylim(-lim, lim)
        pyplot.savefig("plots/test."+str(cl.get_timestamp().value_in(units.Myr))+".png")
        pyplot.close()
                

        artists.append((points, gas_points, text))
Exemplo n.º 2
0
    def test7(self):
        """ Test setting the x and y limits in various ways"""
        if not HAS_MATPLOTLIB:
            return self.skip()
        pyplot.clf()
        set_printing_strategy('default')

        x = numpy.linspace(0, 100, 100)
        y = numpy.linspace(0, 200, 100) | units.RSun

        line = aplot.plot(x, y)

        aplot.xlim(-10, 80)
        self.assertEquals(-10, pyplot.xlim()[0])
        self.assertEquals(80, pyplot.xlim()[1])

        print pyplot.xlim()
        aplot.xlim(xmax=90)
        print pyplot.xlim()
        self.assertEquals(-10, pyplot.xlim()[0])
        self.assertEquals(90, pyplot.xlim()[1])

        aplot.ylim([-12, 110] | units.RSun)
        self.assertEquals(-12, pyplot.ylim()[0])
        self.assertEquals(110, pyplot.ylim()[1])

        aplot.ylim(ymin=1e6 | units.km)
        self.assertAlmostEquals(1.43781452, pyplot.ylim()[0])
        self.assertEquals(110, pyplot.ylim()[1])
Exemplo n.º 3
0
    def test7(self):
        """ Test setting the x and y limits in various ways"""
        if not HAS_MATPLOTLIB:
            return self.skip()
        pyplot.clf()
        set_printing_strategy('default')

        x = numpy.linspace(0, 100, 100)
        y = numpy.linspace(0, 200, 100) | units.RSun

        line = aplot.plot(x, y)

        aplot.xlim(-10, 80)
        self.assertEquals(-10, pyplot.xlim()[0])
        self.assertEquals(80, pyplot.xlim()[1])

        print pyplot.xlim()
        aplot.xlim(xmax=90)
        print pyplot.xlim()
        self.assertEquals(-10, pyplot.xlim()[0])
        self.assertEquals(90, pyplot.xlim()[1])

        aplot.ylim([-12, 110]|units.RSun)
        self.assertEquals(-12, pyplot.ylim()[0])
        self.assertEquals(110, pyplot.ylim()[1])

        aplot.ylim(ymin=1e6|units.km)
        self.assertAlmostEquals(1.43781452, pyplot.ylim()[0])
        self.assertEquals(110, pyplot.ylim()[1])
Exemplo n.º 4
0
    def dm_rvir_gas_sph_subplot(self):
        fig = pyplot.figure(figsize=(20, 10))
        ax_dm = fig.add_subplot(121, aspect='equal')
        ax_gas = fig.add_subplot(122, aspect='equal',
            sharex=ax_dm, sharey=ax_dm)

        # plot dark matter
        center_of_mass = self.dm.center_of_mass()
        virial_radius = self.dm.virial_radius().as_quantity_in(units.kpc)
        innersphere = self.dm.select(lambda r: (center_of_mass-r).length()<virial_radius,["position"])
        outersphere = self.dm.select(lambda r: (center_of_mass-r).length()>= virial_radius,["position"])
        pyplot.gcf().sca(ax_dm)
        x = outersphere.x.as_quantity_in(units.kpc)
        y = outersphere.y.as_quantity_in(units.kpc)
        scatter(x, y, c='red', edgecolor='red', label=r'$r \geq r_{\rm vir}$')
        x = innersphere.x.as_quantity_in(units.kpc)
        y = innersphere.y.as_quantity_in(units.kpc)
        scatter(x, y, c='green', edgecolor='green', label=r'$r < r_{\rm vir}$')
        xlabel(r'$x$')
        ylabel(r'$y$')
        pyplot.legend()

        # plot gas as sph plot

        # Adjusted code from amuse.plot.sph_particles_plot
        pyplot.gcf().sca(ax_gas)
        min_size = 100
        max_size = 10000
        alpha = 0.1
        x = self.gas.x.as_quantity_in(units.kpc)
        y = self.gas.y.as_quantity_in(units.kpc)
        z = self.gas.z.as_quantity_in(units.kpc)
        z, x, y, us, h_smooths = z.sorted_with(x, y, self.gas.u, self.gas.h_smooth)
        u_min, u_max = min(us), max(us)

        log_u = numpy.log((us / u_min)) / numpy.log((u_max / u_min))
        clipped_log_u = numpy.minimum(numpy.ones_like(log_u), numpy.maximum(numpy.zeros_like(log_u), log_u))

        red = 1.0 - clipped_log_u**4
        blue = clipped_log_u**4
        green = numpy.minimum(red, blue)

        colors = numpy.transpose(numpy.array([red, green, blue]))
        n_pixels = pyplot.gcf().get_dpi() * pyplot.gcf().get_size_inches()

        ax_gas.set_axis_bgcolor('#101010')
        ax_gas.set_aspect("equal", adjustable="datalim")
        phys_to_pix2 = n_pixels[0]*n_pixels[1] / ((max(x)-min(x))**2 + (max(y)-min(y))**2)
        sizes = numpy.minimum(numpy.maximum((h_smooths**2 * phys_to_pix2), min_size), max_size)

        scatter(x, y, color=colors, s=sizes, edgecolors="none", alpha=alpha)
        xlabel(r'$x$')
        ylabel(r'$y$')

        xlim(-2.*virial_radius, 2*virial_radius)
        ylim(-2.*virial_radius, 2*virial_radius)
        pyplot.tight_layout()
        pyplot.show()
def make_plots(Ncl, Rcl, t_end):
    """ Not finished """
    try:
        import matplotlib
        matplotlib.use("Agg")
        from matplotlib import pyplot
    except ImportError:
        print "Unable to produce plots: couldn't find matplotlib"
    else:
        fig = pyplot.figure(figsize=[10, 10])
        for data in ["hybrid", "tree", "direct"]
            print "Generating plot data of {0} run".format(data)
            data_file = "CA_Exam_TLRH_{0}.amuse".format(data)

            stars_below_cut, stars_above_cut =\
            read_set_from_file(data_file, 'amuse',
                               names=("stars_below_cut", "stars_below_cut"))

            lim = abs(next(stars_below_cut.history).position).max()

            if data == "hybrid":
                pass
                # dashed curve
                # points = aplot.scatter(dE, time, c='orange',
                #               label='Hybrid')


            if data == "direct":
                pass
                # dotted curve
                # points = aplot.scatter(dE, time, c='red',
                #               label='Direct')

            if data == "tree":
                pass
                # solid curve
                # points = aplot.scatter(dE, time, c='green',
                #               label='Tree')

        aplot.xlabel("Time")
        aplot.ylabel("Relative Energy Error")
        pyplot.axis('equal')
        aplot.xlim(-lim, lim)
        aplot.ylim(-lim, lim)
        pyplot.legend()
        pyplot.title(r'Cluster with $N=${0}, $r=${1}'
                     .format(Ncl, Rcl ) +
                     r', evolved until $t_{\rm end}$={0}'
                     .format(t_end))
        pyplot.savefig("out.png")
        pyplot.close()
Exemplo n.º 6
0
    def test6(self):
        """ Test setting the x limits on a plot """
        if not HAS_MATPLOTLIB:
            return self.skip()
        pyplot.clf()
        set_printing_strategy('default')

        x = numpy.linspace(0, 100, 100) | units.yr
        y = numpy.linspace(0, 200, 100) | units.RSun

        line = aplot.plot(x, y)

        aplot.xlim(0 | units.yr, 2e9 | units.s)

        self.assertAlmostEquals(0, pyplot.xlim()[0])
        self.assertAlmostEquals(63.37752924, pyplot.xlim()[1])
Exemplo n.º 7
0
    def test6(self):
        """ Test setting the x limits on a plot """
        if not HAS_MATPLOTLIB:
            return self.skip()
        pyplot.clf()
        set_printing_strategy('default')

        x = numpy.linspace(0, 100, 100) | units.yr
        y = numpy.linspace(0, 200, 100) | units.RSun

        line = aplot.plot(x, y)

        aplot.xlim(0|units.yr, 2e9|units.s)

        self.assertAlmostEquals(0, pyplot.xlim()[0])
        self.assertAlmostEquals(63.37752924, pyplot.xlim()[1])
Exemplo n.º 8
0
def subplot(potential, orbits, codes, fit_orbit, labels):
    hor, vert = labels
    X = numpy.linspace(-160, 160, 100) | units.parsec
    Y = numpy.linspace(-160, 160, 100) | units.parsec
    X, Y = quantities.meshgrid(X, Y)

    if labels == 'xy':
        pot_args = [X, Y, 0 | units.parsec]
        fit_horizontal = fit_orbit[0]
        fit_vertical = fit_orbit[1]
    elif labels == 'xz':
        pot_args = [X, 0 | units.parsec, Y]
        fit_horizontal = fit_orbit[0]
        fit_vertical = fit_orbit[2]
    elif labels == 'yz':
        pot_args = [0 | units.parsec, X, Y]
        fit_horizontal = fit_orbit[1]
        fit_vertical = fit_orbit[2]

    phi = potential.get_potential_at_point(None, *pot_args)
    aplot.imshow_color_plot(X, Y, phi, cmap="Blues")
    del aplot.UnitlessArgs.arg_units[2]

    aplot.scatter(0 | units.parsec, 0 | units.parsec, c='black')
    aplot.plot(fit_horizontal,
               fit_vertical,
               c="green",
               ls="--",
               label="Kruijssen et al. 2014")

    colors = cycle(['red', 'black', 'yellow', 'grey', 'green'])

    for full_orbit, code in zip(orbits, codes):
        horizontal = full_orbit.x if hor == 'x' else full_orbit.y
        vertical = full_orbit.y if vert == 'y' else full_orbit.z
        color = next(colors)
        aplot.plot(horizontal, vertical, c=color, label=code)
        aplot.scatter(horizontal[-1], vertical[-1], c=color, edgecolor=color)

    pyplot.axis('equal')
    aplot.xlim([-150, 150] | units.parsec)
    aplot.ylim([-150, 150] | units.parsec)
    aplot.xlabel(hor)
    aplot.ylabel(vert)
Exemplo n.º 9
0
def subplot(potential, orbits, codes, fit_orbit, labels):
    hor, vert = labels
    X = numpy.linspace(-160, 160, 100) | units.parsec
    Y = numpy.linspace(-160, 160, 100) | units.parsec
    X, Y = quantities.meshgrid(X, Y)

    if labels == 'xy':
        pot_args = [X, Y, 0 | units.parsec]
        fit_horizontal = fit_orbit[0]
        fit_vertical = fit_orbit[1]
    elif labels == 'xz':
        pot_args = [X, 0 | units.parsec, Y]
        fit_horizontal = fit_orbit[0]
        fit_vertical = fit_orbit[2]
    elif labels == 'yz':
        pot_args = [0 | units.parsec, X, Y]
        fit_horizontal = fit_orbit[1]
        fit_vertical = fit_orbit[2]

    phi = potential.get_potential_at_point(None, *pot_args)
    aplot.imshow_color_plot(X, Y, phi, cmap="Blues")
    del aplot.UnitlessArgs.arg_units[2]

    aplot.scatter(0 | units.parsec, 0 | units.parsec, c='black')
    aplot.plot(fit_horizontal, fit_vertical, c="green", ls="--",
               label="Kruijssen et al. 2014")

    colors = cycle(['red', 'black', 'yellow', 'grey', 'green'])

    for full_orbit, code in zip(orbits, codes):
        horizontal = full_orbit.x if hor == 'x' else full_orbit.y
        vertical = full_orbit.y if vert == 'y' else full_orbit.z
        color = next(colors)
        aplot.plot(horizontal, vertical, c=color, label=code)
        aplot.scatter(horizontal[-1], vertical[-1], c=color, edgecolor=color)

    pyplot.axis('equal')
    aplot.xlim([-150, 150] | units.parsec)
    aplot.ylim([-150, 150] | units.parsec)
    aplot.xlabel(hor)
    aplot.ylabel(vert)
Exemplo n.º 10
0
            fig = pyplot.figure(figsize=[10, 10])

            artists = []
            cl = None
            gas = None
            for c, g in zip(cluster.history, gascloud.history):
                cl = c
                gas = g
            points = aplot.scatter(cl.x, cl.y, c='black',
                                   label='Stellar Cluster')
            gas_points = aplot.scatter(gas.x, gas.y, s=100, c='b',
                                       edgecolors='none', alpha=0.3,
                                       rasterized=True,
                                       label='Giant Molecular Cloud')

            time_label = r'$t_{\rm end}$ ' + "= {:.2f} Myr".format(cl.get_timestamp().
                                                 value_in(units.Myr))
            text = aplot.text(-4./5.*lim, 4./5.*lim, time_label)
            aplot.xlabel("X")
            aplot.ylabel("Y")
            pyplot.axis('equal')
            aplot.xlim(-lim, lim)
            aplot.ylim(-lim, lim)
            pyplot.legend()
            pyplot.title(r'Cluster orbitting GMC with $d$={0}, $v_\infty$={1}'
                         .format(impact_parameter, v_infinity) +
                         r', at $t_{\rm end}$')
            pyplot.savefig(out_file)
            pyplot.close()