Exemple #1
0
def distributions_snapshot(gigafile_name):
    from pylab import scatter, show, xlim, ylim, clf, savefig, title, xlabel, ylabel

    print "Outputting Average Distribution Snapshot"

    dfo = DFO(os.path.join(general.get_path(settings.OUTPUT_DIRECTORY), gigafile_name))

    distributions = []
    for ts in range(dfo.num_timesteps()):
        distributions.append(dfo.get_timestep(ts).get_distribution())

    avg_distribution = stats.average_distributions(distributions)

    x_vals = []
    y_vals = []

    for i in range(len(avg_distribution)):
        if avg_distribution[i] == 0:
            continue
        x_vals.append(i)
        y_vals.append(math.log(avg_distribution[i]))

    title("Bin Counts")
    xlabel("Bin")
    ylabel("Count")
    scatter(x_vals, y_vals)
    savefig(os.path.join(general.get_path(settings.OUTPUT_DIRECTORY), "distribution.png"))
Exemple #2
0
	def snapshot(self, timestep, to_screen = False):
		from pylab import scatter, show, xlim, ylim, clf, savefig, title, xlabel, ylabel
		import os

		x_vals = []
		y_vals = []

		for p in self.pucks:
			x_vals.append(p.get_x())
			y_vals.append(p.get_y())

		#if we don't clear, things build up in the buffer and we get
		#magic spawning pucks - this buffer must exist in the global namespace
		clf()

		title("Puck Positions (pucks not to scale)")
		xlabel("Table Width")
		ylabel("Table Height")
		scatter(x_vals, y_vals,s=710.0)
		xlim( (0, settings.TABLE_WIDTH) )
		ylim( (0, settings.TABLE_HEIGHT) )
		savefig(os.path.join(general.get_path(settings.OUTPUT_DIRECTORY), "ts_%s.png" % (timestep)))

		if to_screen:
			show()
Exemple #3
0
def heatmap(gigafile_name):
    import numpy

    dfo = DFO(os.path.join(general.get_path(settings.OUTPUT_DIRECTORY), gigafile_name))

    DIMX = 50
    DIMY = 50
    dx = dfo.get_timestep(0).get_table().get_width() / DIMX
    dy = dfo.get_timestep(0).get_table().get_height() / DIMY
    grid = numpy.zeros((DIMX, DIMY), "float32")
    for ts in range(dfo.num_timesteps()):
        pucks = dfo.get_timestep(ts).get_table().get_pucks()
        for puck in pucks:
            x, y = puck.get_x(), puck.get_y()
            bin_x = int(x / dx)
            bin_y = int(y / dy)
            grid[bin_x, bin_y] += 1
    dat_file = open(os.path.join("..", "output", "datfile.txt"), "w")
    for x in range(grid.shape[0]):
        for y in range(grid.shape[1]):
            dat_file.write("%s %s %s\n" % (x * dx, y * dy, grid[x, y]))
        dat_file.write("\n")
    dat_file.close()

    # output gnuplot config file
    config = open(os.path.join("..", "output", "gnuplot.config"), "w")
    config.write("set view map\n")
    config.write("set contour base\n")
    config.write("set output '%s'\n" % (os.path.join("..", "output", "heatmap.png")))
    config.write("set term png\n")
    config.write("splot '%s' w pm3d\n" % (os.path.join("..", "output", "datfile.txt")))
    config.write("set terminal windows\n")
    config.close()
    os.system("%s %s" % (settings.GNUPLOT_COMMAND, os.path.join("..", "output", "gnuplot.config")))
Exemple #4
0
	def file_snapshot(self, timestep):
		import os

		output = os.path.join(general.get_path(settings.OUTPUT_DIRECTORY), "ts_%s.txt" % (timestep))
		snapshot = open(output, 'w')
		for puck in self.pucks:
			name= puck.get_name()
			xx = puck.get_x()
			xy = puck.get_y()
			vx = puck.get_vx()
			vy = puck.get_vy()

			snapshot.write("%s %s %s %s %s\n" % (name, xx, xy, vx, vy))
		snapshot.close()
Exemple #5
0
	def gigasnap(self, timestep):
		import os
		try:
			self.gigafile
		except(AttributeError):
			self.gigafile = open(os.path.join(general.get_path(settings.OUTPUT_DIRECTORY), self.GIGAFILE_NAME), 'w')

		self.gigafile.write("#Timestep: %s\n" % (timestep))
		for puck in self.pucks:
			output_str = "%s %s %s %s %s" % (
				puck.get_name(),
				puck.get_x(),
				puck.get_y(),
				puck.get_vx(),
				puck.get_vy()
			)
			self.gigafile.write("%s\n" % (output_str))
		self.gigafile.write("\n") #separate this timestep from the next