コード例 #1
0
ファイル: graph.py プロジェクト: MBradbury/slp
def angle_heapmaps(description, zextractor):
	configuration_names = Configuration.names()
	configurations = [Configuration.create_specific(name, 11, 4.5, "topology") for name in Configuration.names()]

	#Get rid of configurations that aren't grids
	configurations = filter(lambda c: isinstance(c.topology, Grid), configurations)

	# Get rid of configurations that do not have 2 sources
	configurations = filter(lambda c: len(c.source_ids) == 2, configurations)

	grapher = configuration_heatmap.Grapher("results/Configurations", description, zextractor)

	grapher.nokey = True
	grapher.xaxis_label = "X Coordinate"
	grapher.yaxis_label = "Y Coordinate"
	grapher.cb_label = "Source Angle"

	grapher.dgrid3d_dimensions = "11,11"

	grapher.cbrange = (0, 180)

	grapher.create(configurations)

	summary_grapher = summary.GraphSummary(
	    os.path.join("results/Configurations", description),
	    '{}-{}'.format("results/Configurations", description)
	)

	summary_grapher.width_factor = None
	summary_grapher.height = "7cm"

	summary_grapher.run()
コード例 #2
0
    parser.add_argument(
        "-d",
        "--distance",
        type=ArgumentsCommon.type_positive_float,
        default=4.5,
        help=
        "The distance between nodes. How this is used depends on the configuration specified."
    ),

    parser.add_argument(
        "-nido",
        "--node-id-order",
        choices=("topology", "randomised"),
        default="topology",
        help=
        "With 'topology' node id orders are the same as the topology defines. 'randomised' causes the node ids to be randomised."
    ),

    parser.add_argument("--show", default=False, action="store_true")

    args = parser.parse_args()

    configuration = Configuration.create_specific(args.configuration,
                                                  args.network_size,
                                                  args.distance,
                                                  args.node_id_order,
                                                  seed=args.seed)

    main(configuration, show=args.show)
コード例 #3
0
ファイル: graph.py プロジェクト: MBradbury/slp
from simulator.Topology import Grid
from data.graph import summary, configuration_heatmap

parser = argparse.ArgumentParser(description="Misc. Grapher", add_help=True)
parser.add_argument("--min-source-distance-heatmap", action='store_true', default=False)
parser.add_argument("--source-angle-estimate-heatmap", action='store_true', default=False)
parser.add_argument("--source-angle-meters-heatmap", action='store_true', default=False)
parser.add_argument("--source-angle-actual-heatmap", action='store_true', default=False)
parser.add_argument("--source-angle-det-heatmap", action='store_true', default=False)
parser.add_argument("--source-angle-tan-heatmap", action='store_true', default=False)

args = parser.parse_args(sys.argv[1:])

if args.min_source_distance_heatmap:
	configuration_names = Configuration.names()
	configurations = [Configuration.create_specific(name, 11, 4.5, "topology") for name in Configuration.names()]

	#Get rid of configurations that aren't grids
	configurations = filter(lambda c: isinstance(c.topology, Grid), configurations)

	def zextractor(configuration, nid):
		return min(configuration.node_source_distance(nid, src_id) for src_id in configuration.source_ids)

	grapher = configuration_heatmap.Grapher("results/Configurations", "min-src-distance", zextractor)

	grapher.nokey = True
	grapher.xaxis_label = "X Coordinate"
	grapher.yaxis_label = "Y Coordinate"
	grapher.cb_label = "Minimum Source Distance (m)"

	grapher.create(configurations)
コード例 #4
0
ファイル: heatmap.py プロジェクト: MBradbury/slp
    def _create_plot(self, global_params, src_period, params, results):
        def chunks(l, n):
            """ Yield successive n-sized chunks from l."""
            for i in range(0, len(l), n):
                yield l[i:i + n]

        global_parameter_names = self._key_names_base

        # Pop the source period off the end of the parameters
        global_params_dict = dict(
            zip(global_parameter_names[:-1], global_params))

        config = global_params_dict["configuration"]
        size = int(global_params_dict["network size"])
        distance = float(global_params_dict["distance"])
        nido = global_params_dict["node id order"]

        dat = results[self.result_index]

        # The dat is a (mean, var) pair, so take the mean
        if isinstance(dat, np.ndarray):
            dat = dat[0]

        if not isinstance(dat, dict):
            raise RuntimeError(
                "The data is not a dict. It is a {} with value {}".format(
                    type(dat), dat))

        dir_name = os.path.join(
            self.output_directory, self.result_name,
            *(global_params + (str(src_period), ) + tuple(map(str, params))))

        print(dir_name)

        # Ensure that the dir we want to put the files in actually exists
        data.util.create_dirtree(dir_name)

        configuration = Configuration.create_specific(config, size, distance,
                                                      nido)

        (minx, miny) = configuration.minxy_coordinates()
        (maxx, maxy) = configuration.maxxy_coordinates()

        self._write_plot_data(dir_name, configuration, dat)

        with open(os.path.join(dir_name, 'graph.gp'), 'w') as graph_p:
            graph_p.write('#!/usr/bin/gnuplot\n')

            graph_p.write('set terminal pdf enhanced\n')
            graph_p.write('set output "graph.pdf" \n')

            if self.palette is not None:
                graph_p.write('set palette {}\n'.format(self.palette))

            #graph_p.write('set title "Heat Map of Messages Sent"\n')
            graph_p.write('unset key\n')
            #graph_p.write('set size ratio 0.5\n')
            #graph_p.write('set tic scale 0\n')

            graph_p.write('set xlabel "X Coordinate"\n')
            graph_p.write('set ylabel "Y Coordinate"\n')

            graph_p.write('set size square\n')

            # To top left to be (0, 0)
            graph_p.write('set xrange [{}:{}]\n'.format(minx, maxx))
            graph_p.write('set xtics auto\n')

            #graph_p.write('set yrange [{}:{}] reverse\n'.format(maxy, miny))
            graph_p.write('set yrange [:] reverse\n')
            graph_p.write('set ytics auto\n')

            graph_p.write('set cbrange [:]\n')
            graph_p.write('set cblabel "{}"\n'.format(
                self.result_name.title()))

            graph_p.write('set dgrid3d {0},{0}\n'.format(size))
            graph_p.write('set pm3d map interpolate 3,3\n')

            graph_p.write('splot "graph.dat" using 1:2:3 with pm3d\n')

        with open(os.path.join(dir_name, 'graph.caption'),
                  'w') as graph_caption:
            graph_caption.write('Parameters:\\newline\n')
            for (name, value) in global_params_dict.items():
                graph_caption.write('{}: {}\\newline\n'.format(
                    latex.escape(name.title()), latex.escape(value)))
            for (name, value) in zip(self.results.parameter_names, params):
                graph_caption.write('{}: {}\\newline\n'.format(
                    latex.escape(str(name)), latex.escape(str(value))))