Tutorial Acceleration Noise

Main Page > Tutorials > Tutorial: Performance Measures

 Acceleration Noise is the standard deviation of the acceleration of a specific link. Acceleration noise is calculated from the Time Step Data output file to match the Acceleration Noise in given in the Link Performance Measures output file. This tutorial is using R, if you are running this tutorial with R please make sure you are using RStudio 3.4 or newer. The zip file can be found here. Note: The script is coded such that as long as the output files from a SwashSim Two Lane Highway file are uploaded to the correct file path (shown below) that it should be able to be used. The script could be further adapted for use with other uninterrupted flow files with minor modifications by the user. To properly run this script the Time Step Data file and Link Results csv files will need to be taken from the location of the simulation output to ...\accelNoise_v1.x\inputs\timeStepData and ...\accelNoise_v1.x\inputs\linkResultsData, respectively. Before running this script: • Customization of link outputs: Lines 44-45 – Line 44 allows you to choose a custom list of links or use all links present. – Line 45 allows you to manually list the links that will be evaluated. • Verify warm up times and the simulation duration: Lines 48-49 – Line 48 is for the manual input of warm up time – Line 49 is for the manual input of simulation duration

Note: The R script can be run as chunks of script by placing your cursor at the end of the desired chunk and pressing "Ctrl+Alt+T" (for Windows). The R script can also be run by selecting lines and pressing run. It is recommended to run the code in the order it appears.

Running the script and method Inputs Lines 31-50 are the inputs which are used later in the script. Lines 33-37 describe where SwashSim output files should be located as described above. Lines 38-41 are the locations of the output files from this script. Lines 42-40 are described above.

Preparing the R environment Lines 51-79 prepare RStudio to run properly. Lines 51-61 will install the packages needed to run the script. Lines 61-64 call packages to be used, specifically "rstudioapi" and "collections". Please note, that the comments on lines 65-67 refer to the use of "plyr" and "readr" and are not relevant to running this script. Lines 71-79 set the working directory to the where the R script is located, allowing for flexibility in the location of the accelNoise_v1.x file.

Importing the time-step data Lines 80-99 import the time-step data. Line 82 is for user convenience and prints the start time of the operation. Lines 84-85 creates a value that stores the names of the files in the timeStepData folder. Line 92-96 creates a dataframe of all csv files in the timeStepData folder. Line 98 is for user convenience and prints the end time of the importation.

Defining the list of links to be analyzed Lines 100-126 further define the list of links to be analyzed. Line 103 identifies all links with vehicle data. Line 106 reads the link results into a dataframe from the combined csv file. Lines 109-111 removes the entry and exit links from the linkResults data frame. Lines 114-125 are for the usage of a custom link list. This will modify the linkResults dataframe to only included specified links as was specified in Lines 44-45.

Preparing the dictionaries of spreadsheets for each link Lines 127-136 sets up a data structure (dictionary) that allows for link data to be compared with warm-up data and other link data.

Building the dictionaries of time-step data per link Lines 137-172 are to "build" the dictionaries. Lines 140-161 are a for loop to filter the combined csv file. Lines 146-147 change the Link ID type to a string character, allowing for easier filtering. Lines 150-151 filter the data frame by the current link (in layman's terms, all data is separated by Link ID, making each Link ID its own "entry" with "definitions"). Lines 157-161 write each of these filtered data frames as a csv file located in ...\accelNoise_v1.x\outputs\individualLinksTimeStep. Line 165 takes these "entries" and compiles it into the previously defined dictionary. Line 168 creates a data frame that excludes all vehicles present in the warm-up time. Line 169 then takes this data frame and compiles into the other previously defined dictionary.

Initializing the output table with empty values Lines 173-183 creates the output table for both calculations of acceleration noise. For now, the rows are set to 1 and will be iterated later to avoid manual inputs.

Eliminating invalid vehicles and estimating acceleration noise Lines 184-229 prepare data structures for filtering. Line 187 starts the for loop, which filters the vehicle data one link at a time. Line 194 creates a data frame that excludes vehicle data from vehicles present in the warm up time period (e.g. the simulation time stamp is greater than the warm up time). Line 197 creates a data frame with all time step data. Line 200 creates a list of vehicles using the vehicle index to identify unique vehicles. Line 203 is prepares a blank list of correctly filtered vehicles. Line 205 is another for loop (note: this is a nested loop). Lines 209, 211, and 213 create three new data frames that include vehicle data for no warm up vehicles, vehicle data with warm up vehicles, and all vehicle data with all the links present. Lines 219 and 211 define the simulation state time (no warm up) and the real start time (with warm up), respectively. Lines 226 and 228 define the simulation end time (no warm up) and the real end time (no warm up).

Filtering: Lines 230-252 Since the vehicles that were present in the warm-up time are already filtered out, the vehicles that did not fully transverse the link now need to be filtered out. The criteria for filtering out a vehicle are as follows: – The vehicle started to traverse the link during the warm up time. – The vehicle did not enter the consecutive link before the end of the simulation time. This is performed by line 238 and then added to a list of vehicles in line 241. Line 252 simply renames the dataframe.

Calculations: Lines 257-302 Line 260 prepares an empty vector (a list but with number values) for the total time spent in motion on the link. $$T$$. A for loop is started so the following process can be repeated for each filtered vehicle. In Line 264, vehicle is then called from the dataframe from Filtering. $$dt$$ (named deltaTime in R script) is then calculated as the number of rows the exist in that vehicle's dataframe (Line 267). This is then added to a vector that will store all vehicles' time in motion (line 268). $$T$$ (total time in motion) is then calculated by summing all the values in previously mentioned vector (MotionTime in R Script, Line 273). $$[a(t)]^2$$ is then calculated as the square of the acceleration and is stored in the filtered dataframe (Line 277, 279). The acceleration noise with a mean of zero is then calculated by dividing the sum of squared accelerations by the total travel time in motion and taking the square root of this value (Line 281). The mean of accelerations (μ) is calculated using the mean function in R, this can be replicated by summing all the accelerations of all filtered vehicles on that link and dividing that by $$T$$ for that link (Line 286). The acceleration noise with a non-zero mean is then calculated by subtracting the mean from each acceleration and storing it in the dataframe (Line 288) and then summing all these together (Line 290), this sum is then divided by $$T$$ and the square root is taken (Line 292). Lines 294-300, then store these in a dataframe to later be compared to SwashSim results and exported as a csv file.

Comparing R and SwashSim results Lines 303-327 then compare the R calculated values with the SwashSim Link performance values. Lines 307-312 set up a comparison dataframe by merging the dataframe from Lines 294-300 and dataframe (named LinksOnly) defined in Lines 109-111 (which is the SwashSim output). Lines 314-316 renames the column headings. Line 317-318 subtracts the SwashSim acceleration noise values from the R calculated values and outputs this into the comparison dataframe. Line 319-320 repeats the same process except for the acceleration noise with a non-zero mean. Lines 322-325 write the comparison data frame as a csv file, which will be located in ...\accelNoise_v1.x\outputs\accelerationNoiseSheet. Line 328 is for user convenience to let you know the script is finished running.