Two Pipelines Stacked in JGIS¶
Collisions & Taxi Trips Analysis in JGIS¶
In this notebook, we assume that you went through all of the Basics
examples at the very least. In the following notebook we dive into a dual analysis of motor vehicle collisions and taxi trip pickups in Downtown Brooklyn.
Data source:
- https://data.cityofnewyork.us/Public-Safety/Motor-Vehicle-Collisions-Crashes/h9gi-nx95/
- https://www.nyc.gov/site/tlc/about/tlc-trip-record-data.page
More readings:
from urban_mapper import UrbanMapper
from urban_mapper.mixins.jupyter_gis import LayerStyle
Initialise UrbanMapper¶
We begin by creating an UrbanMapper instance, which will handle our data pipelines and map creation.
um = UrbanMapper()
Reusing the Collision Pipeline¶
This section utilises the collision pipeline previously saved from the notebook located at:
examples/Study Cases/Downtown BK Collisions Study/[4]Downtown_BK_Collisions_Advanced_Pipeline_Extras.ipynb
Alternatively, you may reuse one of the following pipelines:
examples/Study Cases/Downtown BK Collisions Study/[3]Downtown_BK_Collisions_Advanced_Pipeline.ipynb
examples/Study Cases/Downtown BK Collisions Study/[2]Downtown_BK_Collisions_Pipeline.ipynb
Instructions¶
To reuse a pipeline:
- Open and execute the desired notebook.
- Invoke the
save
method on the composed pipeline object. - This will generate a serialised file (e.g.,
name_of_pipeline.dill
) containing the pipeline for later use, such as in this next cell.
Note¶
You also can create your pipline straight here in this jupyter notebook then pass it into the pipeline
parameter of .with_pipeline(.)
introduced afterward without any issue. .with_pipeline(.)
deals with 1) pipeline saved, pipeline non-composed and pipeline already composed under the hood for you.
Here we show via an already-saved pipeline to gain time and show how fast it is.
Enjoy working with the pipeline!
Reusing the Taxi Trips Pipeline¶
This section utilises the taxi trips pipeline previously saved from the notebook located at:
examples/Study Cases/Downtown BK Taxi Trips Study/[4]Downtown_BK_Taxi_Trips_Advanced_Pipeline_Extras.ipynb
Alternatively, you may reuse one of the following pipelines:
examples/Study Cases/Downtown BK Taxi Trips Study/[2]Downtown_BK_Taxi_Trips_Pipeline.ipynb
examples/Study Cases/Downtown BK Taxi Trips Study/[3]Downtown_BK_Taxi_Trips_Advanced_Pipeline.ipynb
Instructions¶
To reuse a pipeline:
- Open and execute the desired notebook.
- Invoke the
save
method on the composed pipeline object. - This will generate a serialised file (e.g.,
name_of_pipeline.dill
) containing the pipeline for later use, such as in this next cell.
Note¶
You also can create your pipline straight here in this jupyter notebook then pass it into the pipeline
parameter of .with_pipeline(.)
introduced afterward without any issue. .with_pipeline(.)
deals with 1) pipeline saved, pipeline non-composed and pipeline already composed under the hood for you.
Here we show via an already-saved pipeline to gain time and show how fast it is.
Enjoy working with the pipeline!
Define Visualisation Styles¶
We define styles for both layers:
- Collisions: Yellow to dark red based on count, using discrete steps.
- Taxi Pickups: Light yellow to dark red with a linear gradient, reflecting pickup density.
collision_style = LayerStyle(
attribute="collision_count",
stops={
50: [255, 255, 0, 1], # Yellow
200: [255, 215, 0, 1], # Gold
500: [255, 165, 0, 1], # Orange
1500: [255, 0, 0, 1], # Red
3000: [139, 0, 0, 1] # Dark red
},
interpolation_type="discrete",
default_value=[0, 0, 0, 1]
)
taxi_style = LayerStyle(
attribute="pickup_count",
stops={
100: [255, 255, 153, 1], # Bright light yellow
101: [255, 51, 153, 1], # Hot pink
2000: [153, 51, 255, 1], # Bright purple
5000: [139, 0, 0, 1] # Dark red
},
interpolation_type="linear"
)
Create the Interactive Map¶
The map includes a dark base layer, with collisions as circles and taxi pickups as lines, allowing us to see both datasets overlaid.
jgis_analysis, jgis_doc = (
um.jupyter_gis.with_document_settings(zoom=15)
.with_raster_layer(
url="http://basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png",
name="Dark Base Map",
attribution="© OpenStreetMap contributors",
opacity=0.9
)
.with_pipeline(
pipeline="<path_to>/taxi_advanced_pipeline.dill",
layer_name="Taxi Pickup Density",
layer_style=taxi_style,
opacity=0.6,
type="line"
)
.with_pipeline(
pipeline="<path_to>/collisions_advanced_pipeline.dill",
layer_name="Collision Hotspots",
layer_style=collision_style,
opacity=0.7,
type="circle"
)
.build()
)
Save the Map¶
We save the combined map for future use or sharing.
DISCLAIMER: A file on the left will be created. Make sure to open it, and tada!
In the meantime, you can play with the jgis_doc
directly in this notebook if of interest too!
jgis_analysis.save("collision_taxi_analysis.jGIS")