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: 48408it [00:00, 1184420.62it/s]

edge LineString geometry file: 100%|██████████| 48408/48408 [00:00<00:00, 10357078.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:
    print(result["error"])

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

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



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

Let's look at the energy consumption for the route.

energy = result["route"]["traversal_summary"]["trip_energy_electric"]
print(
    f"Ambient Temperature: {query['ambient_temperature']['value']} F, Trip Energy: {round(energy, 3)} kWh"
)
Ambient Temperature: 72 F, Trip Energy: 2.022 kWh

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:
        print(result["error"])
    else:
        energy = result["route"]["traversal_summary"]["trip_energy_electric"]
        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, 380952.38it/s]

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



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


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

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



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


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

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



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


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

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



search: 100%|██████████| 1/1 [00:00<00:00, 5.99it/s]
Ambient Temperature: 0 F, Trip Energy: 2.893 kWh
Ambient Temperature: 15 F, Trip Energy: 2.881 kWh
Ambient Temperature: 32 F, Trip Energy: 2.593 kWh
Ambient Temperature: 50 F, Trip Energy: 2.171 kWh
Ambient Temperature: 72 F, Trip Energy: 2.022 kWh

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

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



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


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

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



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


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

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



search: 100%|██████████| 1/1 [00:00<00:00, 5.98it/s]
Ambient Temperature: 90 F, Trip Energy: 2.023 kWh
Ambient Temperature: 110 F, Trip Energy: 2.064 kWh
../_images/75a84c294a25eec07e3568edea3a9388c68f4e3c4b172b4b5b7269109700e7aa.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:
            print(result["error"])
        else:
            energy = result["route"]["traversal_summary"]["trip_energy_electric"]
            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()
Model: 2022_Tesla_Model_3_RWD_Steady_Thermal, Ambient Temperature: 0 F, Trip Energy: 2.862 kWh

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

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



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


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

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



search: 100%|██████████| 1/1 [00:00<00:00, 6.02it/s]
Model: 2022_Tesla_Model_3_RWD_Steady_Thermal, Ambient Temperature: 15 F, Trip Energy: 2.538 kWh
Model: 2022_Tesla_Model_3_RWD_Steady_Thermal, Ambient Temperature: 32 F, Trip Energy: 2.085 kWh

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

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



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


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

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



search: 100%|██████████| 1/1 [00:00<00:00, 5.97it/s]
Model: 2022_Tesla_Model_3_RWD_Steady_Thermal, Ambient Temperature: 50 F, Trip Energy: 1.918 kWh
Model: 2022_Tesla_Model_3_RWD_Steady_Thermal, Ambient Temperature: 72 F, Trip Energy: 1.9 kWh
Model: 2022_Tesla_Model_3_RWD_Steady_Thermal, Ambient Temperature: 90 F, Trip Energy: 1.901 kWh
Model: 2022_Tesla_Model_3_RWD_Steady_Thermal, Ambient Temperature: 110 F, Trip Energy: 1.97 kWh

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

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



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


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

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



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


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

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



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


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

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



search: 100%|██████████| 1/1 [00:00<00:00, 6.04it/s]
Model: 2020_Chevrolet_Bolt_EV_Steady_Thermal, Ambient Temperature: 0 F, Trip Energy: 2.956 kWh
Model: 2020_Chevrolet_Bolt_EV_Steady_Thermal, Ambient Temperature: 15 F, Trip Energy: 2.93 kWh
Model: 2020_Chevrolet_Bolt_EV_Steady_Thermal, Ambient Temperature: 32 F, Trip Energy: 2.554 kWh
Model: 2020_Chevrolet_Bolt_EV_Steady_Thermal, Ambient Temperature: 50 F, Trip Energy: 2.036 kWh
Model: 2020_Chevrolet_Bolt_EV_Steady_Thermal, Ambient Temperature: 72 F, Trip Energy: 1.824 kWh

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

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



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


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

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



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


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

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



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


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

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



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


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

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



search: 100%|██████████| 1/1 [00:00<00:00, 5.59it/s]
Model: 2020_Chevrolet_Bolt_EV_Steady_Thermal, Ambient Temperature: 90 F, Trip Energy: 1.825 kWh
Model: 2020_Chevrolet_Bolt_EV_Steady_Thermal, Ambient Temperature: 110 F, Trip Energy: 1.876 kWh

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

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



search: 100%|██████████| 1/1 [00:00<00:00, 5.82it/s]
../_images/2679f7a1564c2f196d168984b92c646c9e63e9317587b9d8c6460d476bd5178e.png