debug_plots.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 # -*- coding: utf-8 -*-
00003 
00004 # File formats (space separated):
00005 # /tmp/{node_name}_place_profile.dat: x y
00006 # /tmp/{node_name}_delaunay_input.dat: x y
00007 # /tmp/{node_name}_delaunay_edges.dat: x1 y1 x2 y2
00008 # /tmp/{node_name}_delaunay_circumcircles.dat: x y r
00009 
00010 from __future__ import print_function, division
00011 
00012 import os
00013 import sys
00014 import numpy as np
00015 import matplotlib
00016 matplotlib.use('Qt4Agg')
00017 import matplotlib.pyplot as plt
00018 from matplotlib.collections import LineCollection
00019 from matplotlib.collections import PatchCollection
00020 from matplotlib.patches import Circle
00021 
00022 # Map size in meters.
00023 map_width = 4
00024 map_height = 4
00025 
00026 
00027 def get_filename(node, dataname):
00028     filename = '/tmp/' + node + '_' + dataname + '.dat'
00029     if not os.path.exists(filename):
00030         raise ValueError('File {} does not exist'.format(filename))
00031     return filename
00032 
00033 
00034 def load_data(node, dataname):
00035     try:
00036         return np.loadtxt(get_filename(node, dataname))
00037     except ValueError, e:
00038         print(e.message)
00039         return None
00040 
00041 
00042 def plot_edges(ax, edges, **kwargs):
00043     segs = []
00044     for x1, y1, x2, y2 in edges:
00045         segs.append([[x1, y1], [x2, y2]])
00046     col = LineCollection(segs, **kwargs)
00047     ax.add_collection(col)
00048 
00049 
00050 def plot_candidates(ax, candidates, **kwargs):
00051     rmax = candidates[:, 2].max()
00052     patches = []
00053     for x, y, r in candidates:
00054         patches.append(Circle((x, y), r))
00055         if r == rmax:
00056             # Add the best candidate twice, wo that it will be darker
00057             # if transparency is used
00058             patches.append(Circle((x, y), r))
00059     col = PatchCollection(patches, **kwargs)
00060     ax.add_collection(col)
00061 
00062 
00063 def do_plots(node):
00064     fig = plt.figure()
00065     ax = fig.add_subplot(1, 1, 1, aspect='equal')
00066 
00067     x = np.array([1, -1, -1, 1, 1]) * map_width / 2
00068     y = np.array([1, 1, -1, -1, 1]) * map_height / 2
00069     ax.plot(x, y, color='k', alpha=0.5)
00070 
00071     if do_plot_place_profile:
00072         place_profile = load_data(node, 'place_profile')
00073         if place_profile is not None:
00074             plt.plot(place_profile[:, 0], place_profile[:, 1],
00075                      'r.', markersize=4,
00076                      label='place_profile')
00077 
00078     if do_plot_delaunay_input:
00079         delaunay_input = load_data(node, 'delaunay_input')
00080         if delaunay_input is not None:
00081             plt.plot(delaunay_input[:, 0], delaunay_input[:, 1],
00082                      'b.', markersize=4,
00083                      label='delaunay_input')
00084 
00085     if do_plot_delaunay_edges:
00086         edges = load_data(node, 'delaunay_edges')
00087         if edges is not None:
00088             plot_edges(ax, edges, color='b', label='delaunay_edges')
00089 
00090     if do_plot_candidates:
00091         candidates = load_data(node, 'candidates')
00092         if candidates is not None:
00093             plot_candidates(ax, candidates, color=[0, 0.8, 0], alpha=0.1,
00094                             label='candidates')
00095 
00096     if do_plot_rejected:
00097         rejected = load_data(node, 'rejected')
00098         if rejected is not None:
00099             plot_candidates(ax, rejected, color=[0.9, 0, 0], alpha=0.1,
00100                             label='rejected')
00101 
00102     if (len(ax.lines) > 1) or ax.collections:
00103         ax.legend()
00104         ax.grid(True)
00105 
00106         plt.show()
00107 
00108 if __name__ == '__main__':
00109     if len(sys.argv) < 2:
00110         print('Usage: {} node_name'.format(sys.argv[0]) +
00111               ' [place_profile]' +
00112               ' [delaunay_input]' +
00113               ' [delaunay_edges]' +
00114               ' [candidates]' +
00115               ' [rejected]')
00116         exit()
00117     if len(sys.argv) > 2:
00118         do_plot_place_profile = 'place_profile' in sys.argv
00119         do_plot_delaunay_input = 'delaunay_input' in sys.argv
00120         do_plot_delaunay_edges = 'delaunay_edges' in sys.argv
00121         do_plot_candidates = 'candidates' in sys.argv
00122         do_plot_rejected = 'rejected' in sys.argv
00123     else:
00124         do_plot_place_profile = True
00125         do_plot_delaunay_input = True
00126         do_plot_delaunay_edges = False
00127         do_plot_candidates = False
00128         do_plot_rejected = False
00129     do_plots(sys.argv[1])


crossing_detector
Author(s): Gaël Ecorchard , Karel Košnar , Vojtěch Vonásek
autogenerated on Thu Jun 6 2019 22:02:06