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


building adjacencies: 100%|██████████| 48601/48601 [00:00<00:00, 4034414.50it/s]
building adjacencies: 100%|██████████| 48601/48601 [00:00<00:00, 4029046.75it/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.05 kWh

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

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



search: 100%|██████████| 1/1 [00:00<00:00, 27.94it/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, 587199.06it/s]

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



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


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

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



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


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

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



search: 100%|██████████| 1/1 [00:00<00:00, 29.50it/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, 2173913.00it/s]



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


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

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



search: 100%|██████████| 1/1 [00:00<00:00, 29.60it/s]
Ambient Temperature: 0 F, Trip Energy: 2.901 kWh
Ambient Temperature: 15 F, Trip Energy: 2.889 kWh
Ambient Temperature: 32 F, Trip Energy: 2.601 kWh
Ambient Temperature: 50 F, Trip Energy: 2.188 kWh
Ambient Temperature: 72 F, Trip Energy: 2.05 kWh
Ambient Temperature: 90 F, Trip Energy: 2.051 kWh
Ambient Temperature: 110 F, Trip Energy: 2.088 kWh

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

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



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


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

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



search: 100%|██████████| 1/1 [00:00<00:00, 29.30it/s]
../_images/ddb53e073f6cecfc93b35d828113e64f0d7d640fa11183732d6b136f9b69b79f.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()
Model: 2022_Tesla_Model_3_RWD_Steady_Thermal, Ambient Temperature: 0 F, Trip Energy: 2.873 kWh
Model: 2022_Tesla_Model_3_RWD_Steady_Thermal, Ambient Temperature: 15 F, Trip Energy: 2.547 kWh

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

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



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


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

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



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

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

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



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


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

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



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


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

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



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


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

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



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


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

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



search: 100%|██████████| 1/1 [00:00<00:00, 29.75it/s]
Model: 2022_Tesla_Model_3_RWD_Steady_Thermal, Ambient Temperature: 32 F, Trip Energy: 2.088 kWh
Model: 2022_Tesla_Model_3_RWD_Steady_Thermal, Ambient Temperature: 50 F, Trip Energy: 1.921 kWh
Model: 2022_Tesla_Model_3_RWD_Steady_Thermal, Ambient Temperature: 72 F, Trip Energy: 1.904 kWh
Model: 2022_Tesla_Model_3_RWD_Steady_Thermal, Ambient Temperature: 90 F, Trip Energy: 1.904 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, 2079002.25it/s]



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


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

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



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


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

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



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


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

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



search: 100%|██████████| 1/1 [00:00<00:00, 29.05it/s]
Model: 2022_Tesla_Model_3_RWD_Steady_Thermal, Ambient Temperature: 110 F, Trip Energy: 1.973 kWh
Model: 2020_Chevrolet_Bolt_EV_Steady_Thermal, Ambient Temperature: 0 F, Trip Energy: 2.966 kWh
Model: 2020_Chevrolet_Bolt_EV_Steady_Thermal, Ambient Temperature: 15 F, Trip Energy: 2.94 kWh
Model: 2020_Chevrolet_Bolt_EV_Steady_Thermal, Ambient Temperature: 32 F, Trip Energy: 2.562 kWh
Model: 2020_Chevrolet_Bolt_EV_Steady_Thermal, Ambient Temperature: 50 F, Trip Energy: 2.039 kWh
Model: 2020_Chevrolet_Bolt_EV_Steady_Thermal, Ambient Temperature: 72 F, Trip Energy: 1.827 kWh
Model: 2020_Chevrolet_Bolt_EV_Steady_Thermal, Ambient Temperature: 90 F, Trip Energy: 1.828 kWh
Model: 2020_Chevrolet_Bolt_EV_Steady_Thermal, Ambient Temperature: 110 F, Trip Energy: 1.879 kWh

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

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



search: 100%|██████████| 1/1 [00:00<00:00, 28.50it/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, 28.85it/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, 28.96it/s]
../_images/ddf2c20707aa10595144309a548f740a8678478d88964a4495d55240481f3d55.png