Configuring a Network Performance analysis

StreetLight InSight® API

To run a Network Performance analysis, you must do the following, which is different from other analysis types:

This example shows a workflow to prepare a zone set with OSM IDs and configure a Network Performance analysis.

📘

Prerequisites

You need the following to run the requests as described in this example:

  • API key
  • StreetLight InSight® login email
  • Installation of the requests Python library

You can use the example calls below as a starting point for your own calls with Python or a Jupyter notebook. Replace api_key with your own API key as a string and login_email with your StreetLight InSight® login email as a string for the calls to be successful.

1. Check available data 📆

Verify what data months are available for the All_Vehicles_AGPS travel mode. New data months are added regularly for this travel mode.

import requests

url = f"https://insight.streetlightdata.com/api/v2/date_ranges/US/All_Vehicles_AGPS?key={api_key}"

headers = {"accept": "application/json"}

response = requests.get(url, headers=headers)

print(response.text)

2. Get OSM IDs for geometry 🌐

Use the Search OSM IDs endpoint to get a list of OSM IDs to use to create a zone set that is compatible with Network Performance analyses. The request below gets all OSM IDs in the 94110 zip code.

url = f"https://insight.streetlightdata.com/api/v2/osm_ids/search?key={api_key}"

payload = { "geometry": { "zip_id": "94110" } }
headers = {
    "accept": "application/json",
    "content-type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)

data = json.loads(response.text)

# Create an array that only contains values in the "osm_id" column
# Service roads are not supported for Network Performance, filtering out rows with service road classification
osm_id_array = [row[0] for row in data["data"] if row[1] != "service"]

print(osm_id_array)

3. Create a zone set with OSM IDs 📍

Using the array of OSM IDs created in the previous step, create a zone set that is compatible with Network Performance.

📘

Zone sets used with Network Performance and Network Origin-Destination analysis types must have zones defined in the osm_ids parameter, rather than the zones parameter with GeoJSON.

url = f"https://insight.streetlightdata.com/api/v2/zone_sets?key={api_key}"

payload = {
    "insight_login_email": login_email,
    "osm_ids": osm_id_array
}
headers = {
    "accept": "application/json",
    "content-type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)
print(response.text)


# assign zone set UUID to variable
data = json.loads(response.text)
zonesUUID = data["uuid"]

4. Configure a Network Performance analysis 🚙

Note the following parameters when configuring a Network Performance analysis:

  • "travel_mode_type" must be All_Vehicles_AGPS".
  • "metric_type" must be set. "spot" metrics describe vehicles at the midpoint of a road segment (similar to a tube counter); "segment" metrics describe vehicles over the length of a road segment and allow you to get metrics such as VMT and VHD.
  • "date_ranges" must be available for "All_Vehicles_AGPS", which we checked in step 1.
url = f"https://insight.streetlightdata.com/api/v2/analyses?key={api_key}"

payload = {
    "analysis_type": "Network_Performance",
    "travel_mode_type": "All_Vehicles_AGPS",
    "output_type": "volume",
    "day_parts": "All Day|0023,Early AM|0005,Peak AM|0609,Mid-Day|1014,Peak PM|1518,Late PM|1923",
    "day_types": "Weekday|14,Weekend Day|67,All Days|17",
    "insight_login_email": login_email,
    "oz_sets": [{ "uuid": zonesUUID }],
    "metric_type": "segment",
    "date_ranges": [
      {
        "start_date": "01/01/2024",
        "end_date": "10/31/2024"
      }
    ]
    "enable_visualization": True
}
headers = {
    "accept": "application/json",
    "content-type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)

data = json.loads(response.text)
analysisUUID = data["uuid"]

5. Get metrics 📊

You can visualize metrics for the completed analysis in the StreetLight InSight® webapp, or download a CSV using the Get Metrics by UUID or Get Metrics by analysis name endpoints.

url = f"https://insight.streetlightdata.com/api/v2/analyses/download/uuid/{analysisUUID}/metric?key={api_key}"

headers = {"accept": "text/csv"}

response = requests.get(url, headers=headers)

print(response.text)