From fbe94c78fd939b30906ddac8e6faee1564f32edd Mon Sep 17 00:00:00 2001
From: anzonyqr <69997588+anzonyqr@users.noreply.github.com>
Date: Fri, 28 Jan 2022 12:40:27 -0500
Subject: [PATCH] #162 Tutorial
---
.../Tutorial-checkpoint.ipynb | 484 ++++++++++++++++++
.../Untitled-checkpoint.ipynb | 6 -
Lecture_11/Tutorial.ipynb | 484 ++++++++++++++++++
3 files changed, 968 insertions(+), 6 deletions(-)
create mode 100644 Lecture_11/.ipynb_checkpoints/Tutorial-checkpoint.ipynb
delete mode 100644 Lecture_11/.ipynb_checkpoints/Untitled-checkpoint.ipynb
create mode 100644 Lecture_11/Tutorial.ipynb
diff --git a/Lecture_11/.ipynb_checkpoints/Tutorial-checkpoint.ipynb b/Lecture_11/.ipynb_checkpoints/Tutorial-checkpoint.ipynb
new file mode 100644
index 000000000..8b509e3e2
--- /dev/null
+++ b/Lecture_11/.ipynb_checkpoints/Tutorial-checkpoint.ipynb
@@ -0,0 +1,484 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 112,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import pandas as pd\n",
+ "from pandas import Series, DataFrame\n",
+ "import numpy as np\n",
+ "import matplotlib.pyplot as plt \n",
+ "import chardet\n",
+ "import folium as fm\n",
+ "from folium import Marker, GeoJson\n",
+ "from folium.plugins import MarkerCluster, HeatMap, StripePattern\n",
+ "import geopandas as gpd\n",
+ "from geopandas import GeoSeries\n",
+ "from shapely.geometry import Point, LineString\n",
+ "import branca as br\n",
+ "import pandas as pd\n",
+ "from pandas import Series, DataFrame\n",
+ "import numpy as np\n",
+ "import matplotlib.pyplot as plt \n",
+ "import chardet\n",
+ "import pandas as pd\n",
+ "import numpy as np\n",
+ "import folium\n",
+ "from folium.plugins import BeautifyIcon\n",
+ "import branca\n",
+ "import folium\n",
+ "from folium.plugins import MarkerCluster\n",
+ "from folium import IFrame\n",
+ "import shapely\n",
+ "from shapely.geometry import Point\n",
+ "\n",
+ "import pandas as pd\n",
+ "import geopandas as gpd\n",
+ "from geopandas.tools import sjoin\n",
+ "\n",
+ "import base64\n",
+ "import math\n",
+ "import os\n",
+ "import numpy as np\n",
+ "import seaborn as sns\n",
+ "import unicodedata\n",
+ "import pysal as ps\n",
+ "import branca\n",
+ "from selenium import webdriver\n",
+ "from selenium.webdriver.common.keys import Keys\n",
+ "from selenium.common.exceptions import NoSuchElementException\n",
+ "from selenium.webdriver import ActionChains\n",
+ "import pandas as pd\n",
+ "import numpy as np\n",
+ "import os\n",
+ "import time\n",
+ "import re\n",
+ "import unidecode\n",
+ "import time \n",
+ "from selenium.webdriver.support.ui import Select\n",
+ "from webdriver_manager.chrome import ChromeDriverManager\n",
+ "import re"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# import csv file of public health centers: MINSA, ESSALUD and Regional Goverment\n",
+ "# coordinates information (NORTE: longitud) (ESTE: latitud)\n",
+ "\n",
+ "health_centers = pd.read_csv(r'../_data/centros_hospitalarios.csv')\n",
+ "Public_health = gpd.GeoDataFrame( health_centers, geometry=gpd.points_from_xy( health_centers.NORTE, health_centers.ESTE ) )\n",
+ "Public_health = Public_health.set_crs( \"EPSG:32718\", allow_override = True)\n",
+ "Public_health.crs\n",
+ "\n",
+ "# Keep only lima\n",
+ "hc2 = Public_health[Public_health.Departamento == 'LIMA'].copy()\n",
+ "hc3 = hc2[hc2.ESTE.notnull()].copy()\n",
+ "\n",
+ "# Get lat and lon\n",
+ "hc3['lon'] = hc3.geometry.x\n",
+ "hc3['lat'] = hc3.geometry.y\n",
+ "\n",
+ "# Import shapefile\n",
+ "geo_distrito = gpd.read_file( r'../_data/shape_file/DISTRITOS.shp')\n",
+ "# keep only Lima\n",
+ "geo2 = geo_distrito[geo_distrito.DEPARTAMEN == 'LIMA']"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Health Centers in Lima"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# FDef\n",
+ "zoom_start = 8\n",
+ "lat_hos = hc3[\"lat\"].mean()\n",
+ "long_hos = hc3[\"lon\"].mean()\n",
+ "centroid_lat = lat_village\n",
+ "centroid_lon = long_village\n",
+ "\n",
+ "m = folium.Map([centroid_lat, centroid_lon], zoom_start=zoom_start)\n",
+ "\n",
+ "for _, row in hc3.iterrows():\n",
+ " \n",
+ " folium.Circle([row['lat'], row['lon']],\n",
+ " radius=50, color = \"red\",\n",
+ " fill_color=\"red\", # divvy color\n",
+ " ).add_to(m)\n",
+ "\n",
+ "\n",
+ "style2 = {'fillColor': '#ffffff', 'lineColor': '#00FFFFFF'}\n",
+ "folium.GeoJson(data=geo2[\"geometry\"], style_function=lambda x:style2, name = 'district_border').add_to(m)\n",
+ "m"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Make Clusters of different types of Health Establishments"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 75,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Get groups of latitude and longitude\n",
+ "hc3_sin = hc3[hc3.Tipo == 'ESTABLECIMIENTO DE SALUD SIN INTERNAMIENTO' ].copy()\n",
+ "hc3_con = hc3[hc3.Tipo == 'ESTABLECIMIENTO DE SALUD CON INTERNAMIENTO' ].copy()\n",
+ "hc3_apoyo = hc3[hc3.Tipo == 'SERVICIO MÉDICO DE APOYO' ].copy()\n",
+ "\n",
+ "# Create tuple of lat and long \n",
+ "locations_sin = list( zip( hc3_sin[\"lat\"], hc3_sin[\"lon\"] ) )\n",
+ "locations_con = list( zip( hc3_con[\"lat\"], hc3_con[\"lon\"]))\n",
+ "locations_apoyo = list(zip(hc3_apoyo[\"lat\"], hc3_apoyo[\"lon\"]))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Get lat and long health_center\n",
+ "zoom_start = 8\n",
+ "lat_health_center = hc3[\"lat\"].mean()\n",
+ "long_health_center = hc3[\"lon\"].mean()\n",
+ "\n",
+ "centroid_lat = lat_health_center\n",
+ "centroid_lon = long_health_center\n",
+ "\n",
+ "m = folium.Map([centroid_lat, centroid_lon], zoom_start=zoom_start)\n",
+ "\n",
+ "style2 = {'fillColor': '#ffffff', 'lineColor': '#00FFFFFF'}\n",
+ "folium.GeoJson(data=geo2[\"geometry\"], style_function=lambda x:style2, name = 'District Border').add_to(m)\n",
+ "\n",
+ "\n",
+ "\n",
+ "### 2015\n",
+ "marker_cluster_1 = MarkerCluster(\n",
+ " locations=locations_sin,\n",
+ " name=\"ESTABLECIMIENTO DE SALUD SIN INTERNAMIENTO\",\n",
+ " overlay=True,\n",
+ " control=True,\n",
+ " \n",
+ ")\n",
+ "\n",
+ "marker_cluster_2 = MarkerCluster(\n",
+ " locations=locations_con,\n",
+ " name=\"ESTABLECIMIENTO DE SALUD CON INTERNAMIENTO\",\n",
+ " overlay=True,\n",
+ " control=True,\n",
+ " \n",
+ ")\n",
+ "\n",
+ "\n",
+ "### 2018\n",
+ "marker_cluster_3 = MarkerCluster(\n",
+ " locations=locations_apoyo,\n",
+ " name=\"SERVICIO MÉDICO DE APOYO\",\n",
+ " overlay=True,\n",
+ " control=True,\n",
+ " \n",
+ ")\n",
+ "\n",
+ "\n",
+ "marker_cluster_1.add_to(m)\n",
+ "marker_cluster_2.add_to(m)\n",
+ "marker_cluster_3.add_to(m)\n",
+ "\n",
+ "\n",
+ "# Add TileLayer\n",
+ "folium.TileLayer( tiles = 'https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png',\n",
+ "attr = '© OpenStreetMap contributors © CARTO',\n",
+ "name = 'Stadia_AlidadeSmoothDark').add_to(m)\n",
+ "\n",
+ "# folium.TileLayer('openstreetmap').add_to(m)\n",
+ "# folium.TileLayer('Stamen Terrain').add_to(m)\n",
+ "\n",
+ "folium.LayerControl().add_to(m)\n",
+ "m\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Make plot of Clusters"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Get lat and long health_center\n",
+ "zoom_start = 8\n",
+ "lat_health_center = hc3[\"lat\"].mean()\n",
+ "long_health_center = hc3[\"lon\"].mean()\n",
+ "\n",
+ "centroid_lat = lat_health_center\n",
+ "centroid_lon = long_health_center\n",
+ "\n",
+ "m = folium.Map([centroid_lat, centroid_lon], zoom_start=zoom_start)\n",
+ "\n",
+ "# Add District shapefiles\n",
+ "style2 = {'fillColor': '#ffffff', 'lineColor': '#00FFFFFF'}\n",
+ "folium.GeoJson(data=geo2[\"geometry\"], style_function=lambda x:style2, name = 'District Border').add_to(m)\n",
+ "\n",
+ "\n",
+ "# Genereate groups in folioum\n",
+ "health_centers_group = folium.FeatureGroup( name = 'Heakth Centers', control=True)\n",
+ "\n",
+ "hth_con = folium.FeatureGroup( name = 'ESTABLECIMIENTO DE SALUD SIN INTERNAMIENTO', control = True )\n",
+ "hth_sin = folium.FeatureGroup( name = 'ESTABLECIMIENTO DE SALUD CON INTERNAMIENTO', control = True )\n",
+ "hth_apoyo = folium.FeatureGroup( name = 'SERVICIO MÉDICO DE APOYO', control = True )\n",
+ "\n",
+ "\n",
+ "# Helath establishment groups\n",
+ "\n",
+ "# HEALTH ESTABLISHMENT WITHOUT INTERNMENT GROUP\n",
+ "for _, row in hc3_sin.iterrows():\n",
+ " \n",
+ " # Customize pop up \n",
+ " html = row[ 'Nombre del establecimiento' ]\n",
+ " iframe = br.element.IFrame( html = html, width = 180, height = 100 )\n",
+ " popup = fm.Popup( iframe, parse_html = True )\n",
+ " \n",
+ " folium.Marker( [row[ 'lat' ], row[ 'lon' ] ] , \n",
+ " popup = popup,\n",
+ " icon = folium.Icon( color = \"green\" )\n",
+ " ).add_to( hth_con )\n",
+ " \n",
+ "# HEALTH ESTABLISHMENT WITH INTERNMENT Group\n",
+ "for _, row in hc3_con.iterrows():\n",
+ " \n",
+ " # Customize pop up \n",
+ " html = row[ 'Nombre del establecimiento' ]\n",
+ " iframe = br.element.IFrame( html = html, width = 180, height = 100 )\n",
+ " popup = fm.Popup( iframe, parse_html = True )\n",
+ "\n",
+ " folium.Marker( [row[ 'lat' ], row[ 'lon' ] ] , \n",
+ " popup = row[ 'Nombre del establecimiento' ].lower(),\n",
+ " icon = folium.Icon( color = \"blue\" )\n",
+ " ).add_to( hth_sin )\n",
+ "\n",
+ "# Apoyo group\n",
+ "for _, row in hc3_apoyo.iterrows():\n",
+ " \n",
+ " # Customize pop up \n",
+ " html = row[ 'Nombre del establecimiento' ]\n",
+ " iframe = br.element.IFrame( html = html, width = 180, height = 100 )\n",
+ " popup = fm.Popup( iframe, parse_html = True )\n",
+ "\n",
+ " folium.Marker( [row[ 'lat' ], row[ 'lon' ] ] , \n",
+ " popup = popup,\n",
+ " icon = folium.Icon( color = \"red\" )\n",
+ " ).add_to( hth_apoyo )\n",
+ " \n",
+ "\n",
+ "# Add groups \n",
+ "m.add_child( hth_con )\n",
+ "m.add_child( hth_sin ) \n",
+ "m.add_child( hth_apoyo ) \n",
+ " \n",
+ "\n",
+ "\n",
+ "legend_html_0 = '''\n",
+ "
► Legend\n",
+ "
● WITHOUT INTERNMENT
\n",
+ "
● WITH INTERNMENT
\n",
+ "
● Apoyo
\n",
+ "\n",
+ "\n",
+ "\n",
+ "
\n",
+ "\n",
+ "
\n",
+ "'''\n",
+ "\n",
+ "# Add Legend\n",
+ "legend_html = \"{% macro html(this, kwargs) %}\" + legend_html_0 + \"{% endmacro %}\"\n",
+ "legend = branca.element.MacroElement()\n",
+ "legend._template = branca.element.Template(legend_html)\n",
+ "m.get_root().add_child(legend)\n",
+ "\n",
+ "# Add layer\n",
+ "folium.LayerControl().add_to(m)\n",
+ "\n",
+ "\n",
+ "m"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Get lat and long health_center\n",
+ "zoom_start = 8\n",
+ "lat_health_center = hc3[\"lat\"].mean()\n",
+ "long_health_center = hc3[\"lon\"].mean()\n",
+ "\n",
+ "centroid_lat = lat_health_center\n",
+ "centroid_lon = long_health_center\n",
+ "\n",
+ "m = folium.Map([centroid_lat, centroid_lon], zoom_start=zoom_start)\n",
+ "\n",
+ "# Add District shapefiles\n",
+ "style2 = {'fillColor': '#ffffff', 'lineColor': '#00FFFFFF'}\n",
+ "folium.GeoJson(data=geo2[\"geometry\"], style_function=lambda x:style2, name = 'District Border').add_to(m)\n",
+ "\n",
+ "\n",
+ "# Genereate groups in folioum\n",
+ "health_centers_group = folium.FeatureGroup( name = 'Heakth Centers', control=True)\n",
+ "\n",
+ "hth_con = folium.FeatureGroup( name = 'ESTABLECIMIENTO DE SALUD SIN INTERNAMIENTO', control = True )\n",
+ "hth_sin = folium.FeatureGroup( name = 'ESTABLECIMIENTO DE SALUD CON INTERNAMIENTO', control = True )\n",
+ "hth_apoyo = folium.FeatureGroup( name = 'SERVICIO MÉDICO DE APOYO', control = True )\n",
+ "\n",
+ "\n",
+ "# Helath establishment groups\n",
+ "\n",
+ "# HEALTH ESTABLISHMENT WITHOUT INTERNMENT GROUP\n",
+ "for _, row in hc3_sin.iterrows():\n",
+ "\n",
+ " \n",
+ " folium.Circle( [row[ 'lat' ], row[ 'lon' ] ] , \n",
+ " radius=15, color = \"green\",\n",
+ " fill_color=\"green\", # divvy color\n",
+ " ).add_to( hth_con )\n",
+ " \n",
+ "# HEALTH ESTABLISHMENT WITH INTERNMENT Group\n",
+ "for _, row in hc3_con.iterrows():\n",
+ " \n",
+ " folium.Circle( [row[ 'lat' ], row[ 'lon' ] ] , \n",
+ " radius=15, color = \"blue\",\n",
+ " fill_color=\"blue\", # divvy color\n",
+ " ).add_to( hth_sin )\n",
+ "\n",
+ "# Apoyo group\n",
+ "for _, row in hc3_apoyo.iterrows():\n",
+ " \n",
+ " # Customize pop up \n",
+ " html = row[ 'Nombre del establecimiento' ]\n",
+ " iframe = br.element.IFrame( html = html, width = 180, height = 100 )\n",
+ " popup = fm.Popup( iframe, parse_html = True )\n",
+ "\n",
+ " folium.Circle( [row[ 'lat' ], row[ 'lon' ] ] , \n",
+ " radius=15, color = \"red\",\n",
+ " fill_color=\"red\", # divvy color\n",
+ " ).add_to( hth_apoyo )\n",
+ " \n",
+ "\n",
+ "\n",
+ "# Add groups \n",
+ "m.add_child( hth_con )\n",
+ "m.add_child( hth_sin ) \n",
+ "m.add_child( hth_apoyo ) \n",
+ " \n",
+ "\n",
+ "\n",
+ "legend_html_0 = '''\n",
+ "► Legend\n",
+ "
● WITHOUT INTERNMENT
\n",
+ "
● WITH INTERNMENT
\n",
+ "
● Apoyo
\n",
+ "\n",
+ "\n",
+ "\n",
+ "
\n",
+ "\n",
+ "
\n",
+ "'''\n",
+ "\n",
+ "# Add legend\n",
+ "legend_html = \"{% macro html(this, kwargs) %}\" + legend_html_0 + \"{% endmacro %}\"\n",
+ "legend = branca.element.MacroElement()\n",
+ "legend._template = branca.element.Template(legend_html)\n",
+ "m.get_root().add_child(legend)\n",
+ "\n",
+ "# Add layer\n",
+ "folium.LayerControl().add_to(m)\n",
+ "m"
+ ]
+ }
+ ],
+ "metadata": {
+ "hide_input": false,
+ "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.8.6"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 4
+}
diff --git a/Lecture_11/.ipynb_checkpoints/Untitled-checkpoint.ipynb b/Lecture_11/.ipynb_checkpoints/Untitled-checkpoint.ipynb
deleted file mode 100644
index 7fec51502..000000000
--- a/Lecture_11/.ipynb_checkpoints/Untitled-checkpoint.ipynb
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "cells": [],
- "metadata": {},
- "nbformat": 4,
- "nbformat_minor": 4
-}
diff --git a/Lecture_11/Tutorial.ipynb b/Lecture_11/Tutorial.ipynb
new file mode 100644
index 000000000..8b509e3e2
--- /dev/null
+++ b/Lecture_11/Tutorial.ipynb
@@ -0,0 +1,484 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 112,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import pandas as pd\n",
+ "from pandas import Series, DataFrame\n",
+ "import numpy as np\n",
+ "import matplotlib.pyplot as plt \n",
+ "import chardet\n",
+ "import folium as fm\n",
+ "from folium import Marker, GeoJson\n",
+ "from folium.plugins import MarkerCluster, HeatMap, StripePattern\n",
+ "import geopandas as gpd\n",
+ "from geopandas import GeoSeries\n",
+ "from shapely.geometry import Point, LineString\n",
+ "import branca as br\n",
+ "import pandas as pd\n",
+ "from pandas import Series, DataFrame\n",
+ "import numpy as np\n",
+ "import matplotlib.pyplot as plt \n",
+ "import chardet\n",
+ "import pandas as pd\n",
+ "import numpy as np\n",
+ "import folium\n",
+ "from folium.plugins import BeautifyIcon\n",
+ "import branca\n",
+ "import folium\n",
+ "from folium.plugins import MarkerCluster\n",
+ "from folium import IFrame\n",
+ "import shapely\n",
+ "from shapely.geometry import Point\n",
+ "\n",
+ "import pandas as pd\n",
+ "import geopandas as gpd\n",
+ "from geopandas.tools import sjoin\n",
+ "\n",
+ "import base64\n",
+ "import math\n",
+ "import os\n",
+ "import numpy as np\n",
+ "import seaborn as sns\n",
+ "import unicodedata\n",
+ "import pysal as ps\n",
+ "import branca\n",
+ "from selenium import webdriver\n",
+ "from selenium.webdriver.common.keys import Keys\n",
+ "from selenium.common.exceptions import NoSuchElementException\n",
+ "from selenium.webdriver import ActionChains\n",
+ "import pandas as pd\n",
+ "import numpy as np\n",
+ "import os\n",
+ "import time\n",
+ "import re\n",
+ "import unidecode\n",
+ "import time \n",
+ "from selenium.webdriver.support.ui import Select\n",
+ "from webdriver_manager.chrome import ChromeDriverManager\n",
+ "import re"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# import csv file of public health centers: MINSA, ESSALUD and Regional Goverment\n",
+ "# coordinates information (NORTE: longitud) (ESTE: latitud)\n",
+ "\n",
+ "health_centers = pd.read_csv(r'../_data/centros_hospitalarios.csv')\n",
+ "Public_health = gpd.GeoDataFrame( health_centers, geometry=gpd.points_from_xy( health_centers.NORTE, health_centers.ESTE ) )\n",
+ "Public_health = Public_health.set_crs( \"EPSG:32718\", allow_override = True)\n",
+ "Public_health.crs\n",
+ "\n",
+ "# Keep only lima\n",
+ "hc2 = Public_health[Public_health.Departamento == 'LIMA'].copy()\n",
+ "hc3 = hc2[hc2.ESTE.notnull()].copy()\n",
+ "\n",
+ "# Get lat and lon\n",
+ "hc3['lon'] = hc3.geometry.x\n",
+ "hc3['lat'] = hc3.geometry.y\n",
+ "\n",
+ "# Import shapefile\n",
+ "geo_distrito = gpd.read_file( r'../_data/shape_file/DISTRITOS.shp')\n",
+ "# keep only Lima\n",
+ "geo2 = geo_distrito[geo_distrito.DEPARTAMEN == 'LIMA']"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Health Centers in Lima"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# FDef\n",
+ "zoom_start = 8\n",
+ "lat_hos = hc3[\"lat\"].mean()\n",
+ "long_hos = hc3[\"lon\"].mean()\n",
+ "centroid_lat = lat_village\n",
+ "centroid_lon = long_village\n",
+ "\n",
+ "m = folium.Map([centroid_lat, centroid_lon], zoom_start=zoom_start)\n",
+ "\n",
+ "for _, row in hc3.iterrows():\n",
+ " \n",
+ " folium.Circle([row['lat'], row['lon']],\n",
+ " radius=50, color = \"red\",\n",
+ " fill_color=\"red\", # divvy color\n",
+ " ).add_to(m)\n",
+ "\n",
+ "\n",
+ "style2 = {'fillColor': '#ffffff', 'lineColor': '#00FFFFFF'}\n",
+ "folium.GeoJson(data=geo2[\"geometry\"], style_function=lambda x:style2, name = 'district_border').add_to(m)\n",
+ "m"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Make Clusters of different types of Health Establishments"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 75,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Get groups of latitude and longitude\n",
+ "hc3_sin = hc3[hc3.Tipo == 'ESTABLECIMIENTO DE SALUD SIN INTERNAMIENTO' ].copy()\n",
+ "hc3_con = hc3[hc3.Tipo == 'ESTABLECIMIENTO DE SALUD CON INTERNAMIENTO' ].copy()\n",
+ "hc3_apoyo = hc3[hc3.Tipo == 'SERVICIO MÉDICO DE APOYO' ].copy()\n",
+ "\n",
+ "# Create tuple of lat and long \n",
+ "locations_sin = list( zip( hc3_sin[\"lat\"], hc3_sin[\"lon\"] ) )\n",
+ "locations_con = list( zip( hc3_con[\"lat\"], hc3_con[\"lon\"]))\n",
+ "locations_apoyo = list(zip(hc3_apoyo[\"lat\"], hc3_apoyo[\"lon\"]))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Get lat and long health_center\n",
+ "zoom_start = 8\n",
+ "lat_health_center = hc3[\"lat\"].mean()\n",
+ "long_health_center = hc3[\"lon\"].mean()\n",
+ "\n",
+ "centroid_lat = lat_health_center\n",
+ "centroid_lon = long_health_center\n",
+ "\n",
+ "m = folium.Map([centroid_lat, centroid_lon], zoom_start=zoom_start)\n",
+ "\n",
+ "style2 = {'fillColor': '#ffffff', 'lineColor': '#00FFFFFF'}\n",
+ "folium.GeoJson(data=geo2[\"geometry\"], style_function=lambda x:style2, name = 'District Border').add_to(m)\n",
+ "\n",
+ "\n",
+ "\n",
+ "### 2015\n",
+ "marker_cluster_1 = MarkerCluster(\n",
+ " locations=locations_sin,\n",
+ " name=\"ESTABLECIMIENTO DE SALUD SIN INTERNAMIENTO\",\n",
+ " overlay=True,\n",
+ " control=True,\n",
+ " \n",
+ ")\n",
+ "\n",
+ "marker_cluster_2 = MarkerCluster(\n",
+ " locations=locations_con,\n",
+ " name=\"ESTABLECIMIENTO DE SALUD CON INTERNAMIENTO\",\n",
+ " overlay=True,\n",
+ " control=True,\n",
+ " \n",
+ ")\n",
+ "\n",
+ "\n",
+ "### 2018\n",
+ "marker_cluster_3 = MarkerCluster(\n",
+ " locations=locations_apoyo,\n",
+ " name=\"SERVICIO MÉDICO DE APOYO\",\n",
+ " overlay=True,\n",
+ " control=True,\n",
+ " \n",
+ ")\n",
+ "\n",
+ "\n",
+ "marker_cluster_1.add_to(m)\n",
+ "marker_cluster_2.add_to(m)\n",
+ "marker_cluster_3.add_to(m)\n",
+ "\n",
+ "\n",
+ "# Add TileLayer\n",
+ "folium.TileLayer( tiles = 'https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png',\n",
+ "attr = '© OpenStreetMap contributors © CARTO',\n",
+ "name = 'Stadia_AlidadeSmoothDark').add_to(m)\n",
+ "\n",
+ "# folium.TileLayer('openstreetmap').add_to(m)\n",
+ "# folium.TileLayer('Stamen Terrain').add_to(m)\n",
+ "\n",
+ "folium.LayerControl().add_to(m)\n",
+ "m\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Make plot of Clusters"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Get lat and long health_center\n",
+ "zoom_start = 8\n",
+ "lat_health_center = hc3[\"lat\"].mean()\n",
+ "long_health_center = hc3[\"lon\"].mean()\n",
+ "\n",
+ "centroid_lat = lat_health_center\n",
+ "centroid_lon = long_health_center\n",
+ "\n",
+ "m = folium.Map([centroid_lat, centroid_lon], zoom_start=zoom_start)\n",
+ "\n",
+ "# Add District shapefiles\n",
+ "style2 = {'fillColor': '#ffffff', 'lineColor': '#00FFFFFF'}\n",
+ "folium.GeoJson(data=geo2[\"geometry\"], style_function=lambda x:style2, name = 'District Border').add_to(m)\n",
+ "\n",
+ "\n",
+ "# Genereate groups in folioum\n",
+ "health_centers_group = folium.FeatureGroup( name = 'Heakth Centers', control=True)\n",
+ "\n",
+ "hth_con = folium.FeatureGroup( name = 'ESTABLECIMIENTO DE SALUD SIN INTERNAMIENTO', control = True )\n",
+ "hth_sin = folium.FeatureGroup( name = 'ESTABLECIMIENTO DE SALUD CON INTERNAMIENTO', control = True )\n",
+ "hth_apoyo = folium.FeatureGroup( name = 'SERVICIO MÉDICO DE APOYO', control = True )\n",
+ "\n",
+ "\n",
+ "# Helath establishment groups\n",
+ "\n",
+ "# HEALTH ESTABLISHMENT WITHOUT INTERNMENT GROUP\n",
+ "for _, row in hc3_sin.iterrows():\n",
+ " \n",
+ " # Customize pop up \n",
+ " html = row[ 'Nombre del establecimiento' ]\n",
+ " iframe = br.element.IFrame( html = html, width = 180, height = 100 )\n",
+ " popup = fm.Popup( iframe, parse_html = True )\n",
+ " \n",
+ " folium.Marker( [row[ 'lat' ], row[ 'lon' ] ] , \n",
+ " popup = popup,\n",
+ " icon = folium.Icon( color = \"green\" )\n",
+ " ).add_to( hth_con )\n",
+ " \n",
+ "# HEALTH ESTABLISHMENT WITH INTERNMENT Group\n",
+ "for _, row in hc3_con.iterrows():\n",
+ " \n",
+ " # Customize pop up \n",
+ " html = row[ 'Nombre del establecimiento' ]\n",
+ " iframe = br.element.IFrame( html = html, width = 180, height = 100 )\n",
+ " popup = fm.Popup( iframe, parse_html = True )\n",
+ "\n",
+ " folium.Marker( [row[ 'lat' ], row[ 'lon' ] ] , \n",
+ " popup = row[ 'Nombre del establecimiento' ].lower(),\n",
+ " icon = folium.Icon( color = \"blue\" )\n",
+ " ).add_to( hth_sin )\n",
+ "\n",
+ "# Apoyo group\n",
+ "for _, row in hc3_apoyo.iterrows():\n",
+ " \n",
+ " # Customize pop up \n",
+ " html = row[ 'Nombre del establecimiento' ]\n",
+ " iframe = br.element.IFrame( html = html, width = 180, height = 100 )\n",
+ " popup = fm.Popup( iframe, parse_html = True )\n",
+ "\n",
+ " folium.Marker( [row[ 'lat' ], row[ 'lon' ] ] , \n",
+ " popup = popup,\n",
+ " icon = folium.Icon( color = \"red\" )\n",
+ " ).add_to( hth_apoyo )\n",
+ " \n",
+ "\n",
+ "# Add groups \n",
+ "m.add_child( hth_con )\n",
+ "m.add_child( hth_sin ) \n",
+ "m.add_child( hth_apoyo ) \n",
+ " \n",
+ "\n",
+ "\n",
+ "legend_html_0 = '''\n",
+ "► Legend\n",
+ "
● WITHOUT INTERNMENT
\n",
+ "
● WITH INTERNMENT
\n",
+ "
● Apoyo
\n",
+ "\n",
+ "\n",
+ "\n",
+ "
\n",
+ "\n",
+ "
\n",
+ "'''\n",
+ "\n",
+ "# Add Legend\n",
+ "legend_html = \"{% macro html(this, kwargs) %}\" + legend_html_0 + \"{% endmacro %}\"\n",
+ "legend = branca.element.MacroElement()\n",
+ "legend._template = branca.element.Template(legend_html)\n",
+ "m.get_root().add_child(legend)\n",
+ "\n",
+ "# Add layer\n",
+ "folium.LayerControl().add_to(m)\n",
+ "\n",
+ "\n",
+ "m"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Get lat and long health_center\n",
+ "zoom_start = 8\n",
+ "lat_health_center = hc3[\"lat\"].mean()\n",
+ "long_health_center = hc3[\"lon\"].mean()\n",
+ "\n",
+ "centroid_lat = lat_health_center\n",
+ "centroid_lon = long_health_center\n",
+ "\n",
+ "m = folium.Map([centroid_lat, centroid_lon], zoom_start=zoom_start)\n",
+ "\n",
+ "# Add District shapefiles\n",
+ "style2 = {'fillColor': '#ffffff', 'lineColor': '#00FFFFFF'}\n",
+ "folium.GeoJson(data=geo2[\"geometry\"], style_function=lambda x:style2, name = 'District Border').add_to(m)\n",
+ "\n",
+ "\n",
+ "# Genereate groups in folioum\n",
+ "health_centers_group = folium.FeatureGroup( name = 'Heakth Centers', control=True)\n",
+ "\n",
+ "hth_con = folium.FeatureGroup( name = 'ESTABLECIMIENTO DE SALUD SIN INTERNAMIENTO', control = True )\n",
+ "hth_sin = folium.FeatureGroup( name = 'ESTABLECIMIENTO DE SALUD CON INTERNAMIENTO', control = True )\n",
+ "hth_apoyo = folium.FeatureGroup( name = 'SERVICIO MÉDICO DE APOYO', control = True )\n",
+ "\n",
+ "\n",
+ "# Helath establishment groups\n",
+ "\n",
+ "# HEALTH ESTABLISHMENT WITHOUT INTERNMENT GROUP\n",
+ "for _, row in hc3_sin.iterrows():\n",
+ "\n",
+ " \n",
+ " folium.Circle( [row[ 'lat' ], row[ 'lon' ] ] , \n",
+ " radius=15, color = \"green\",\n",
+ " fill_color=\"green\", # divvy color\n",
+ " ).add_to( hth_con )\n",
+ " \n",
+ "# HEALTH ESTABLISHMENT WITH INTERNMENT Group\n",
+ "for _, row in hc3_con.iterrows():\n",
+ " \n",
+ " folium.Circle( [row[ 'lat' ], row[ 'lon' ] ] , \n",
+ " radius=15, color = \"blue\",\n",
+ " fill_color=\"blue\", # divvy color\n",
+ " ).add_to( hth_sin )\n",
+ "\n",
+ "# Apoyo group\n",
+ "for _, row in hc3_apoyo.iterrows():\n",
+ " \n",
+ " # Customize pop up \n",
+ " html = row[ 'Nombre del establecimiento' ]\n",
+ " iframe = br.element.IFrame( html = html, width = 180, height = 100 )\n",
+ " popup = fm.Popup( iframe, parse_html = True )\n",
+ "\n",
+ " folium.Circle( [row[ 'lat' ], row[ 'lon' ] ] , \n",
+ " radius=15, color = \"red\",\n",
+ " fill_color=\"red\", # divvy color\n",
+ " ).add_to( hth_apoyo )\n",
+ " \n",
+ "\n",
+ "\n",
+ "# Add groups \n",
+ "m.add_child( hth_con )\n",
+ "m.add_child( hth_sin ) \n",
+ "m.add_child( hth_apoyo ) \n",
+ " \n",
+ "\n",
+ "\n",
+ "legend_html_0 = '''\n",
+ "► Legend\n",
+ "
● WITHOUT INTERNMENT
\n",
+ "
● WITH INTERNMENT
\n",
+ "
● Apoyo
\n",
+ "\n",
+ "\n",
+ "\n",
+ "
\n",
+ "\n",
+ "
\n",
+ "'''\n",
+ "\n",
+ "# Add legend\n",
+ "legend_html = \"{% macro html(this, kwargs) %}\" + legend_html_0 + \"{% endmacro %}\"\n",
+ "legend = branca.element.MacroElement()\n",
+ "legend._template = branca.element.Template(legend_html)\n",
+ "m.get_root().add_child(legend)\n",
+ "\n",
+ "# Add layer\n",
+ "folium.LayerControl().add_to(m)\n",
+ "m"
+ ]
+ }
+ ],
+ "metadata": {
+ "hide_input": false,
+ "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.8.6"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 4
+}