DOI: 10.25338/b8tp5q
title: NCST Caltrans project on sensor data error estimation

description: The aim of this script is to automate the process of directed network
 graph formation, i.e., creation of incidence matrix, node adjacency
 matrix, and map the sensors to appropriate links. The data used for
 creating the freeway network is obtained from open street maps, whereas,
 the data for sensors is obtained from PeMS. The results of the algorithm
 will later be fed to the network sensor error estimation algorithm, that
 quantifies the erroneous sensors using network statistics.
description: Major libraries used:
 <strong>Osmar</strong> - To import data from open
 street
 maps <strong>Leaflet</strong>, <strong>mapview</strong>, <strong>sp</strong> - Mapping the network <strong>dplyr</strong>, <strong>plyr</strong> - To manipulate data frames Data used: The data used for creating the freeway network is obtained from <strong>open street maps</strong>, whereas, the data for sensors is obtained from <strong>PeMS</strong>. Methodology <strong>Creating the map required</strong> We start by downloading the bulk osm data for California (approx. 18GB). Next, using osmar library, we extract the required data using a bounding box, demarcating the latitude and longitude boundaries. <em>bbox = corner_bbox(-118.0042, 33.6363, -117.7226, 33.9194)</em> Then extracting only the freeway information (links and nodes) from the resulting data.  The problem here is that most of the links contain more than two nodes, which would make the incidence matrix unnecessarily large. Thus, we extract the nodes that connect two links, and map them over the links. <strong>Creating the incidence matrix</strong> To create the incidence matrix, each link was looked up for the first and last node incident on it, keeping in mind the direction. The rows represent nodes, whereas the columns represent links. +1 was assigned at the head and -1 to the tail of the link, all other entries to 0. The incidence matrix has a dimension of 2973 by 2640. <strong>Assigning links to appropriate freeways</strong> The osm data does not explicitly mention about which freeway is a particular link part of.  Thus, for the freeway links a combination of "name" and "ref" tag was used to obtain the information about the freeway. <strong>Adding ramps to the Fwy data frame</strong> So far, we only have freeway links assigned to the appropriate freeways. Now, we would like to add the immediate links that go off or on the freeway, aka ramps, to the data frame Fwy. This is done by checking for each node on the freeway segment, out of the links it is incident upon, which one is tagged as "motorway-link" in the osm data. If there is such a link, it was added to the Fwy data set with appropriate freeway values.  <strong>Overlapping sensors over the network</strong> The sensor data is now used to add a layer over the existing graph to help visualize the complete network. Different types of sensors are grouped separately and can be viewed as per user's choice by clicking the check boxes. The legend shows the color used for each sensor type. Hovering upon the sensor, link or node highlights their IDs. By default, main line (ML) sensors are checked. <strong>Mapping sensors to the appropriate links</strong> Currently, by visualization we can figure out the link that contains a particular sensor. As PeMS sensor metadata does not interact with the osm data, the link-sensor relation is unknown. We need to create an algorithm such that each sensor automatically gets mapped to the link using the geographical properties. The algorithm for mapping sensors to the links is as follows: For each sensor location, extract all the links on the freeway segment in the direction sensor is installed For the nodes on each link, calculate 3 distances Distance between the nodes (d1) Distance between first node and sensor (d2) Distance between last node and sensor Calculate d1 - (d2+d3), call it d4 Calculate d4 for each link, and arrange d4 in ascending order The link for which d4 is smallest and lesser than a threshold (1e-4 in this case), assign it the sensor Repeat the above steps for each sensor location Finally, the results are stored as a form of a list (linkId). For illustration purpose, 5 ML sensors on I-5, highlighted on the map, are shown below with the appropriate link chosen by the algorithm. One can verify the IDs by hovering above the links in the map and cross checking with the table that appears below. <strong>Re-mapping ramp and freeway-freeway sensors</strong> Looking closely, one would figure out that the ramp sensors (OR/FR) are located on the freeways rather than ramps. Same for freeway-Freeway (FF) sensors. This was one of the tedious challenges I encountered in this project. But with a combination of a simple algorithm and manual work, the sensors were remapped. The details are omitted in this document. In the map below, all the remapped sensors are shown on their appropriate new links. <strong>Creating the adjacency matrix</strong> To create adjacency matrix, for each link, nodes having 1 or -1 were searched in the incidence matrix. The cell corresponding to these nodes in the adjacency matrix was assigned 1, else 0.  Conclusion The results of this project, namely, incidence matrix, adjacency matrix and link-sensor relation data frame were used for the network sensor error estimation algorithm. This project led to the application of the error estimation algorithm on large networks, which is expected to result in an important contribution to the field of sensor bias estimation.
description: For more details and some illustrations to facilitate a better
 understanding of the data and script, please refer to the following github
 link: https://github.com/sbhmaheshwari/Projects/blob/master/Network%20graph%20automation/Graph_Contraction.md