tvaLib
Public Member Functions | Static Public Member Functions | List of all members
lib.vis.DrawOther Class Reference

Other. More...

Public Member Functions

def __init__ (self)
 

Static Public Member Functions

def DMPExperimental (predictionParameters, objects, site_analysis, config, fig_dpi=100, fig_format='png', dmp_plot_depth_frames=80, indent=8, plotSettings=None, verbose=0)
 
def viewInteractionAsDMP (userPairs, predictionParameters, site_analysis, config, fig_dpi=100, fig_format='png', dmp_plot_depth_frames=80, indent=8, plotSettings=None, verbose=0)
 
def DMP (data, plotcurvy=None, plotcurvyall=None, text='', extent=[0, mask=None, sm_scale=[0, colour='bone', interpolation='bilinear', xy_bounds=None, alignments=None, bounding_boxes=None, labels=True, local=None, verbose=0, fig_name='Motion Pattern Map', figsize=[15.0, plotSettings=None)
 
def DMP3D (data, plotcurvy=None, plotcurvyall=None, text='', colour='winter', marker='o', xy_bounds=None, alignments=None, bounding_boxes=None, labels=True, local=None, verbose=0, fig_name='3D Motion Pattern Map', figsize=[15.0)
 

Detailed Description

Other.

Definition at line 2117 of file vis.py.

Constructor & Destructor Documentation

◆ __init__()

def lib.vis.DrawOther.__init__ (   self)

Definition at line 2118 of file vis.py.

2118  def __init__(self):
2119  return
2120 

Member Function Documentation

◆ DMP()

def lib.vis.DrawOther.DMP (   data,
  plotcurvy = None,
  plotcurvyall = None,
  text = '',
  extent = [0,
  mask = None,
  sm_scale = [0,
  colour = 'bone',
  interpolation = 'bilinear',
  xy_bounds = None,
  alignments = None,
  bounding_boxes = None,
  labels = True,
  local = None,
  verbose = 0,
  fig_name = 'Motion Pattern Map',
  figsize = [15.0,
  plotSettings = None 
)
static
Plot 2D map (X,Y) of motion pattern array

    The plotting format is dependant on the type of data:
- Plot a hexbin if data is a 2-column-by-n-row matrix of points (x,y)
- Plot an imshow if data is a n*m matrix

Definition at line 2273 of file vis.py.

2273  def DMP(data, plotcurvy=None, plotcurvyall=None, text='', extent=[0,1,0,1], mask=None, sm_scale=[0,50], colour='bone', interpolation='bilinear', xy_bounds=None, alignments=None, bounding_boxes=None, labels=True, local=None, verbose=0, fig_name='Motion Pattern Map', figsize=[15.0,12.0], plotSettings=None):
2274  ''' Plot 2D map (X,Y) of motion pattern array
2275 
2276  The plotting format is dependant on the type of data:
2277  - Plot a hexbin if data is a 2-column-by-n-row matrix of points (x,y)
2278  - Plot an imshow if data is a n*m matrix
2279  '''
2280  fig = plt.figure(fig_name, figsize=(figsize[0], figsize[1]))
2281  ax = fig.add_subplot(111, axisbg='black')
2282  if(not local): local = tvaLocal.Local()
2283 
2284 
2285 
2286  from matplotlib.patches import Rectangle
2287  try: ax.add_patch(Rectangle((xy_bounds[0].lower-100, xy_bounds[1].lower-100), 1000, 1000, facecolor='black', zorder=-20))
2288  except: pass
2289 
2290 
2291  plotBB(mask, labels=labels, boxLabel=local['vis_mask'])
2292 
2293 
2294  if(type(data) == list and len(data) == 2 and type(data[0]) == list):
2295  Map(data, colour=colour, xy_bounds=xy_bounds, gridsize=[10,10], mincnt=2, sm_scale=sm_scale, full_plot=False)
2296  else:
2297  #Adjust transparency of colour map
2298  cm = plt.get_cmap(colour)
2299  #cm._init()
2300  #cm._lut[:-3,-1] = np.abs(np.linspace(-1.0, 1.0, cm.N))
2301  #Plot
2302  plt.imshow(np.transpose(data), interpolation=interpolation, cmap=cm, vmin=sm_scale[0], vmax=sm_scale[1], extent=(extent[0], extent[1], extent[2], extent[3]), origin='lower')
2303  cb = plt.colorbar()
2304  cb.set_label(local['vis_map_density'])
2305 
2306 
2307 
2308  plotAlign(alignments, labels=labels, plotSettings=plotSettings)
2309 
2310 
2311  plt.axis('equal')
2312  if(xy_bounds):
2313  ax.set_xlim([xy_bounds[0].lower,xy_bounds[0].upper])
2314  ax.set_ylim([xy_bounds[1].lower,xy_bounds[1].upper])
2315  ax.set_ylim(ax.get_ylim()[::-1])
2316 
2317 
2318  if(plotcurvy): plt.plot(plotcurvy[0], plotcurvy[1], color='c', linestyle='-', marker='', linewidth=4, zorder=20)
2319  if(plotcurvyall): plt.plot(plotcurvyall[0], plotcurvyall[1], color='r', linestyle='', marker='o', linewidth=4, zorder=22) if(plotcurvy): plt.plot(plotcurvy[0], plotcurvy[1], color='c', linestyle='', marker='o', linewidth=4, zorder=23)
2320  if(text): plt.annotate(text, xy=(0.95, 0.05), xycoords='axes fraction', xytext=(0.95, 0.05), textcoords='axes fraction', ha='right', va='bottom', bbox=dict(boxstyle='Square,pad=0.5', fc='white'), size=plotSettings['size']*0.5)
2321 
2322  return fig
2323 
2324 
2325 
def plotBB(bounding_boxes, labels=False, legacyLabels=False, boxLabel=None, outlineOnly=False, alpha=1.00, zorder=1, zone_bgcolour='0.66', plotSettings=None, kwargs)
Definition: vis.py:422
def plotAlign(alignments, custom_colours=None, draw_connectors=True, draw_corridors=True, labels=False, legacyLabels=False, distanceBetweenLabels=20.0, highContrastLabels=False, lineAlpha=1.0, annotateAlpha=0.2, corridorAlpha=0.5, zorder=20, plotSettings=None)
Definition: vis.py:477
def Map(pointList, colour='hot', xy_bounds=None, gridsize=[60, mincnt=1, sm_scale=None, alignments=False, mask=False, labels=False, local=None, fig_name='Generic Map', verbose=0, figsize=[15.0, full_plot=True)
Definition: vis.py:375

◆ DMP3D()

def lib.vis.DrawOther.DMP3D (   data,
  plotcurvy = None,
  plotcurvyall = None,
  text = '',
  colour = 'winter',
  marker = 'o',
  xy_bounds = None,
  alignments = None,
  bounding_boxes = None,
  labels = True,
  local = None,
  verbose = 0,
  fig_name = '3D Motion Pattern Map',
  figsize = [15.0 
)
static
Plot a 3D map (x,y,t) of motion pattern memory

    The plotting format is dependant on the type of data:
- Plot a scatter if data is a 4-column-by-n-row matrix of points (x,y,t,value)

Definition at line 2327 of file vis.py.

2327  def DMP3D(data, plotcurvy=None, plotcurvyall=None, text='', colour='winter', marker='o', xy_bounds=None, alignments=None, bounding_boxes=None, labels=True, local=None, verbose=0, fig_name='3D Motion Pattern Map', figsize=[15.0,12.0]):
2328  ''' Plot a 3D map (x,y,t) of motion pattern memory
2329 
2330  The plotting format is dependant on the type of data:
2331  - Plot a scatter if data is a 4-column-by-n-row matrix of points (x,y,t,value)
2332  '''
2333 
2334  fig = plt.figure(fig_name, figsize=(figsize[0], figsize[1]))
2335  ax = fig.add_subplot(111, projection='3d')
2336  if(not local): local = tvaLocal.Local()
2337 
2338 
2340 
2341 
2342  if(type(data) == list and len(data) == 4):
2343  cm = plt.get_cmap(colour)
2344  # Find max density
2345  max_density = 0
2346  for i in data[3]:
2347  if(max_density < i):
2348  max_density = i
2349  if(max_density == 0):
2350  return False
2351  for i in range(len(data[3])):
2352  #Filter empty values
2353  if(data[3][i] and data[3][i]/max_density > 0.2):
2354  alpha = data[3][i]/max_density
2355  traj_colour_actual = alpha,0,0
2356  p = ax.scatter(data[0][i], data[1][i], data[2][i], c=data[3][i], cmap=cm, marker=marker, color=traj_colour_actual, alpha=alpha)
2357  cb = fig.colorbar(p)
2358  cb.set_clim(0.1, max_density)
2359  else:
2360  return False
2361 
2362 
2363  plotAlign(alignments, labels=labels)
2364 
2365 
2366  ax = plb.gca()
2367  plt.axis('equal')
2368  if(xy_bounds):
2369  ax.set_xlim([xy_bounds[0].lower,xy_bounds[0].upper])
2370  ax.set_ylim([xy_bounds[1].lower,xy_bounds[1].upper])
2371  ax.set_ylim(ax.get_ylim()[::-1])
2372  ax.set_xlabel(local['vis_gen_x_coords_m'])
2373  ax.set_ylabel(local['vis_gen_y_coords_m'])
2374  ax.set_zlabel(local['vis_gen_z_coords_m'])
2375  cb.set_label(local['vis_map_density'])
2376 
2377 
2378  if(plotcurvy): plt.plot(plotcurvy[0], plotcurvy[1], color='r', linestyle='-', marker='', linewidth=4, zorder=20) if(plotcurvyall): plt.plot(plotcurvyall[0], plotcurvyall[1], color='r', linestyle='', marker='o', linewidth=4, zorder=22)
2379  if(text): annotate(text, 120, 120)
2380 
2381  return fig
2382 
2383 
def plotAlign(alignments, custom_colours=None, draw_connectors=True, draw_corridors=True, labels=False, legacyLabels=False, distanceBetweenLabels=20.0, highContrastLabels=False, lineAlpha=1.0, annotateAlpha=0.2, corridorAlpha=0.5, zorder=20, plotSettings=None)
Definition: vis.py:477
def annotate(text, x=None, y=None, target='bottom-right')
Definition: vis.py:580

◆ DMPExperimental()

def lib.vis.DrawOther.DMPExperimental (   predictionParameters,
  objects,
  site_analysis,
  config,
  fig_dpi = 100,
  fig_format = 'png',
  dmp_plot_depth_frames = 80,
  indent = 8,
  plotSettings = None,
  verbose = 0 
)
static
EXPERIMENTAL VISUALISATION 

Definition at line 2122 of file vis.py.

2122  def DMPExperimental(predictionParameters, objects, site_analysis, config, fig_dpi=100, fig_format='png', dmp_plot_depth_frames=80, indent=8, plotSettings=None, verbose=0):
2123  ''' EXPERIMENTAL VISUALISATION '''
2124 
2125  sampleSizes = predictionParameters.getSampleSizes()
2126 
2127 
2128  max_value, max_index = max((x, (i, j, k))
2129  for i, row in enumerate(sampleSizes)
2130  for j, row2 in enumerate(row)
2131  for k, x in enumerate(row2))
2132 
2133 
2134  histo1 = np.histogram(tvaLib.flatten_list(sampleSizes), bins=range(1,50))
2135  histo2 = np.histogram(tvaLib.flatten_list(sampleSizes), bins=range(1,15))
2136  empty = len(filter(None, tvaLib.flatten_list(sampleSizes)))
2137  top = deepcopy(tvaLib.flatten_list(sampleSizes))
2138  top.sort(reverse=True)
2139 
2140  fig = plt.figure('DMP initial conditions sample size distribution', figsize=(config.figsize[0], config.figsize[1]))
2141  ax1 = fig.add_subplot(221)
2142  ax1.bar(histo2[1][1:-1],histo2[0][1:], 1, color=(0.449, 0.449, 0.449), linewidth=0)
2143  ax1.set_ylabel('Initial conditions frequency')
2144  ax1.set_xlabel('Sample size')
2145  annotate('Empty initial conditions: '+str(empty), x=0.85, y=0.85, target='top-right')
2146  ax2 = fig.add_subplot(222)
2147  ax2.bar(histo1[1][1:-1],histo1[0][1:], 1, color=(0.449, 0.449, 0.449), linewidth=0)
2148  ax2.set_xlabel('Sample size')
2149  annotate('Empty initial conditions: '+str(empty), x=0.85, y=0.85, target='top-right')
2150  ax3 = fig.add_subplot(212)
2151  ax3.bar(range(200),top[0:200], 1, color=(0.449, 0.449, 0.449), linewidth=0)
2152  ax3.set_ylabel('Sample size')
2153  ax3.set_xlabel('Initial condition ordered by sample size')
2154  plt.tight_layout()
2155  Save(fig, site_analysis.getFullResultsFolder(config.output_folder, customSubPath='DMP'), fig_dpi=fig_dpi, fig_format=fig_format, verbose=verbose)
2156  plt.close(fig)
2157 
2158 
2159  nonZeroCellCount = predictionParameters.getNonZeroCellCount()
2160  print(''.rjust(indent,' ')+'Non-zero cells: '+str(nonZeroCellCount))
2161  print(''.rjust(indent,' ')+'DMP total cell size: '+str(predictionParameters.getSize()))
2162  print(''.rjust(indent,' ')+'Non-zero ratio: '+str(nonZeroCellCount/float(predictionParameters.getSize())))
2163 
2164  figures = []
2165  dmp_lane_i = max_index[0]
2166  dmp_curvy_i = max_index[1]
2167  dmp_speed_i = max_index[2]
2168  dmp_curvy_x_list = []
2169  dmp_curvy_y_list = []
2170 
2171  for align in range(len(site_analysis.site.alignments)):
2172  for point in predictionParameters.curvy[align][:]:
2173  [x,y] = tvaLib.Geo.getXYfromSY(point, site_analysis.site.alignments[align])
2174  dmp_curvy_x_list.append(x)
2175  dmp_curvy_y_list.append(y)
2176  dmp_total_greatest_count = 0
2177  for dmp_dt_i in range(1,dmp_plot_depth_frames):
2178  try: temp = predictionParameters.getLargestValAt(dmp_lane_i, dmp_curvy_i, dmp_speed_i, dmp_dt_i)
2179  except: #Prevent depth from exceeding available timehorzion
2180  dmp_plot_depth_frames = dmp_dt_i-1
2181  break
2182  if(temp > dmp_total_greatest_count): dmp_total_greatest_count = temp
2183  dmp_curvy_l = predictionParameters.curvy[dmp_lane_i][dmp_curvy_i]
2184  dmp_curvy_h = predictionParameters.curvy[dmp_lane_i][dmp_curvy_i+1]
2185  [dmp_curvy_x1, dmp_curvy_y1] = tvaLib.Geo.getXYfromSY(dmp_curvy_l, site_analysis.site.alignments[dmp_lane_i])
2186  [dmp_curvy_x2, dmp_curvy_y2] = tvaLib.Geo.getXYfromSY(dmp_curvy_h, site_analysis.site.alignments[dmp_lane_i])
2187 
2188 
2190 
2191  maxSum = 2000
2192  a = 0
2193  b = 0
2194  x_debug2 = []
2195  #percentiles = tvaLib.Math.getPercintileBinsFromList(histoDump, 50, includeLeftEdge=True, sampleSize=10000)
2196  for i in predictionParameters:
2197  i_sum = i.getMat().sum()
2198  if(i_sum > 0):
2199  x_debug2.append(i_sum)
2200  a += 1
2201  b += 1
2202 
2203  histo = np.histogram(x_debug2, bins=100)
2204  if(verbose): print histo, a, b
2205  Histo(histo, x_bounds=[0,maxSum])
2206 
2207 
2208  '''
2209  ######
2210  obj1 = 4
2211  to = 10
2212  timeHorizon = 50
2213  dmp_3d_data = [[],[],[],[]]
2214  #import pdb; pdb.set_trace()
2215  dmp_userType_i2 = predictionParameters.userType.findIDofLowerRangeFromValue(objects[obj1].getUserType())
2216  for dmp_dt_i in range(1, timeHorizon):
2217  dmp_lane_i2 = predictionParameters.lane.findIDofLowerRangeFromValue(objects[obj1].curvilinearPositions.getLanes()[to+dmp_dt_i])
2218  dmp_curvy_i2 = predictionParameters.curvy[dmp_lane_i2].findIDofLowerRangeFromValue(objects[obj1].curvilinearPositions.getXCoordinates()[to+dmp_dt_i])
2219  dmp_speed_i2 = predictionParameters.speed.findIDofLowerRangeFromValue(objects[obj1].getSpeeds()[to+dmp_dt_i])
2220  data = predictionParameters.getMatrixData(dmp_lane_i2, dmp_curvy_i2, dmp_speed_i2, dmp_userType_i2, dmp_dt_i, normalise=True)
2221  if(not data): break
2222  for x in range(len(data)):
2223  for y in range(len(data[x])):
2224  dmp_3d_data[0].append(x)
2225  dmp_3d_data[1].append(y)
2226  dmp_3d_data[2].append(dmp_dt_i)
2227  dmp_3d_data[3].append(data[x][y])
2228  figures.append(DrawOther.DMP3D(dmp_3d_data, plotcurvy=[[dmp_curvy_x1,dmp_curvy_x2],[dmp_curvy_y1,dmp_curvy_y2]], plotcurvyall=[dmp_curvy_x_list,dmp_curvy_y_list], text='something', xy_bounds=site_analysis.xy_bounds, alignments=site.alignments, bounding_boxes=site_analysis.zone, fig_name='Motion Pattern Map for object #'+str(obj1)))
2229  plt.show()'''
2230 
2231 
2232  for dmp_dt_i in range(1,dmp_plot_depth_frames):
2233  # Flush figure buffer
2234  if(dmp_dt_i % 5 == 0):
2235  Save(figures, site_analysis.getFullResultsFolder(config.output_folder, customSubPath='DMP'), fig_dpi=fig_dpi, verbose=verbose)
2236  figures = []
2237  dmp_data = predictionParameters.getMatrixData(dmp_lane_i, dmp_curvy_i, dmp_speed_i, dmp_dt_i, normalise=True); dmp_sm_scale = [0,0.030]
2238  #dmp_data = predictionParameters.getPointData(dmp_lane_i, dmp_curvy_i, dmp_speed_i, dmp_dt_i, format='columns'); dmp_sm_scale = [0,50]
2239  dmp_sample_size = predictionParameters.getSampleSizeAt(dmp_lane_i, dmp_curvy_i, dmp_speed_i, dmp_dt_i)
2240  dmp_greatest_density = predictionParameters.getLargestValAt(dmp_lane_i, dmp_curvy_i, dmp_speed_i, dmp_dt_i)
2241  dmp_an_text='sample size = {0}\ngreatest density = {1}\nlane = {2}\nS = [{3:.2f},{4:.2f}[ m\nspeed = [{5:.1f},{6:.1f}[ km/h\ndeltaTime = {7} frames'.format(dmp_sample_size, dmp_greatest_density, int(predictionParameters.lane[dmp_lane_i]+1), dmp_curvy_l, dmp_curvy_h, predictionParameters.speed[dmp_speed_i], predictionParameters.speed[dmp_speed_i+1], int(predictionParameters.deltatime[dmp_dt_i]))
2242  figures.append(DrawOther.DMP(dmp_data, plotcurvy=[[dmp_curvy_x1,dmp_curvy_x2],[dmp_curvy_y1,dmp_curvy_y2]], plotcurvyall=[dmp_curvy_x_list,dmp_curvy_y_list], text=dmp_an_text, sm_scale=dmp_sm_scale, extent=predictionParameters.getSpatialBounds(), interpolation='nearest', xy_bounds=site_analysis.xy_bounds, alignments=site_analysis.site.alignments, fig_name='DMP_deltatime_'+"%02d" % (int(predictionParameters.deltatime[dmp_dt_i])), plotSettings=plotSettings))
2243 
2244 
2245 
2246  Save(figures, site_analysis.getFullResultsFolder(config.output_folder, customSubPath='DMP'), fig_dpi=fig_dpi, verbose=verbose)
2247 
2248  return True
2249 
2250 
def annotate(text, x=None, y=None, target='bottom-right')
Definition: vis.py:580
def Save(figures, results_path='', fig_dpi=300, fig_format='png', fig_lan_suffix='', supressClose=False, fig_resize=None, fig_bg_colour='', verbose=0)
Definition: vis.py:77
def Histo(data, enableBars=True, dist_type='freq', enableHalfStepOffset=True, halfStepSign=1, legendLabels='', linewidth=2, spacing_modifier=1, x_bounds=None, y_bounds=None, x_label='', y_label='', force_one_label_per_bar=False, local=None, fig_name='Generic histogram', figsize=[15.0)
Definition: vis.py:164

◆ viewInteractionAsDMP()

def lib.vis.DrawOther.viewInteractionAsDMP (   userPairs,
  predictionParameters,
  site_analysis,
  config,
  fig_dpi = 100,
  fig_format = 'png',
  dmp_plot_depth_frames = 80,
  indent = 8,
  plotSettings = None,
  verbose = 0 
)
static
Plot a single interaction sequence as a series of DMP calculations 

Definition at line 2252 of file vis.py.

2252  def viewInteractionAsDMP(userPairs, predictionParameters, site_analysis, config, fig_dpi=100, fig_format='png', dmp_plot_depth_frames=80, indent=8, plotSettings=None, verbose=0):
2253  ''' Plot a single interaction sequence as a series of DMP calculations '''
2254  import pdb; pdb.set_trace()
2255  figures = []
2256  for dmp_dt_i in range(1,dmp_plot_depth_frames):
2257  # Flush figure buffer
2258  if(dmp_dt_i % 5 == 0):
2259  Save(figures, site_analysis.getFullResultsFolder(config.output_folder, customSubPath='DMP'), fig_dpi=fig_dpi, verbose=verbose)
2260  figures = []
2261  dmp_data = predictionParameters.getMatrixData(dmp_lane_i, dmp_curvy_i, dmp_speed_i, dmp_dt_i, normalise=True); dmp_sm_scale = [0,0.030]
2262  #dmp_data = predictionParameters.getPointData(dmp_lane_i, dmp_curvy_i, dmp_speed_i, dmp_dt_i, format='columns'); dmp_sm_scale = [0,50]
2263  dmp_sample_size = predictionParameters.getSampleSizeAt(dmp_lane_i, dmp_curvy_i, dmp_speed_i, dmp_dt_i)
2264  dmp_greatest_density = predictionParameters.getLargestValAt(dmp_lane_i, dmp_curvy_i, dmp_speed_i, dmp_dt_i)
2265  dmp_an_text='sample size = {0}\ngreatest density = {1}\nlane = {2}\nS = [{3:.2f},{4:.2f}[ m\nspeed = [{5:.1f},{6:.1f}[ km/h\ndeltaTime = {7} frames'.format(dmp_sample_size, dmp_greatest_density, int(predictionParameters.lane[dmp_lane_i]+1), dmp_curvy_l, dmp_curvy_h, predictionParameters.speed[dmp_speed_i], predictionParameters.speed[dmp_speed_i+1], int(predictionParameters.deltatime[dmp_dt_i]))
2266  figures.append(DrawOther.DMP(dmp_data, plotcurvy=[[dmp_curvy_x1,dmp_curvy_x2],[dmp_curvy_y1,dmp_curvy_y2]], plotcurvyall=[dmp_curvy_x_list,dmp_curvy_y_list], text=dmp_an_text, sm_scale=dmp_sm_scale, extent=predictionParameters.getSpatialBounds(), interpolation='nearest', xy_bounds=site_analysis.xy_bounds, alignments=site_analysis.site.alignments, fig_name='DMP_deltatime_'+"%02d" % (int(predictionParameters.deltatime[dmp_dt_i])), plotSettings=plotSettings))
2267  return True
2268 
2269 
2270 
2271 
def Save(figures, results_path='', fig_dpi=300, fig_format='png', fig_lan_suffix='', supressClose=False, fig_resize=None, fig_bg_colour='', verbose=0)
Definition: vis.py:77

The documentation for this class was generated from the following file:
  • C:/Home/Documents/workspace/tvaLib/lib/vis.py