I have a network that has to be divided into a grid of square cells (200 X 200 m). each cell includes sub-segments of the edges.
I have generated the simulation data output and used sumolib to extract edge-based output. I have to calculate the average traffic volume in each cell (not edge) measured in (vehicles/second).
this is part of the script I have written:
extract edge-based density and speed values:
for interval in sumolib.output.parse('cairo.edgeDataOutput.xml','interval'): for edge in interval.edge: edgeDataOutput[edge.id]= (edge.density,edge.speed)
after saving density and speed into edgeDataOutput, I have to aggregate into cells and calculate avg.traffic volume in each cell:
for cellID in ids: density=0 speed=0 n=0 #avg.traffic vol for edgeID in cell_edgeMap[cellID].keys(): if edgeID in edgeDataOutput.keys(): density+= float(edgeDataOutput[edgeID][1]) speed+= float(edgeDataOutput[edgeID][2]) n += (float(edgeDataOutput[edgeID][1])/1000) * float(edgeDataOutput[edgeID][2]) #traffic vol = (density/1000)*speed densities.append(int((density / len(cell_edgeMap[cellID].keys()))+0.5)) speeds.append(int((speed / len(cell_edgeMap[cellID].keys()))+0.5)) numOfVehicles.append(int(n/len(cell_edgeMap[cellID].keys())))
as you can see from the code, I sum up the density, speed values of each edge that is in the cell then divide by the number of edges inside the cell to get the mean value.
density at cell(veh/Km) = sum(density at each edge inside cell)/num of edges inside cell.
speed at cell(m/s) = sum(speed at each edge inside cell)/num of edges in cell.
and I am using the following formula to calculate the traffic volume at each cell:
avg.traffic volume at cell(veh/s) = sum(avg.traffic volume at each edge inside cell)/num of edges inside cell.
avg.traffic volume at edge(veh/s) = density at edge(veh/Km) * speed at edge(m/s) / 1000.
I just want to make sure that I am using the write formula.