Trajectories Processing and Visualization

Estimate Arterial

mtldp.mtltrajs.estimate_arterial.get_estimated_traverse_time(time, distance, distance_interval, min_speed=2, free_flow_speed=15)

Calculate estimated average traverse time of each column based on the input matrices

T(t) = sum_i s / v_i(t) T(t): traverse time at time t i: entry index s: entry length v_i: velocity at entry i

Parameters
  • time – numpy.array of time matrix

  • distance – numpy.array of distance matrix

  • distance_interval – int, distance of each grid of distance array

  • min_speed – any speed lower than min_speed will be considered as 0, default 2 (m/s)

  • free_flow_speed – speed to fill in the entry of speed array when there is no measured data, default 15 (m/s)

Returns

numpy.array

mtldp.mtltrajs.estimate_arterial.get_estimated_average_speed(time, distance, min_speed=2, free_flow_speed=15)

Calculate estimated average speed of each column of speed matrix calculated by time and distance matrices V(t) = n / (sum_i 1 / v_i(t)) V(t): speed at time t is given by the harmonic mean of each column of the speed matrix

Parameters
  • time – numpy.array of time matrix

  • distance – numpy.array of distance matrix

  • min_speed – any speed lower than min_speed will be considered as 0, default 02 (m/s)

  • free_flow_speed – speed to fill in the entry of speed array when there is no measured data, default 15 (m/s)

Returns

numpy.array

mtldp.mtltrajs.estimate_arterial.plot_line_chart(data, start_time, end_time, timezone=None, input_local_seconds=False, ax=None, fig=None, x_partition=0, y_partition=5, xlabel='Date time', ylabel=None, y_texts_conversion=1, label=None, line='.-', color='k', alpha=1.0, figsize=(10, 4), add_axis=False)

Plot a line chart based on given data

Parameters
  • data – numpy.array

  • start_time – timestamp

  • end_time – timestamp

  • timezonemtldp.utils.Timezone, default None

  • input_local_seconds – bool, if False, tod will be calculated by UTC timezone, default False

  • axmatplotlib.axes.Axes: if None, a new ax will be created, default None

  • figmatplotlib.pyplot.figure, default None

  • x_partition – the number of partitions on x_axis, default len(data)

  • y_partition – the number of partitions on y_axis, default 5

  • xlabel – label of x axis, default “Date time”

  • ylabel – label of y axis, default None

  • y_texts_conversion – the ratio of converting original y axis data to texts on y axis (ie. y_texts_conversion=60 if y axis data is timestamp and the user wants y axis to be minute), default 1

  • label – label of line, default None

  • line – style of the line, default “.-“

  • color – color of the line, default “k”

  • alpha – alpha of the line, default 1.0

  • figsize – tuple of size of graph, default (10, 10)

  • add_axis – True if the user wants to plot axis label and grid line will be plotted, default False

Returns

(matplotlib.pyplot.figure and matplotlib.axes.Axes) or (matplotlib.axes.Axes if fig is not None)

Grid Trajectories

mtldp.mtltrajs.grid_plotter.grid_arterial(arterial, movement_trajectory, start_time, end_time, time_interval=10, distance_interval=10, time_attr='timestamp', distance_attr='distance', direction_stream='former')

Grid and plot the trajectories in the given Arterial User can choose to plot the trajectories in former or latter directions by setting direction_stream

Parameters
  • arterialmtldp.mtlmap.Arterial

  • movement_trajectory – dict, key: movement_id, value: mtldp.mtltrajs.TrajectoryDict

  • start_time – timestamp

  • end_time – timestamp

  • time_interval – default 10 sec

  • distance_interval – default 10 meters

  • time_attr – the attribute to be plotted on x axis , default: “timestamp”

  • distance_attr – the attribute to be plotted on y axis, default: “distance”

  • direction_stream – up or down stream to be plotted, default “former”

Returns

numpy.array of number, time, and distance and a tuple of (start_distance, end_distance)

mtldp.mtltrajs.grid_plotter.grid_movement(movement, trajectory_dict, start_time, end_time, time_interval=10, distance_interval=10, time_attr='timestamp', distance_attr='distance')

Grid one movement

Parameters
  • movementmtldp.mtlmap.Movement

  • trajectory_dictmtldp.mtltrajs.TrajectoryDict

  • start_time – timestamp

  • end_time – timestamp

  • time_interval – default 10 sec

  • distance_interval – default 10 meters

  • time_attr – the attribute to be plotted on x axis , default: “timestamp”

  • distance_attr – the attribute to be plotted on y axis, default: “distance”

Returns

numpy.array of number, time, and distance, and a tuple of (start_distance, end_distance)

mtldp.mtltrajs.grid_plotter.plot_speed(grid_time, grid_distance, movement_list, start_time, end_time, time_interval, start_dis, end_dis, distance_interval, max_speed=15, timezone=None, input_local_seconds=False, x_partition=5, ax=None, fig=None, xlabel='Date time', ylabel=None, colorbar_title='Speed (m/s)', figsize=(10, 10))

Plot the speed heatmap

Parameters
  • grid_time – grid of time

  • grid_distance – grid of time

  • movement_list – grid of time

  • start_time – timestamp

  • end_time – timestamp

  • time_interval – time in each grid

  • start_dis – unit: meter

  • end_dis – unit: meter

  • distance_interval – distance in each grid

  • max_speed – any speed above max_speed will be plotted maximum green, default 15 (m/sec)

  • timezonemtldp.utils.Timezone, default None

  • input_local_seconds – bool, True if timestamps in trajectories are already shifted to local time, default False

  • x_partition – the number of partitions on x_axis, default 5

  • axmatplotlib.axes.Axes: if None, a new ax will be created, default None

  • figmatplotlib.pyplot.figure, default None

  • xlabel – label of x axis, default “date time”

  • ylabel – label of y axis, default None

  • colorbar_title – title of the color bar, default “speed (m/sec)”

  • figsize – tuple of size of graph, default (10, 10)

Returns

(matplotlib.pyplot.figure and matplotlib.axes.Axes) or (matplotlib.axes.Axes if fig is not None)

Time-Space Diagram

mtldp.mtltrajs.ts_plotter.truncate_trajectory(arterial, movement_trajectory_dict, direction_stream, truncate_length=20, time_attr='timestamp', distance_attr='distance')

Truncate the trajectory to prevent over-counting at the intersection of two movements

Parameters
  • arterialmtldp.mtlmap.Arterial

  • movement_trajectory_dict – dict, key: movement_id, value: mtldp.mtltrajs.TrajectoryDict

  • direction_stream – “both”/”former”/”latter”

  • truncate_length – float length to truncate at an intersection, default 20m

  • time_attr – the attribute to be plotted on x axis, default: “timestamp”

  • distance_attr – the attribute to be plotted on y axis, default: “distance”

Returns

dict, key: movement_id, value: mtldp.mtltrajs.TrajectoryDict

mtldp.mtltrajs.ts_plotter.plot_arterial_ts(arterial, mid_trajectory, spat_collection, start_time, end_time, direction='both', down_green_band=True, up_green_band=True, time_attr='timestamp', distance_attr='distance', truncate_length=20, timezone=None, input_local_seconds=False, x_partition=5, ax=None, fig=None, xlabel='Date time', ylabel=None, traj_line='k.-', figsize=(10, 10))

Plot the time-space diagram along an arterial

Parameters
  • arterialmtldp.mtlmap.Arterial

  • mid_trajectory – key: movement_id, value: mtldp.mtltrajs.TrajectoryDict

  • spat_collectionmtldp.mtlmap.SPaTCollection

  • start_time – timestamp

  • end_time – timestamp

  • direction – “former”/”latter”/”both”, trajectories on the direction of movements to be plotted, default “both”

  • down_green_band – True if the user want to plot the green bands in latter direction, default True

  • up_green_band – True if the user want to plot the green bands in former direction, default True

  • time_attr – the attribute to be plotted on x axis , default: “timestamp”

  • distance_attr – the attribute to be plotted on y axis, default: “distance”

  • truncate_length – float length to truncate at an intersection, default 20m

  • input_local_seconds – bool, True if timestamps in trajectories are already shifted to local time, default False

  • timezonemtldp.utils.Timezone, if None, a timezone will be automatically created, default None.

  • x_partition – the number of partitions on x_axis, default 5

  • axmatplotlib.axes.Axes: if None, a new ax will be created, default None

  • figmatplotlib.pyplot.figure, default None

  • xlabel – label of x axis, default “date time”

  • ylabel – label of y axis, default None

  • traj_line – the line style of trajectories, default “k.-“

  • figsize – tuple of size of graph, default (10, 10)

Returns

(matplotlib.pyplot.figure and matplotlib.axes.Axes) or (matplotlib.axes.Axes if fig is not None)

mtldp.mtltrajs.ts_plotter.plot_movement_ts(movement, trajectory_dict, spat_collection, start_time, end_time, time_attr='timestamp', distance_attr='distance', timezone=None, input_local_seconds=False, x_partition=5, ax=None, fig=None, xlabel='date time', ylabel=None, traj_line='k.-', figsize=(10, 10))

Plot the time-space diagram of a given movement

Parameters
  • movementmtldp.mtlmap.Movement

  • trajectory_dictmtldp.mtltrajs.TrajectoryDict

  • spat_collectionmtldp.mtlmap.SPaTCollection

  • start_time – timestamp

  • end_time – timestamp

  • time_attr – the attribute to be plotted on x axis , default: “timestamp”

  • distance_attr – the attribute to be plotted on y axis, default: “distance”

  • timezonemtldp.utils.Timezone

  • input_local_seconds – bool, True if timestamps in trajectories are already shifted to local time, default False

  • x_partition – the number of partitions on x_axis, default 5

  • axmatplotlib.axes.Axes: if None, a new ax will be created, default None

  • figmatplotlib.pyplot.figure, default None

  • xlabel – label of x axis, default “date time”

  • ylabel – label of y axis, default None

  • traj_line – the line style of trajectories, default “k.-“

  • figsize – tuple of size of graph, default (10, 10)

Returns

(matplotlib.pyplot.figure and matplotlib.axes.Axes) or (matplotlib.axes.Axes if fig is not None)