In [1]:
Copied!
import urban_mapper as um
from urban_mapper.pipeline import UrbanPipeline
# Note: For the documentation interactive mode, we only query 5000 records from the dataset. Feel free to remove for a more realistic analysis.
data = (
um.UrbanMapper()
.loader
.from_huggingface("oscur/NYC_vehicle_collisions", number_of_rows=5000, streaming=True)
.with_columns(longitude_column="LONGITUDE", latitude_column="LATITUDE")
.load()
)
data['LONGITUDE'] = data['LONGITUDE'].astype(float)
data['LATITUDE'] = data['LATITUDE'].astype(float)
data.to_csv("./NYC_Motor_Vehicle_Collisions_Mar_12_2025.csv")
import urban_mapper as um
from urban_mapper.pipeline import UrbanPipeline
# Note: For the documentation interactive mode, we only query 5000 records from the dataset. Feel free to remove for a more realistic analysis.
data = (
um.UrbanMapper()
.loader
.from_huggingface("oscur/NYC_vehicle_collisions", number_of_rows=5000, streaming=True)
.with_columns(longitude_column="LONGITUDE", latitude_column="LATITUDE")
.load()
)
data['LONGITUDE'] = data['LONGITUDE'].astype(float)
data['LATITUDE'] = data['LATITUDE'].astype(float)
data.to_csv("./NYC_Motor_Vehicle_Collisions_Mar_12_2025.csv")
--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) Cell In[1], line 1 ----> 1 import urban_mapper as um 2 from urban_mapper.pipeline import UrbanPipeline 4 # Note: For the documentation interactive mode, we only query 5000 records from the dataset. Feel free to remove for a more realistic analysis. File ~/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/70/src/urban_mapper/__init__.py:3 1 from loguru import logger ----> 3 from .mixins import ( 4 LoaderMixin, 5 EnricherMixin, 6 VisualMixin, 7 TableVisMixin, 8 AuctusSearchMixin, 9 PipelineGeneratorMixin, 10 UrbanPipelineMixin, 11 ) 12 from .modules import ( 13 LoaderBase, 14 CSVLoader, (...) 30 PipelineGeneratorFactory, 31 ) 33 from .urban_mapper import UrbanMapper File ~/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/70/src/urban_mapper/mixins/__init__.py:1 ----> 1 from .loader import LoaderMixin 2 from .enricher import EnricherMixin 3 from .visual import VisualMixin File ~/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/70/src/urban_mapper/mixins/loader.py:1 ----> 1 from urban_mapper.modules.loader.loader_factory import LoaderFactory 4 class LoaderMixin(LoaderFactory): 5 def __init__(self): File ~/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/70/src/urban_mapper/modules/__init__.py:1 ----> 1 from .loader import LoaderBase, CSVLoader, ShapefileLoader, ParquetLoader 2 from .imputer import ( 3 GeoImputerBase, 4 SimpleGeoImputer, 5 AddressGeoImputer, 6 ) 7 from .filter import ( 8 GeoFilterBase, 9 BoundingBoxFilter, 10 ) File ~/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/70/src/urban_mapper/modules/loader/__init__.py:3 1 from .abc_loader import LoaderBase 2 from .loaders import CSVLoader, ShapefileLoader, ParquetLoader ----> 3 from .loader_factory import LoaderFactory 5 __all__ = [ 6 "LoaderBase", 7 "CSVLoader", (...) 10 "LoaderFactory", 11 ] File ~/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/70/src/urban_mapper/modules/loader/loader_factory.py:19 17 from urban_mapper.modules.loader.loaders.csv_loader import CSVLoader 18 from urban_mapper.modules.loader.loaders.parquet_loader import ParquetLoader ---> 19 from urban_mapper.modules.loader.loaders.raster_loader import RasterLoader # Importing RasterLoader of the new raster loader module 20 from urban_mapper.modules.loader.loaders.shapefile_loader import ShapefileLoader 21 from urban_mapper.utils import require_attributes File ~/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/70/src/urban_mapper/modules/loader/loaders/raster_loader.py:2 1 from ..abc_loader import LoaderBase ----> 2 import rasterio 3 from typing import Any 4 import numpy as np ModuleNotFoundError: No module named 'rasterio'
In [2]:
Copied!
mapper = um.UrbanMapper()
# Define the pipeline
pipeline = UrbanPipeline([
("urban_layer", (
mapper
.urban_layer
.with_type("streets_intersections")
.from_place("Downtown Brooklyn, New York City, USA", network_type="drive")
.with_mapping(
longitude_column="LONGITUDE",
latitude_column="LATITUDE",
output_column="nearest_intersection"
)
.build()
)),
("loader", (
mapper
.loader
.from_file("./NYC_Motor_Vehicle_Collisions_Mar_12_2025.csv")
.with_columns(longitude_column="LONGITUDE", latitude_column="LATITUDE")
.build()
)),
("imputer", (
mapper
.imputer
.with_type("SimpleGeoImputer")
.on_columns("LONGITUDE", "LATITUDE")
.build()
)),
("filter", um.UrbanMapper().filter.with_type("BoundingBoxFilter").build()),
("enricher", (
mapper
.enricher
.with_data(group_by="nearest_intersection")
.count_by(output_column="collision_count")
.build()
)),
("visualiser", (
mapper
.visual
.with_type("Interactive")
.with_style({"tiles": "CartoDB dark_matter", "colorbar_text_color": "white"})
.build()
))
])
mapper = um.UrbanMapper()
# Define the pipeline
pipeline = UrbanPipeline([
("urban_layer", (
mapper
.urban_layer
.with_type("streets_intersections")
.from_place("Downtown Brooklyn, New York City, USA", network_type="drive")
.with_mapping(
longitude_column="LONGITUDE",
latitude_column="LATITUDE",
output_column="nearest_intersection"
)
.build()
)),
("loader", (
mapper
.loader
.from_file("./NYC_Motor_Vehicle_Collisions_Mar_12_2025.csv")
.with_columns(longitude_column="LONGITUDE", latitude_column="LATITUDE")
.build()
)),
("imputer", (
mapper
.imputer
.with_type("SimpleGeoImputer")
.on_columns("LONGITUDE", "LATITUDE")
.build()
)),
("filter", um.UrbanMapper().filter.with_type("BoundingBoxFilter").build()),
("enricher", (
mapper
.enricher
.with_data(group_by="nearest_intersection")
.count_by(output_column="collision_count")
.build()
)),
("visualiser", (
mapper
.visual
.with_type("Interactive")
.with_style({"tiles": "CartoDB dark_matter", "colorbar_text_color": "white"})
.build()
))
])
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[2], line 1 ----> 1 mapper = um.UrbanMapper() 3 # Define the pipeline 4 pipeline = UrbanPipeline([ 5 ("urban_layer", ( 6 mapper (...) 45 )) 46 ]) NameError: name 'um' is not defined
In [3]:
Copied!
# Execute the pipeline
mapped_data, enriched_layer = pipeline.compose_transform()
# Execute the pipeline
mapped_data, enriched_layer = pipeline.compose_transform()
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[3], line 2 1 # Execute the pipeline ----> 2 mapped_data, enriched_layer = pipeline.compose_transform() NameError: name 'pipeline' is not defined
In [4]:
Copied!
# Visualize results
pipeline.visualise(["collision_count"])
# Visualize results
pipeline.visualise(["collision_count"])
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[4], line 2 1 # Visualize results ----> 2 pipeline.visualise(["collision_count"]) NameError: name 'pipeline' is not defined
In [5]:
Copied!
# Save the pipeline
pipeline.save("./collisions_pipeline.dill")
# Save the pipeline
pipeline.save("./collisions_pipeline.dill")
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[5], line 2 1 # Save the pipeline ----> 2 pipeline.save("./collisions_pipeline.dill") NameError: name 'pipeline' is not defined