Python API Docs#

nrel.routee.powertrain.io.load.list_available_models(local: bool = True, external: bool = True) List[str][source]#

returns a list of all the available pretrained models

Parameters:
  • local -- include local models?

  • external -- include external models?

Returns: a list of model keys

nrel.routee.powertrain.io.load.load_model(name: str | Path) Model[source]#

A helper function to load a pretrained model. If the model is a file, it will be loaded from disk. If the model is a name, it will be loaded from the default model catalog (local or external).

Parameters:

name -- the name of the file or default model to load

Returns: a routee-powertrain model

Examples:

>>> import nrel.routee.powertrain as pt
>>>
>>> # load a default model
>>> model = pt.load_model("2016_HYUNDAI_Elantra_4cyl_2WD")
>>>
>>> # load a model from file
>>> model = pt.load_model("MyModel.json")
nrel.routee.powertrain.io.load.load_sample_route(name: str | None = None) DataFrame[source]#

A helper function to load sample routes

Parameters:

name -- The name of the route. Defaults to "sample_route".

Returns: a pandas DataFrame representing the route

class nrel.routee.powertrain.core.model.Model(estimators: Dict[str, Estimator], metadata: Metadata, errors: ModelErrors)[source]#

A RouteE-Powertrain vehicle model represents a single vehicle (i.e. a 2016 Toyota Camry with a 1.5 L gasoline engine).

contour(estimator_id: str, x_feature: str, y_feature: str, n_samples: int | None = 100, output_path: str | None = None)[source]#

generates a contour plot of the two test features: x_feature and y_feature. for the given estimator id

Parameters:
  • estimator_id -- the estimator id for generating the plots

  • x_feature -- one of the features used to generate the energy matrix and will be the x-axis feature

  • y_feature -- one of the features used to generate the energy matrix and will be the y-axis feature

  • n_samples -- the number of samples used to generate the plots

  • output_path -- an optional path to save the plots as png files.

classmethod from_dict(input_dict: dict) Model[source]#

Load a vehicle model from a python dictionary

classmethod from_file(file: str | Path)[source]#

Load a vehicle model from a file.

Parameters:

file -- the path to the file to load

Returns: a powertrain vehicle

classmethod from_url(url: str) Model[source]#

Attempts to read a file from a url.

Parameters:

url -- the url to download the file from

Returns: a powertrain vehicle

predict(links_df: DataFrame, feature_columns: List[str] | None = None, distance_column: str | None = None, apply_real_world_adjustment: bool = True) DataFrame[source]#

Predict absolute energy consumption for each link

Parameters:
  • links_df -- a dataframe containing the links to predict on

  • feature_columns -- the features to use for prediction

  • distance_column -- the column to use for distance

  • apply_real_world_adjustment -- whether to apply a real world adjustment to the predicted energy consumption

Returns: a dataframe containing the predicted energy consumption for each link

to_dict() dict[source]#

Convert model to a dictionary

to_file(file: str | Path)[source]#

Save a vehicle model to a file.

Parameters:

file -- the path to the file to save to

visualize_features(estimator_id: FeatureSetId, n_samples: int | None = 100, output_path: str | None = None, return_predictions: bool | None = False) Dict[str, 'Series'] | None[source]#

generates test links to independently test the model's features and creates plots of those predictions for the given estimator id

Parameters:
  • estimator_id -- the estimator id for generating the plots

  • n_samples -- the number of samples used to generate the plots

  • output_path -- an optional path to save the plots as png files.

  • return_predictions -- if true, returns the dictionary containing the prediction values

Returns: optionally returns a dictionary containing the predictions where the key is the feature tested