{ "cells": [ { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "from pathlib import Path\n", "\n", "import pyrosm\n", "import geopandas as gpd\n", "import pandas as pd\n", "import shapely\n", "import pyproj\n", "\n", "import src.data.mapillary as mapi\n", "import src.data.osm as osmd\n", "#from src.data.mapillary import download_mapillary_image_by_key, download_mapillary_object_detection_by_key\n", "#from src.data.osm import add_mapillary_key_to_network\n", "from ipyleaflet import Map, Marker, Icon, Polyline, FullScreenControl\n", "from importlib import reload\n", "from tqdm.notebook import tqdm" ] }, { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "### Settings" ] }, { "cell_type": "code", "execution_count": 106, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "input_filepath = \"../data/raw/berlin-latest.osm.pbf\"\n", "min_quality_score = 4\n", "output_dir = Path(\"../data/processed/out\")" ] }, { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "### Code (see make_dataset.py)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "osm = pyrosm.OSM(input_filepath)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "network = osm.get_network(\n", " network_type=\"cycling\",\n", " extra_attributes=[\"surface\", \"smoothness\"]\n", ")" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "network = network.head(100)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "# Filter relevant columns\n", "network = network[[\"id\", \"geometry\", \"surface\", \"smoothness\"]]" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "# Filter only records where both surface and smoothness is set\n", "network = network[(~network[\"surface\"].isna()) & (~network[\"smoothness\"].isna())]" ] }, { "cell_type": "code", "execution_count": 102, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Request URL: https://a.mapillary.com/v3/images?client_id=TmxURHBKRFFFRTc1dWZscGpLWW5VUDo1ZjYyYmFjYjY5MTA3MDNk&bbox=13.526105139690427,52.4891476086417,13.5277082950903,52.49031200789549&per_page=500&sort_by=key&min_quality_score=4\n", "DONE\n", "Total images: 42\n" ] } ], "source": [ "# Get Mapillary keys for each street\n", "street_mapillary_df = osmd.add_mapillary_key_to_network(network.head(1), \n", " street_buffer=5,\n", " shorten_street_by=30,\n", " min_quality_score=min_quality_score)" ] }, { "cell_type": "code", "execution_count": 103, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
geometryidimg_coordsmapillary_keysmoothnesssurface
2MULTILINESTRING ((13.52783 52.49043, 13.52639 ...4045220.0POINT (13.5268612 52.4896728)DQYk9CKOsaVKI5jgJyXsnQbadsett
2MULTILINESTRING ((13.52783 52.49043, 13.52639 ...4045220.0POINT (13.5268964 52.4896935)dfHVHCxaiLxOq5kxh88NeAbadsett
2MULTILINESTRING ((13.52783 52.49043, 13.52639 ...4045220.0POINT (13.5269718 52.4897393)zyibnfVuppLVnlgGTImXxQbadsett
2MULTILINESTRING ((13.52783 52.49043, 13.52639 ...4045220.0POINT (13.5270097 52.4897627)pL2n6QmeQSa0mVlTyoLilwbadsett
2MULTILINESTRING ((13.52783 52.49043, 13.52639 ...4045220.0POINT (13.5270929 52.4898373)rmpE7Tg1R2Vrb3W6ET2dQAbadsett
2MULTILINESTRING ((13.52783 52.49043, 13.52639 ...4045220.0POINT (13.5271284 52.4898888)n6urwZz0q3NBs18aD3NULQbadsett
2MULTILINESTRING ((13.52783 52.49043, 13.52639 ...4045220.0POINT (13.5271522 52.4899155)NdcqcMPINtZwd_LfOozWdwbadsett
2MULTILINESTRING ((13.52783 52.49043, 13.52639 ...4045220.0POINT (13.5274044 52.4901188)apY4zo5qfDD83lOJjdJEpQbadsett
2MULTILINESTRING ((13.52783 52.49043, 13.52639 ...4045220.0POINT (13.5274312 52.490138)zddDUI090ORSkTD8d2-SXAbadsett
\n", "
" ], "text/plain": [ " geometry id \\\n", "2 MULTILINESTRING ((13.52783 52.49043, 13.52639 ... 4045220.0 \n", "2 MULTILINESTRING ((13.52783 52.49043, 13.52639 ... 4045220.0 \n", "2 MULTILINESTRING ((13.52783 52.49043, 13.52639 ... 4045220.0 \n", "2 MULTILINESTRING ((13.52783 52.49043, 13.52639 ... 4045220.0 \n", "2 MULTILINESTRING ((13.52783 52.49043, 13.52639 ... 4045220.0 \n", "2 MULTILINESTRING ((13.52783 52.49043, 13.52639 ... 4045220.0 \n", "2 MULTILINESTRING ((13.52783 52.49043, 13.52639 ... 4045220.0 \n", "2 MULTILINESTRING ((13.52783 52.49043, 13.52639 ... 4045220.0 \n", "2 MULTILINESTRING ((13.52783 52.49043, 13.52639 ... 4045220.0 \n", "\n", " img_coords mapillary_key smoothness surface \n", "2 POINT (13.5268612 52.4896728) DQYk9CKOsaVKI5jgJyXsnQ bad sett \n", "2 POINT (13.5268964 52.4896935) dfHVHCxaiLxOq5kxh88NeA bad sett \n", "2 POINT (13.5269718 52.4897393) zyibnfVuppLVnlgGTImXxQ bad sett \n", "2 POINT (13.5270097 52.4897627) pL2n6QmeQSa0mVlTyoLilw bad sett \n", "2 POINT (13.5270929 52.4898373) rmpE7Tg1R2Vrb3W6ET2dQA bad sett \n", "2 POINT (13.5271284 52.4898888) n6urwZz0q3NBs18aD3NULQ bad sett \n", "2 POINT (13.5271522 52.4899155) NdcqcMPINtZwd_LfOozWdw bad sett \n", "2 POINT (13.5274044 52.4901188) apY4zo5qfDD83lOJjdJEpQ bad sett \n", "2 POINT (13.5274312 52.490138) zddDUI090ORSkTD8d2-SXA bad sett " ] }, "execution_count": 103, "metadata": {}, "output_type": "execute_result" } ], "source": [ "street_mapillary_df" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "# Create output dir\n", "Path(f\"{output_dir}\").mkdir(parents=True, exist_ok=True)" ] }, { "cell_type": "code", "execution_count": 108, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "# Create sub dirs\n", "image_dir = output_dir/ \"images\"\n", "object_detection_dir = output_dir / \"object_detections\"\n", "\n", "image_dir.mkdir(exist_ok=True)\n", "object_detection_dir.mkdir(exist_ok=True)" ] }, { "cell_type": "code", "execution_count": 109, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "# Export street_mapillary_df as data.csv\n", "csv_filepath = output_dir / \"data.csv\"\n", "street_mapillary_df.to_csv(csv_filepath, index=False)" ] }, { "cell_type": "code", "execution_count": 77, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "d187651267504f2ba241822deebb1d7e", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/1 [00:00