Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To Disk Output Plugin #22

Merged
merged 13 commits into from
Nov 9, 2023
49 changes: 29 additions & 20 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ parallelism = 2
# the parameters for the underlying road network graph
[graph]
# a file containing all the graph edges and their adjacencies
edge_list_file = "edges-compass.csv.gz"
edge_list_input_file = "edges-compass.csv.gz"
# a file containing all the graph verticies
vertex_list_file = "vertices-compass.csv.gz"
vertex_list_input_file = "vertices-compass.csv.gz"
# if verbose is true, you'll see more information when loading the graph
verbose = true

Expand All @@ -24,11 +24,11 @@ verbose = true
# the speed_grade_energy_model can compute routes using time or energy as costs
type = "speed_grade_energy_model"
# speeds for each edge in the graph
speed_table_file = "edges-posted-speed-enumerated.txt.gz"
speed_table_input_file = "edges-posted-speed-enumerated.txt.gz"
# the units of the above speed table
speed_table_speed_unit = "kilometers_per_hour"
# grades for each edge in the graph
grade_table_file = "edges-grade-enumerated.txt.gz"
grade_table_input_file = "edges-grade-enumerated.txt.gz"
# the units of the above graph table
grade_table_grade_unit = "decimal"
# the units of what the traversal model outputs for time
Expand All @@ -42,7 +42,7 @@ output_distance_unit = "miles"
# the name of the model that can be passed in from a query as "model_name"
name = "2012_Ford_Focus"
# the file for the routee-powertrain model
model_file = "models/2012_Ford_Focus.bin"
model_input_file = "models/2012_Ford_Focus.bin"
# what underlying machine learn framework to use [smartcore | onnx]
model_type = "smartcore"
# the units of what the routee-powertrain model expects speed to be in
Expand All @@ -69,7 +69,7 @@ type = "grid_search"
# a vertex based RTree for matching incoming x/y coordinates to a graph vertex
type = "vertex_rtree"
# a file with all the graph verticies
vertices_file = "vertices-compass.csv.gz"
vertices_input_file = "vertices-compass.csv.gz"

# output plugs get applied to the result of running a query
[[plugin.output_plugins]]
Expand All @@ -84,13 +84,13 @@ route = "geo_json"
# return the full search tree in a geojson format
tree = "geo_json"
# geometry objects for all the edges in the graph
geometry_file = "edges-geometries-enumerated.txt.gz"
geometry_input_file = "edges-geometries-enumerated.txt.gz"

[[plugin.output_plugins]]
# append an map specific id(like Open Street Maps Nodes) onto the compass verticies (which use a simple integer internal index)
type = "uuid"
# a file with ids for each vertex in the graph
uuid_file = "vertices-uuid-enumerated.txt.gz"
uuid_input_file = "vertices-uuid-enumerated.txt.gz"
```

## Traversal Models
Expand All @@ -116,7 +116,7 @@ The speed table traversal model uses a speed lookup table to compute the fastest
```toml
[traversal]
type = "speed_table"
speed_table_file = "edges-posted-speed-enumerated.txt.gz"
speed_table_input_file = "edges-posted-speed-enumerated.txt.gz"
speed_unit = "kilometers_per_hour"
output_distance_unit = "miles"
output_time_unit = "minutes"
Expand All @@ -130,10 +130,10 @@ The speed grade energy model computes energy (with a routee-powertrain vehicle m
[traversal]
type = "speed_grade_energy_model"
model_type = "smartcore"
speed_table_file = "data/tomtom_metro_denver_network/edges-free-flow-speed-enumerated.txt.gz"
grade_table_file = "data/tomtom_metro_denver_network/edges-grade-enumerated.txt.gz"
speed_table_input_file = "data/tomtom_metro_denver_network/edges-free-flow-speed-enumerated.txt.gz"
grade_table_input_file = "data/tomtom_metro_denver_network/edges-grade-enumerated.txt.gz"
grade_table_grade_unit = "decimal"
energy_model_file = "data/2016_TOYOTA_Camry_4cyl_2WD.bin"
energy_model_input_file = "data/2016_TOYOTA_Camry_4cyl_2WD.bin"
ideal_energy_rate = 0.02857142857
speed_table_speed_unit = "kilometers_per_hour"
energy_model_speed_unit = "miles_per_hour"
Expand Down Expand Up @@ -195,8 +195,6 @@ The grid search plugin would take this single query and generate two queries tha
]
```

#### Config

```toml
[[plugin.input_plugins]]
type = "grid_search"
Expand All @@ -208,12 +206,10 @@ The vertex RTree plugin uses an RTree to match coordiantes to graph verticies.

For example, if you specify your query origin and destination as lat/lon coordinates (i.e. `origin_x`, `origin_y`) we need a way to match this to the graph and then insert an `origin_vertex` or a `destination_vertex` into the query. Those two fields are what the application expects when conducting a search.

#### Config

```toml
[[plugin.input_plugins]]
type = "vertex_rtree"
vertices_file = "vertices-compass.csv.gz"
vertices_input_file = "vertices-compass.csv.gz"
```

## Output Plugins
Expand All @@ -233,14 +229,12 @@ type = "summary"

A plugin that appends various items to the result.

#### Config

```toml
[[plugin.output_plugins]]
type = "traversal"
route = "geo_json"
tree = "geo_json"
geometry_file = "edges-geometries-enumerated.txt.gz"
geometry_input_file = "edges-geometries-enumerated.txt.gz"
```

The `route` key will add route information to the result depending on the type.
Expand All @@ -251,3 +245,18 @@ Both the `route` and the `tree` key are optional and if omitted, the plugin will
- "json": non-geometry output writing traversal metrics (cost, state) as JSON for a route or a tree
- "wkt": outputs a LINESTRING for a route, or a MULTILINESTRING for a tree
- "geo_json": annotated geometry data as a FeatureCollection of LineStrings with properties assigned from traversal metrics

### To Disk

The `to_disk` plugin writes the results to a specified output file rather than returning them when the `run` method is called.

This plugin writes the results in newline delimited JSON.

```toml
[[plugin.output_plugins]]
type = "to_disk"

# where to write the results
# relative to where the application is being run
output_file = "result.json"
```
9 changes: 5 additions & 4 deletions python/nrel/routee/compass/compass_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import json

from pathlib import Path
from typing import Any, Dict, List, Union
from typing import Any, Dict, List, Optional, Union
from nrel.routee.compass.routee_compass_py import (
CompassAppWrapper,
)

Query = Dict[str, Any]
Result = List[Dict[str, Any]]


class CompassApp:
"""
Expand Down Expand Up @@ -40,9 +43,7 @@ def from_config_file(cls, config_file: Union[str, Path]) -> CompassApp:
app = CompassAppWrapper._from_config_file(str(config_path.absolute()))
return cls(app)

def run(
self, query: Union[Dict[str, Any], List[Dict[str, Any]]]
) -> List[Dict[str, Any]]:
def run(self, query: Union[Query, List[Query]]) -> Result:
"""
Run a query (or multiple queries) against the CompassApp

Expand Down
2 changes: 1 addition & 1 deletion python/nrel/routee/compass/io/generate_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def replace_id(vertex_uuid):
if filename == "osm_default_energy.toml":
if add_grade:
init_toml["traversal"][
"grade_table_file"
"grade_table_input_input_file"
] = "edges-grade-enumerated.txt.gz"
init_toml["traversal"]["grade_table_grade_unit"] = "decimal"
with open(output_directory / filename, "w") as f:
Expand Down
10 changes: 5 additions & 5 deletions python/nrel/routee/compass/resources/osm_default_distance.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
parallelism = 2

[graph]
edge_list_file = "edges-compass.csv.gz"
vertex_list_file = "vertices-compass.csv.gz"
edge_list_input_file = "edges-compass.csv.gz"
vertex_list_input_file = "vertices-compass.csv.gz"
verbose = true

[traversal]
Expand All @@ -12,10 +12,10 @@ distance_unit = "miles"
[plugin]
input_plugins = [
{ type = "grid_search" },
{ type = "vertex_rtree", vertices_file = "vertices-compass.csv.gz" },
{ type = "vertex_rtree", vertices_input_file = "vertices-compass.csv.gz" },
]
output_plugins = [
{ type = "summary" },
{ type = "traversal", route = "geo_json", tree = "geo_json", geometry_file = "edges-geometries-enumerated.txt.gz" },
{ type = "uuid", uuid_file = "vertices-uuid-enumerated.txt.gz" },
{ type = "traversal", route = "geo_json", tree = "geo_json", geometry_input_file = "edges-geometries-enumerated.txt.gz" },
{ type = "uuid", uuid_input_file = "vertices-uuid-enumerated.txt.gz" },
]
Loading