{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n\n# Exploring the network on a notebook\n\nIn this example, we show how to use Folium to plot a network for different modes.\n\nWe will need Folium for this example, and we will focus on creating a layer for\neach mode in the network, a layer for all links and a layer for all nodes.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# Imports\nfrom uuid import uuid4\nfrom tempfile import gettempdir\nfrom os.path import join\n\nfrom aequilibrae.utils.create_example import create_example\nimport folium"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# We create an empty project on an arbitrary folder\nfldr = join(gettempdir(), uuid4().hex)\n\n# Let's use the Nauru example project for display\nproject = create_example(fldr, \"nauru\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "We grab all the links data as a geopandas GeoDataFrame so we can process it easier\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "links = project.network.links.data\nnodes = project.network.nodes.data"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "And if you want to take a quick look in your GeoDataFrames, you can plot it!\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# links.plot()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Let's create copies of our link layers for each mode\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "bike = links[links[\"modes\"].str.contains(\"b\")]\ncar = links[links[\"modes\"].str.contains(\"c\")]\ntransit = links[links[\"modes\"].str.contains(\"t\")]\nwalk = links[links[\"modes\"].str.contains(\"w\")]"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "And plot out data!\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "map = links.explore(color=\"gray\", style_kwds={\"weight\": 2}, popup=\"link_id\", tooltip=\"modes\", name=\"network_links\")\nmap = nodes.explore(m=map, color=\"black\", style_kwds={\"radius\": 5, \"fillOpacity\": 1.0}, name=\"network_nodes\")\n\nmap = walk.explore(m=map, color=\"green\", style_kwds={\"weight\": 3}, popup=\"link_id\", tooltip=\"modes\", name=\"walk\")\nmap = bike.explore(m=map, color=\"green\", style_kwds={\"weight\": 3}, popup=\"link_id\", tooltip=\"modes\", name=\"bike\")\nmap = car.explore(m=map, color=\"red\", style_kwds={\"weight\": 3}, popup=\"link_id\", tooltip=\"modes\", name=\"car\")\nmap = transit.explore(m=map, color=\"yellow\", style_kwds={\"weight\": 3}, popup=\"link_id\", tooltip=\"modes\", name=\"transit\")\n\nfolium.LayerControl().add_to(map)\nmap"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "project.close()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.10.18"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}