title: How to aggregate edge-based simulation output to grid cells?
body: <p>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.</p>
  
  <p>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).</p>
  
  <p>this is part of the script I have written:</p>
  
  <ol>
  <li><p>extract edge-based density and speed values:</p>
  
  <pre><code> for interval in sumolib.output.parse('cairo.edgeDataOutput.xml','interval'):
       for edge in interval.edge:
           edgeDataOutput[edge.id]= (edge.density,edge.speed)
  </code></pre></li>
  <li><p>after saving density and speed into edgeDataOutput, I have to aggregate into cells and calculate avg.traffic volume in each cell:</p>
  
  <pre><code>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())))
  </code></pre></li>
  </ol>
  
  <p>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.</p>
  
  <p>density at cell(veh/Km) = sum(density at each edge inside cell)/num of edges inside cell.</p>
  
  <p>speed at cell(m/s) = sum(speed at each edge inside cell)/num of edges in cell.</p>
  
  <p>and I am using the following formula to calculate the traffic volume at each cell:</p>
  
  <p>avg.traffic volume at cell(veh/s) = sum(avg.traffic volume at each edge inside cell)/num of edges inside cell.</p>
  
  <p>avg.traffic volume at edge(veh/s) = density at edge(veh/Km) * speed at edge(m/s) / 1000.</p>
  
  <p>I just want to make sure that I am using the write formula.</p>