Ambient Temperature Example

Ambient Temperature Example#

In this example, we'll demonstrate how to use RouteE Compass to plan routes that incorporate ambient temperature data for electric vehicles.

This builds off the Open Street Maps Example and assumes that we've already downloaded a road network, so be sure to check that one out first.

from nrel.routee.compass import CompassApp

import pandas as pd
import matplotlib.pyplot as plt
INFO:numexpr.utils:NumExpr defaulting to 4 threads.

First, we'll load the application from the pre-built configuration file that includes a traversal model that injects ambient temperature.

app = CompassApp.from_config_file("./denver_co/osm_default_temperature.toml")
graph edge list 0: /home/runner/work/routee-compass/routee-compass/docs/examples/denver_co/edges-compass.csv.gz: 48526it [00:00, 1692576.75it/s]


building adjacencies: 100%|██████████| 48526/48526 [00:00<00:00, 3715495.25it/s]
building adjacencies: 100%|██████████| 48526/48526 [00:00<00:00, 3708977.00it/s]

Basic Route With Mild Ambient Temperature#

Let's start with a basic route query for a 2016 Nissan Leaf 30 kWh with mild ambient temperature considerations and search for the shortest time route.

query = {
    "origin_x": -104.969307,
    "origin_y": 39.779021,
    "destination_x": -104.975360,
    "destination_y": 39.693005,
    "model_name": "2016_Nissan_Leaf_30_kWh_Steady_Thermal",
    "weights": {"trip_distance": 0, "trip_time": 1, "trip_energy_electric": 0},
    "ambient_temperature": {"value": 72, "unit": "fahrenheit"},
}

result = app.run(query)

if "error" in result:
    raise ValueError(f"Error: {result['error']}")
elif "route" not in result or result["route"] is None:
    raise ValueError("No route found.")
else:
    energy = result["route"]["traversal_summary"]["trip_energy_electric"]["value"]
    print(
        f"Ambient Temperature: {query['ambient_temperature']['value']} F, Trip Energy: {round(energy, 3)} kWh"
    )
Ambient Temperature: 72 F, Trip Energy: 2.028 kWh

applying input plugin 1: 100%|██████████| 1/1 [00:00<00:00, 2816.48it/s]

applying input plugin 2: 100%|██████████| 1/1 [00:00<00:00, 1074113.88it/s]



search: 100%|██████████| 1/1 [00:00<00:00, 27.18it/s]

Next, let's look at how the ambient temperature affects the energy consumption by running the same route query with different temperature settings.

temp_results = []
for temp in [0, 15, 32, 50, 72, 90, 110]:
    query["ambient_temperature"] = {"value": temp, "unit": "fahrenheit"}
    result = app.run(query)
    if "error" in result:
        raise ValueError(f"Error for temperature {temp} F: {result['error']}")
    elif "route" not in result or result["route"] is None:
        raise ValueError(f"No route found for temperature {temp} F.")
    else:
        energy = result["route"]["traversal_summary"]["trip_energy_electric"][
            "value"
        ]
        temp_results.append(
            {
                "ambient_temperature_f": temp,
                "trip_energy_electric": energy,
                "vehicle_model": query["model_name"],
            }
        )
        print(f"Ambient Temperature: {temp} F, Trip Energy: {round(energy, 3)} kWh")

plot_df = pd.DataFrame(temp_results)

plt.figure(figsize=(10, 6))
plt.plot(
    plot_df["ambient_temperature_f"], plot_df["trip_energy_electric"], marker="o"
)
plt.title("Effect of Ambient Temperature on Trip Energy Consumption")
plt.xlabel("Ambient Temperature (F)")
plt.ylabel("Trip Energy (kWh)")
plt.grid(True)
plt.show()

applying input plugin 1: 100%|██████████| 1/1 [00:00<00:00, 302480.34it/s]

applying input plugin 2: 100%|██████████| 1/1 [00:00<00:00, 1366120.25it/s]



search: 100%|██████████| 1/1 [00:00<00:00, 27.05it/s]


applying input plugin 1: 100%|██████████| 1/1 [00:00<00:00, 360360.38it/s]

applying input plugin 2: 100%|██████████| 1/1 [00:00<00:00, 2169197.25it/s]



search: 100%|██████████| 1/1 [00:00<00:00, 27.72it/s]


applying input plugin 1: 100%|██████████| 1/1 [00:00<00:00, 372439.47it/s]

applying input plugin 2: 100%|██████████| 1/1 [00:00<00:00, 1536098.38it/s]



search: 100%|██████████| 1/1 [00:00<00:00, 27.63it/s]
Ambient Temperature: 0 F, Trip Energy: 2.902 kWh
Ambient Temperature: 15 F, Trip Energy: 2.89 kWh
Ambient Temperature: 32 F, Trip Energy: 2.601 kWh
Ambient Temperature: 50 F, Trip Energy: 2.178 kWh
Ambient Temperature: 72 F, Trip Energy: 2.028 kWh

applying input plugin 1: 100%|██████████| 1/1 [00:00<00:00, 349040.16it/s]

applying input plugin 2: 100%|██████████| 1/1 [00:00<00:00, 1751313.50it/s]



search: 100%|██████████| 1/1 [00:00<00:00, 27.60it/s]


applying input plugin 1: 100%|██████████| 1/1 [00:00<00:00, 366972.47it/s]

applying input plugin 2: 100%|██████████| 1/1 [00:00<00:00, 2169197.25it/s]



search: 100%|██████████| 1/1 [00:00<00:00, 27.42it/s]

applying input plugin 1: 100%|██████████| 1/1 [00:00<00:00, 316856.78it/s]

applying input plugin 2: 100%|██████████| 1/1 [00:00<00:00, 2079002.25it/s]



search: 100%|██████████| 1/1 [00:00<00:00, 28.04it/s]


applying input plugin 1: 100%|██████████| 1/1 [00:00<00:00, 303490.16it/s]

applying input plugin 2: 100%|██████████| 1/1 [00:00<00:00, 2127659.50it/s]



search: 100%|██████████| 1/1 [00:00<00:00, 27.58it/s]
Ambient Temperature: 90 F, Trip Energy: 2.03 kWh
Ambient Temperature: 110 F, Trip Energy: 2.07 kWh
../_images/6f5b48e3760d09e829a2a6cff6a486dacc410a010b440296168f4ed0ca170cae.png

Next, let's take a look at the 2022 Tesla Model 3 and the 2020 Chevy Bolt and compare their energy consumption across the same range of ambient temperatures.

for model in [
    "2022_Tesla_Model_3_RWD_Steady_Thermal",
    "2020_Chevrolet_Bolt_EV_Steady_Thermal",
]:
    for temp in [0, 15, 32, 50, 72, 90, 110]:
        query["model_name"] = model
        query["ambient_temperature"] = {"value": temp, "unit": "fahrenheit"}
        result = app.run(query)
        if "error" in result:
            raise ValueError(f"Error for temperature {temp} F: {result['error']}")
        else:
            energy = result["route"]["traversal_summary"]["trip_energy_electric"][
                "value"
            ]
            temp_results.append(
                {
                    "ambient_temperature_f": temp,
                    "trip_energy_electric": energy,
                    "vehicle_model": model,
                }
            )
            print(
                f"Model: {model}, Ambient Temperature: {temp} F, Trip Energy: {round(energy, 3)} kWh"
            )

plot_df = pd.DataFrame(temp_results)

plt.figure(figsize=(10, 6))
for model in plot_df["vehicle_model"].unique():
    model_data = plot_df[plot_df["vehicle_model"] == model]
    plt.plot(
        model_data["ambient_temperature_f"],
        model_data["trip_energy_electric"],
        marker="o",
        label=model,
    )
plt.title(
    "Effect of Ambient Temperature on Trip Energy Consumption by Vehicle Model"
)
plt.xlabel("Ambient Temperature (F)")
plt.ylabel("Trip Energy (kWh)")
plt.grid(True)
plt.legend()
plt.show()

applying input plugin 1: 100%|██████████| 1/1 [00:00<00:00, 198019.81it/s]

applying input plugin 2: 100%|██████████| 1/1 [00:00<00:00, 1751313.50it/s]



search: 100%|██████████| 1/1 [00:00<00:00, 26.80it/s]


applying input plugin 1: 100%|██████████| 1/1 [00:00<00:00, 332778.69it/s]

applying input plugin 2: 100%|██████████| 1/1 [00:00<00:00, 2079002.25it/s]



search: 100%|██████████| 1/1 [00:00<00:00, 27.35it/s]


applying input plugin 1: 100%|██████████| 1/1 [00:00<00:00, 297973.78it/s]

applying input plugin 2: 100%|██████████| 1/1 [00:00<00:00, 1109877.88it/s]



search: 100%|██████████| 1/1 [00:00<00:00, 27.72it/s]


applying input plugin 1: 100%|██████████| 1/1 [00:00<00:00, 340599.44it/s]

applying input plugin 2: 100%|██████████| 1/1 [00:00<00:00, 1956947.12it/s]



search: 100%|██████████| 1/1 [00:00<00:00, 27.64it/s]
Model: 2022_Tesla_Model_3_RWD_Steady_Thermal, Ambient Temperature: 0 F, Trip Energy: 2.871 kWh
Model: 2022_Tesla_Model_3_RWD_Steady_Thermal, Ambient Temperature: 15 F, Trip Energy: 2.547 kWh
Model: 2022_Tesla_Model_3_RWD_Steady_Thermal, Ambient Temperature: 32 F, Trip Energy: 2.091 kWh
Model: 2022_Tesla_Model_3_RWD_Steady_Thermal, Ambient Temperature: 50 F, Trip Energy: 1.924 kWh
Model: 2022_Tesla_Model_3_RWD_Steady_Thermal, Ambient Temperature: 72 F, Trip Energy: 1.906 kWh
Model: 2022_Tesla_Model_3_RWD_Steady_Thermal, Ambient Temperature: 90 F, Trip Energy: 1.907 kWh

applying input plugin 1: 100%|██████████| 1/1 [00:00<00:00, 407331.97it/s]

applying input plugin 2: 100%|██████████| 1/1 [00:00<00:00, 1218026.75it/s]



search: 100%|██████████| 1/1 [00:00<00:00, 27.98it/s]


applying input plugin 1: 100%|██████████| 1/1 [00:00<00:00, 330578.50it/s]

applying input plugin 2: 100%|██████████| 1/1 [00:00<00:00, 2169197.25it/s]



search: 100%|██████████| 1/1 [00:00<00:00, 27.62it/s]


applying input plugin 1: 100%|██████████| 1/1 [00:00<00:00, 309981.41it/s]

applying input plugin 2: 100%|██████████| 1/1 [00:00<00:00, 2169197.25it/s]



search: 100%|██████████| 1/1 [00:00<00:00, 28.15it/s]


applying input plugin 1: 100%|██████████| 1/1 [00:00<00:00, 383877.16it/s]

applying input plugin 2: 100%|██████████| 1/1 [00:00<00:00, 2320185.75it/s]



search: 100%|█████��████| 1/1 [00:00<00:00, 27.68it/s]


applying input plugin 1: 100%|██████████| 1/1 [00:00<00:00, 345303.84it/s]

applying input plugin 2: 100%|██████████| 1/1 [00:00<00:00, 1814882.00it/s]



search: 100%|██████████| 1/1 [00:00<00:00, 27.42it/s]


applying input plugin 1: 100%|██████████| 1/1 [00:00<00:00, 321957.50it/s]
Model: 2022_Tesla_Model_3_RWD_Steady_Thermal, Ambient Temperature: 110 F, Trip Energy: 1.976 kWh
Model: 2020_Chevrolet_Bolt_EV_Steady_Thermal, Ambient Temperature: 0 F, Trip Energy: 2.965 kWh
Model: 2020_Chevrolet_Bolt_EV_Steady_Thermal, Ambient Temperature: 15 F, Trip Energy: 2.939 kWh
Model: 2020_Chevrolet_Bolt_EV_Steady_Thermal, Ambient Temperature: 32 F, Trip Energy: 2.562 kWh

applying input plugin 2: 100%|██████████| 1/1 [00:00<00:00, 1468428.75it/s]



search: 100%|██████████| 1/1 [00:00<00:00, 27.03it/s]


applying input plugin 1: 100%|██████████| 1/1 [00:00<00:00, 297000.28it/s]

applying input plugin 2: 100%|██████████| 1/1 [00:00<00:00, 1996008.00it/s]



search: 100%|██████████| 1/1 [00:00<00:00, 27.37it/s]


applying input plugin 1: 100%|██████████| 1/1 [00:00<00:00, 273522.97it/s]

applying input plugin 2: 100%|██████████| 1/1 [00:00<00:00, 2123142.25it/s]



search: 100%|██████████| 1/1 [00:00<00:00, 27.66it/s]


applying input plugin 1: 100%|██████████| 1/1 [00:00<00:00, 360360.38it/s]

applying input plugin 2: 100%|██████████| 1/1 [00:00<00:00, 2036660.00it/s]



search: 100%|██████████| 1/1 [00:00<00:00, 27.81it/s]


applying input plugin 1: 100%|██████████| 1/1 [00:00<00:00, 294464.06it/s]

applying input plugin 2: 100%|██████████| 1/1 [00:00<00:00, 1996008.00it/s]



search: 100%|██████████| 1/1 [00:00<00:00, 27.79it/s]
Model: 2020_Chevrolet_Bolt_EV_Steady_Thermal, Ambient Temperature: 50 F, Trip Energy: 2.043 kWh
Model: 2020_Chevrolet_Bolt_EV_Steady_Thermal, Ambient Temperature: 72 F, Trip Energy: 1.83 kWh
Model: 2020_Chevrolet_Bolt_EV_Steady_Thermal, Ambient Temperature: 90 F, Trip Energy: 1.831 kWh
Model: 2020_Chevrolet_Bolt_EV_Steady_Thermal, Ambient Temperature: 110 F, Trip Energy: 1.882 kWh
../_images/51894dd959d4a380950aaa49bcd0ff0d1b5ca7a81b027706d5397770738caf91.png