Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

ASSIGNMENT 3 CCS2-505, Fall 2019 Due: Wednesday, Dec 11th, (23:59) Please read the entire PDF before starting. You must do this assignment individually. It is very important that you follow the...

1 answer below »
ASSIGNMENT 3
CCS2-505, Fall 2019
Due: Wednesday, Dec 11th, (23:59)
Please read the entire PDF before starting. You must do this assignment individually.
It is very important that you follow the directions as closely as possible. The directions, while
perhaps tedious, are designed to make it as easy as possible for me to mark the assignments.
Up to 30% can be removed for bad indentation of your code as well as omitting comments, or poor coding
structure.
To get full marks, you must:
• Follow all directions below
– In particular, make sure that all the file names and column names are spelled exactly as de-
scribed in this document. Otherwise, you will receive a 30% penalty.
• Make sure that your code run
– Code that does not run (e.g due to a NameE
or, TypeE
or) will receive a very
lowmark.
• Write your name and student ID as a comment in all .py files you hand in
• Indent your code properly
• Name your variables appropriately
– The purpose of each variable should be obvious from the name
• Comment your work
– A comment every line is not needed, but there should be enough comments to fully understand
your program
1
Part 1
In this assignment, you will be asked to analyze vehicular mobility trace data on highway. You have been
provided with two .csv files: 01 tracks.csv and 01 tracksMeta.csv. Throughout this assignment you are
allowed to use everything we have learned in class to solve the questions. You also need to make sure to
precisely follow the instructions provided.
Question 1: Fill missing value (5 points)
The 01 tracks.csv has few missing x and y values as shown as below. Both x and y are the coordinate
value, where the x-value represents the horizontal position and the y-value represents the vertical position.
Please fill the missing value via linear interpolation and output the result.csv.
Page 2
Question 2: Vehicle direction (10 points)
Besides the x and y value, the 01 tracks.csv also contains vehicle id and time frame. Note that each
time frame is about 0.04 second. Suppose we have two lane marking: upper lane marking and lowe
lane marking. The upper lane marking has 3 values: 8.51;12.59;16.43 and the lower lane marking has 3
values: 21.00;24.96;28.80. These values are represented as the line position in terms of the y-axis from
ottom to top direction (See the figure below). Your task is to add an extra column to result.csv
called ’direction’. If a vehicle’s y value is inside the range XXXXXXXXXX, the direction is 1, and 0 if the
value is in between XXXXXXXXXXOutliers might exist, vehicles might have weird y value such as 7.3. In
such case, we label direction according to the closest lane markings. For example, 7.3 is close to 8.51, so
the direction should be 1.
Question 3: x velocity and y velocity (10 points)
In this part, you need to calculate two velocity values: x velocity and y velocity for each vehicle (Different
ID). Thus you need to store these two values under two new columns: ’x velocity’ and ’y velocity’ into
your result.csv. Since a time unit for a frame is 0.04 seconds and given two x values: XXXXXXXXXXand
363.73, the x velocity is calculated as:
x velocity = XXXXXXXXXX − 362.26)/0.04
Same trick should be applied for calculating the y velocity. Note that for the first x value, since we do
not have previous x value, the velocity should be 0. Please see below for an example output.
Page 3
Question 4: Su
ounding vehicles (10 points)
In this part, you need to calculate the number of su
ounding vehicles given a distance as the threshold.
To do this, you need to first group the data base on the time frame. For example, assume the time
frame 4 has 4 vehicles: id = [1, 3, 27, 41]. Then, we divide these vehicles into two sets according to the
vehicles’ direction. Finally, calculate the distance between each vehicles within the set. Given the x and
y value, the distance should be calculated by the following function:
distance =
√
(x2 − x1)2 + (y2 − y1)2
Thus, let 50 and 100 be the distance threshold. You should display the number of neighbor vehicles that
the distance is under or equal to the threshold by creating two columns: ’neighbor 50’ and ’neighbor 100’.
For example, given the threshold is 50, if the distance between vehicle id 3 and 27 is 20 at frame 4, then
neighbor 50 for id 3 and id 27 at frame 4 should both +1. Below shows the sample output to the
esult.csv.
Question 5: Merge data (5 points)
In this question, you are asked to merge the 01 tracksMeta.csv to result.csv according to the vehicle
id. The 01 tracksMeta.csv contains width and height of each vehicle, thus your result.csv should
also has these two columns.
Question 6: Number of lane changes (10 points)
In this question, you are asked to count number of lane changes of each vehicle using the upper lane
marking and the lower lane marking. Note that lane changes happened when the vehicle across the
middle line. Below is the sample output to the result.csv
Page 4
Part 2
In this part of your assignment, you will be asked to draw several graphs using Matplotlib. For each
question, you will be provided with a sample output. Note that these outputs are just for template use,
you are free to make them prettier.
Question 7: vehicle class distribution (5 points)
In this question, you need to draw a pie chart for vehicle class distribution. We categorize vehicles into
three classes according to vehicles’ width. For width that is less than 4.7 is a car, for width that is
etween 4.7 and 6.7 is a van and for width that is larger than 6.7 is a truck. Below is a sample graph.
Note that you should show me three vehicle classes.
Question 8: Vehicle velocity distribution (5 points)
In this question, you need to draw a plot which shows vehicle velocity distribution for both x and y.
Below is a sample plot for x velocity, you should show both x and y on the same plot.
Page 5
Question 9: Vehicle velocity by lanes (10 points)
In this question, you need to draw a plot which shows only vehicle x velocity for four different lanes.
By using the upper lane marking and the lower lane marking, we can find the four lanes. e.g. lane 0 is
etween 8.51 to 12.59, lane 1 is between 12.59 to 16.43, and so on. Outliers should not be in any of the
lanes in this case. Below is a sample plot.
Question 10: Vehicle position (10 points)
In this question you are going to draw a plot showing a vehicle’s position. Since each vehicle can switch
etween two lanes while moving, you should show the position with two different color according to the
two different lanes. Warping your code into a function called position(id). The function is taking an
ID as a parameter. Thus, if we call the position(25), we should get the following example output.
Page 6
Question 11: Vehicle position with neighbor (20 points)
In this question, you need to show not only a vehicle’s positions but also show the neighbor information.
You need to write a function called neighbors(*id) which takes multiple ID as an inputs. For all input
vehicles, they must have at least 50 overlay time frames. You should depict each vehicle with different
color. However, if the vehicle is close to the other vehicle within 50 meters as the threshold (hint: the
neighbor 50 column), you should change the mark color to red. Please see the following example for two
vehicles.
What To Submit
Please put all your files in a folder called Assignment3. Zip the folder (DO NOT RAR it or use othe
compression extension like .7z) and submit it on MyCourses. If you use other compression extension like
.rar, .7z etc, you will lose marks. Use only .zip.
Inside your zipped folder, there must be the following files. Do not submit any other files Any
deviation from these requirements may lead to lost marks.
a3 part1.py
a3 part2.py
01 tracks.csv
01 tracksMeta.csv
esult.csv
All plots .png
In your result.csv, plase make sure you have the following headers: id, x, y, frame, direction,
x velocity, y velocity, neighbor 50, neighbor 100, width, height, and lane changes
Page 7
Answered Same Day Dec 10, 2021 CCS2

Solution

Kshitij answered on Dec 12 2021
133 Votes
assignment.ra
Untitled69.ipyn
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"