Skip to content
Snippets Groups Projects
Commit 25afeddc authored by kraleva's avatar kraleva
Browse files

Merge branch 'vicky_test' into 'main'

Debug tool

See merge request !9
parents fbb9c705 efed9cc8
Branches
No related tags found
1 merge request!9Debug tool
...@@ -25,7 +25,7 @@ The environment is called `swp_debug_tool` by default. You can activate it via t ...@@ -25,7 +25,7 @@ The environment is called `swp_debug_tool` by default. You can activate it via t
When adding dependencies, execute : When adding dependencies, execute :
```sh ```sh
conda env export -f <path to YAML file> --from-history conda env export --from-history | grep -v "^prefix: " > environment.yml
``` ```
The `--from-history` parameter prevents adding the build ID to the dependency, as that is usually OS-specific. Also, it only The `--from-history` parameter prevents adding the build ID to the dependency, as that is usually OS-specific. Also, it only
...@@ -38,3 +38,5 @@ still have build IDs (i.e. your dependencies have the form `<name>=<version>=<bu ...@@ -38,3 +38,5 @@ still have build IDs (i.e. your dependencies have the form `<name>=<version>=<bu
This works on JetBrains IDEs at least. This works on JetBrains IDEs at least.
so that the dependencies are reflected in the state of the project. so that the dependencies are reflected in the state of the project.
The proto sample should be in the directory `debug-tool/proto/sample` and the tool would take it automatically.
\ No newline at end of file
from ipyleaflet import Map, basemaps, basemap_to_tiles, GeoData from ipyleaflet import Map, basemaps, basemap_to_tiles, GeoData
from ipywidgets import HTML
from ipyleaflet import WidgetControl, LayerGroup, Polyline
from proto_parser import ( from proto_parser import (
parseData, parseData,
getNodesDataframe, getNodesDataframe,
...@@ -15,6 +17,14 @@ class DebugTool: ...@@ -15,6 +17,14 @@ class DebugTool:
center=(self.nodes_df.iloc[0].lat, self.nodes_df.iloc[0].lon), center=(self.nodes_df.iloc[0].lat, self.nodes_df.iloc[0].lon),
zoom=17, zoom=17,
) )
self.node_widget = HTML(
"""
Information Widget
"""
)
self.node_widget.layout.margin = "0px 20px 20px 20px"
control1 = WidgetControl(widget=self.node_widget, position="bottomright")
self.m.add(control1)
self.initializeLayers() self.initializeLayers()
def initializeLayers(self): def initializeLayers(self):
...@@ -39,25 +49,46 @@ class DebugTool: ...@@ -39,25 +49,46 @@ class DebugTool:
}, },
name="Intersections", name="Intersections",
) )
geo_data_edges = GeoData( geo_data_nodes.on_click(self.addNodeDescription)
geo_dataframe=self.edges_df, geo_data_edges = self.visualiseSegments()
style={
"color": "black",
"fillColor": "#3366cc",
"opacity": 0.05,
"weight": 1.9,
"dashArray": "2",
"fillOpacity": 0.6,
},
hover_style={
"fillColor": "red",
"fillOpacity": 0.2,
}, # point_style={'radius': 5, 'color': 'red', 'fillOpacity': 0.8, 'fillColor': 'blue', 'weight': 3},
name="Segments",
)
self.m.add_layer(geo_data_nodes) self.m.add_layer(geo_data_nodes)
self.m.add_layer(geo_data_edges) self.m.add_layer(geo_data_edges)
def visualiseSegments(self):
edges_layer = LayerGroup()
for _, row in self.edges_df.iterrows():
layer = Polyline(
locations=row["geometry"],
color="green",
opacity=0.6,
weight=5,
fill=False,
)
layer.on_click(self.onEdgeClick(row))
edges_layer.add_layer(layer)
return edges_layer
def onEdgeClick(self, edge):
def innerEdgeClick(**_):
self.node_widget.value = f"""
EDGE:
ID: {edge["id"]}, </br>
OSM ID: {edge["osmId"]}, </br>
LENGTH: {edge["length"]}, </br>
START NODE: {edge["startNode"]}, </br>
END NODE: {edge["endNode"]},
"""
return innerEdgeClick
def addNodeDescription(self, **e):
properties = e["properties"]
self.node_widget.value = f"""
NODE:
OSM ID: {properties["osmId"]}, </br>
LAT/LON: {properties["lat"]}, {properties["lon"]}
"""
def loadData(self): def loadData(self):
roadnetwork = parseData("./proto/sample/roadnetwork_sample.proto") roadnetwork = parseData("./proto/sample/roadnetwork_sample.proto")
self.nodes_df = getNodesDataframe(roadnetwork) self.nodes_df = getNodesDataframe(roadnetwork)
......
name: swp_debug_tool name: debug-tool
channels: channels:
- defaults - defaults
- conda-forge - conda-forge
- anaconda - anaconda
dependencies: dependencies:
- python=3.9 - ipyleaflet
- jupyter=1.0.0 - google-api-python-client
- ipyleaflet=0.17.2 - python=3.10
- protobuf=3.20.3 - pandas
- pandas=1.5.3 - pip
- geopandas=0.12.2 - shapely
- shapely=2.0.1 - jupyterlab
No preview for this file type
...@@ -24,14 +24,18 @@ def getNodesDataframe(roadnetwork_dict): ...@@ -24,14 +24,18 @@ def getNodesDataframe(roadnetwork_dict):
def getEdgesDataframe(roadnetwork_dict): def getEdgesDataframe(roadnetwork_dict):
if "segments" not in roadnetwork_dict.keys():
return gpd.GeoDataFrame()
edges_df = pd.DataFrame.from_dict(roadnetwork_dict["segments"].values()) edges_df = pd.DataFrame.from_dict(roadnetwork_dict["segments"].values())
edges_df["geometry"] = edges_df["geometry"].map( edges_df["geometry"] = edges_df["geometry"].apply(
lambda values: LineString([[x["lon"], x["lat"]] for x in values]) lambda x: [(value["lat"], value["lon"]) for value in x]
) )
gdf = gpd.GeoDataFrame(edges_df, geometry=edges_df.geometry) # gdf = gpd.GeoDataFrame(edges_df, geometry=edges_df.geometry)
return gdf return edges_df
def getTurnRestrictions(roadnetwork_dict): def getTurnRestrictions(roadnetwork_dict):
if "turnRestrictions" not in roadnetwork_dict.keys():
return gpd.GeoDataFrame()
turn_restrictions_df = pd.DataFrame.from_dict(roadnetwork_dict["turnRestrictions"]) turn_restrictions_df = pd.DataFrame.from_dict(roadnetwork_dict["turnRestrictions"])
return turn_restrictions_df return turn_restrictions_df
%% Cell type:code id:0ac881f6 tags: %% Cell type:code id:0ac881f6 tags:
``` python ``` python
%load_ext autoreload %load_ext autoreload
%autoreload 2 %autoreload 2
``` ```
%% Output
The autoreload extension is already loaded. To reload it, use:
%reload_ext autoreload
%% Cell type:markdown id:a30524cd tags: %% Cell type:markdown id:a30524cd tags:
The tool takes automatically the file put in the `debug-tool/proto/sample/roadnetwork_sample.proto` file, if you want to take a new version of the roadnetwork, just replace it and reexecute the tool The tool takes automatically the file put in the `debug-tool/proto/sample/roadnetwork_sample.proto` file, if you want to take a new version of the roadnetwork, just replace it and reexecute the tool
%% Cell type:code id:191b5e99-44db-4cb2-99f9-392a786ab6c1 tags: %% Cell type:code id:191b5e99-44db-4cb2-99f9-392a786ab6c1 tags:
``` python ``` python
from debug_map import DebugTool from debug_map import DebugTool
``` ```
%% Cell type:code id:e9991e26 tags: %% Cell type:code id:e9991e26 tags:
``` python ``` python
tool = DebugTool() tool = DebugTool()
tool.m tool.m
``` ```
%% Output %% Output
Map(center=[51.743538, 14.326337], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title',… Map(center=[51.759586, 14.31715], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', …
%% Cell type:code id:a0c84919 tags:
``` python
```
%% Cell type:code id:606f6f23 tags: %% Cell type:code id:192b13b2-2db1-4af3-abdb-cbd43ed7a86c tags:
``` python ``` python
``` ```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment