{ "cells": [ { "cell_type": "markdown", "id": "ea4e3349-9fc2-41e9-834c-f784c843a95e", "metadata": {}, "source": [ "# Example Visualizations using CyberGIS-Vis" ] }, { "cell_type": "markdown", "id": "f595ccc2-a25e-4745-b18a-555938b037ea", "metadata": {}, "source": [ "#### Documentations and Demos about CyberGIS-Vis are available at: https://github.com/su-gis/CyberGIS-Vis" ] }, { "cell_type": "markdown", "id": "4ff57881-5852-4900-87a8-4479da615c77", "metadata": {}, "source": [ "## Adaptive Choropleth Mapper with Multiple Line Chart (MLC): Temporal Patterns of Covid-19 Crude Rate and Death Rate in US Counties" ] }, { "cell_type": "markdown", "id": "ed09b33e-a504-44c4-b208-aea277961934", "metadata": {}, "source": [ "## Setup environment" ] }, { "cell_type": "code", "execution_count": 1, "id": "f2fea90f-ace0-49a7-ba55-832f941eb6c4", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import geopandas as gpd\n", "from Adaptive_Choropleth_Mapper import CLC, MLC, Initial_Layers" ] }, { "cell_type": "markdown", "id": "30bb97d9-c261-479f-9f15-eb3ac440cb14", "metadata": {}, "source": [ "### Set input Data" ] }, { "cell_type": "markdown", "id": "efa40adb-9028-48ca-a516-515d586ae06c", "metadata": {}, "source": [ "1. Load U.S. counties from the Shapefile. Note: New York is an exception, represented by New York City with the city ID 777777, instead of county names and IDs.\n", "- Read the Shapefile \"County_NY_TIMES.shp\" into a GeoDataFrame\n", "- The Shapefile is located in the \"shp/US/\" directory\n", "- The 'geoid' column is explicitly set to be read as a string (str)\n", "- The first column in both the attribute file and the shapefile must be named 'geoid,' as it serves as the key for joining the shapefile with the attribute data.\n", "- The second column should contain the names of the corresponding regions, which will be directly displayed on the resulting map." ] }, { "cell_type": "code", "execution_count": 2, "id": "2c3b778c-7391-4288-b198-097f7059b763", "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", " \n", " \n", " \n", " \n", " \n", " \n", "
geoidnameShape_LengShape_Areageometry
010001Kent,DE2.0296820.215240POLYGON ((-75.74776 39.14334, -75.75600 39.246...
110003New Castle,DE1.7987790.134081POLYGON ((-75.78860 39.72220, -75.77379 39.722...
210005Sussex,DE2.3690840.320841POLYGON ((-75.70157 38.56074, -75.70744 38.635...
31001Autauga,AL1.9949480.150242POLYGON ((-86.41312 32.70739, -86.41279 32.625...
41003Baldwin,AL3.9775600.494110POLYGON ((-87.59883 30.99745, -87.59650 30.987...
..................
32129007Middlesex,CT1.8781720.122471POLYGON ((-72.75218 41.57889, -72.75294 41.592...
32139009New Haven,CT2.6298680.240237POLYGON ((-73.31047 41.46881, -73.32091 41.477...
32149011New London,CT2.3902770.215441POLYGON ((-72.46673 41.58390, -72.41723 41.590...
32159013Tolland,CT1.8120810.117074POLYGON ((-72.13572 42.03025, -72.10217 42.028...
32169015Windham,CT1.7546120.146376POLYGON ((-71.78970 41.72456, -71.78725 41.656...
\n", "

3217 rows × 5 columns

\n", "
" ], "text/plain": [ " geoid name Shape_Leng Shape_Area \n", "0 10001 Kent,DE 2.029682 0.215240 \\\n", "1 10003 New Castle,DE 1.798779 0.134081 \n", "2 10005 Sussex,DE 2.369084 0.320841 \n", "3 1001 Autauga,AL 1.994948 0.150242 \n", "4 1003 Baldwin,AL 3.977560 0.494110 \n", "... ... ... ... ... \n", "3212 9007 Middlesex,CT 1.878172 0.122471 \n", "3213 9009 New Haven,CT 2.629868 0.240237 \n", "3214 9011 New London,CT 2.390277 0.215441 \n", "3215 9013 Tolland,CT 1.812081 0.117074 \n", "3216 9015 Windham,CT 1.754612 0.146376 \n", "\n", " geometry \n", "0 POLYGON ((-75.74776 39.14334, -75.75600 39.246... \n", "1 POLYGON ((-75.78860 39.72220, -75.77379 39.722... \n", "2 POLYGON ((-75.70157 38.56074, -75.70744 38.635... \n", "3 POLYGON ((-86.41312 32.70739, -86.41279 32.625... \n", "4 POLYGON ((-87.59883 30.99745, -87.59650 30.987... \n", "... ... \n", "3212 POLYGON ((-72.75218 41.57889, -72.75294 41.592... \n", "3213 POLYGON ((-73.31047 41.46881, -73.32091 41.477... \n", "3214 POLYGON ((-72.46673 41.58390, -72.41723 41.590... \n", "3215 POLYGON ((-72.13572 42.03025, -72.10217 42.028... \n", "3216 POLYGON ((-71.78970 41.72456, -71.78725 41.656... \n", "\n", "[3217 rows x 5 columns]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "shapefile = gpd.read_file(\"shp/US/County_NY_TIMES.shp\", dtype={'geoid': str})\n", "shapefile" ] }, { "cell_type": "markdown", "id": "bb46b47e-ac00-4339-871c-97bf9011a0dc", "metadata": {}, "source": [ "2. Load the attribute data that will be used for visualization. Data Source: \"The New York Times. (2021). Coronavirus (Covid-19) Data in the United States. Retrieved [08/01/2024], from https://github.com/nytimes/covid-19-data.\"\n", "- Read the CSV file \"Covid_Rate_Mobility_US_2020_2021_weekly.csv\" into a DataFrame\n", "- The CSV file is located in the \"attributes/\" directory\n", "- The 'geoid' column is explicitly set to be read as a string (str)\n", "- The first column in both the attribute file and the shapefile must be named 'geoid,' as it serves as the key for joining the shapefile with the attribute data.\n", "- The second column header must be named 'period' and should contain time-related values, such as days, months, or years, formatted as YYYY, MM-DD, or MM-DD-YYYY.\"" ] }, { "cell_type": "code", "execution_count": 3, "id": "e37bce9e-9ba3-4b3c-b37b-35b36dbf7112", "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", " \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", " \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", "
geoidperiodconfirmed_ratedeath_rateconfirmed_rate_totaldeath_rate_totalvisitor_flows_to_selected_areavisitor_flows_from_selected_areapop_flows_to_selected_areapop_flows_from_selected_areaconfirmed_cases_totaldeath_totalcasesdeathpop
0250212020-03-0276.340.00000076.340.000000225932.0222941.04296827.04489797.01010131
1170312020-03-020.270.0000001.880.0000002410769.02203579.034150598.031518502.0701037172
260952020-03-020.120.0000002.970.000000155015.0176145.02935064.03281805.02401080680
360752020-03-020.000.0000003.450.000000291306.0221035.05711711.04196901.0600017376
4120572020-03-027.160.00000014.330.000000943468.0855974.010914786.09880641.020101396
................................................
276123421092021-11-22261.530.00000057660.291214.84814427845.015230.0415693.0228453.0205044329303556
276124421072021-11-22134.072.18000022966.91532.71079140167.052320.0568134.0733340.0841141951491836624
276125271392021-11-2275.850.6224218641.9761.70863653778.075885.0725802.0979598.0971916948537112464
276126421212021-11-221559.3635.210000148385.313143.86317914101.015193.0196044.0202678.02949962531071988
27612790152021-11-2225.400.1200006932.50109.87520332688.043879.0502565.0641831.056217891206181092
\n", "

276128 rows × 15 columns

\n", "
" ], "text/plain": [ " geoid period confirmed_rate death_rate confirmed_rate_total \n", "0 25021 2020-03-02 76.34 0.000000 76.34 \\\n", "1 17031 2020-03-02 0.27 0.000000 1.88 \n", "2 6095 2020-03-02 0.12 0.000000 2.97 \n", "3 6075 2020-03-02 0.00 0.000000 3.45 \n", "4 12057 2020-03-02 7.16 0.000000 14.33 \n", "... ... ... ... ... ... \n", "276123 42109 2021-11-22 261.53 0.000000 57660.29 \n", "276124 42107 2021-11-22 134.07 2.180000 22966.91 \n", "276125 27139 2021-11-22 75.85 0.622421 8641.97 \n", "276126 42121 2021-11-22 1559.36 35.210000 148385.31 \n", "276127 9015 2021-11-22 25.40 0.120000 6932.50 \n", "\n", " death_rate_total visitor_flows_to_selected_area \n", "0 0.000000 225932.0 \\\n", "1 0.000000 2410769.0 \n", "2 0.000000 155015.0 \n", "3 0.000000 291306.0 \n", "4 0.000000 943468.0 \n", "... ... ... \n", "276123 1214.848144 27845.0 \n", "276124 532.710791 40167.0 \n", "276125 61.708636 53778.0 \n", "276126 3143.863179 14101.0 \n", "276127 109.875203 32688.0 \n", "\n", " visitor_flows_from_selected_area pop_flows_to_selected_area \n", "0 222941.0 4296827.0 \\\n", "1 2203579.0 34150598.0 \n", "2 176145.0 2935064.0 \n", "3 221035.0 5711711.0 \n", "4 855974.0 10914786.0 \n", "... ... ... \n", "276123 15230.0 415693.0 \n", "276124 52320.0 568134.0 \n", "276125 75885.0 725802.0 \n", "276126 15193.0 196044.0 \n", "276127 43879.0 502565.0 \n", "\n", " pop_flows_from_selected_area confirmed_cases_total death_total \n", "0 4489797.0 1 0 \\\n", "1 31518502.0 7 0 \n", "2 3281805.0 24 0 \n", "3 4196901.0 6 0 \n", "4 9880641.0 2 0 \n", "... ... ... ... \n", "276123 228453.0 20504 432 \n", "276124 733340.0 84114 1951 \n", "276125 979598.0 97191 694 \n", "276126 202678.0 29499 625 \n", "276127 641831.0 56217 891 \n", "\n", " cases death pop \n", "0 1 0 131 \n", "1 1 0 37172 \n", "2 1 0 80680 \n", "3 0 0 17376 \n", "4 1 0 1396 \n", "... ... ... ... \n", "276123 93 0 3556 \n", "276124 491 8 36624 \n", "276125 853 7 112464 \n", "276126 310 7 1988 \n", "276127 206 1 81092 \n", "\n", "[276128 rows x 15 columns]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "attributes = pd.read_csv(\"attributes/Covid_Rate_Mobility_US_2020_2021_weekly.csv\", dtype={'geoid': str} )\n", "attributes" ] }, { "cell_type": "markdown", "id": "6432a95e-76bb-499e-8ebc-8f5ecbdfd715", "metadata": { "tags": [] }, "source": [ "

\n", "### Set the parameters to create visualizations using Multiple Linked Charts (MLC)." ] }, { "cell_type": "markdown", "id": "439b454b-7b12-42e8-a8ef-57f90f4a4e05", "metadata": {}, "source": [ "The interface will include two choropleth maps, a chart displaying the top or bottom values of your selected variable, such as COVID-19 confirmed rates, within the geographic regions of your map, and multiple linked charts (MLC). The MLC feature allows users to click on any county to explore spatiotemporal patterns of selected variables, such as COVID-19 confirmed or death rates, across multiple time series charts.\n", "\n", "     Your result visualization would be similar to the image below.
\n", "     " ] }, { "cell_type": "markdown", "id": "ff54804b-f145-4e1f-83f9-7cb9e2e6197d", "metadata": {}, "source": [ "- Specifying the map center and zoom levels is optional in MLC([latitude, longitude], zoom level). When MLC() is called without these parameters, the map center and zoom levels are automatically adjusted." ] }, { "cell_type": "code", "execution_count": 4, "id": "1a747e83-51ba-45fa-b0a2-9dc6db4bd7ce", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "1b92439f355f423d936e24b44461420c", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(Tab(children=(VBox(children=(VBox(children=(HBox(children=(Text(value='attributes', description…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "MLC([38, -97], 4)" ] }, { "cell_type": "markdown", "id": "991a4dbe-8c5d-48a2-b20b-2fd64c08d55e", "metadata": { "tags": [] }, "source": [ "

\n", "### Set the parameters to create visualizations using Comparison Line Chart (CLC)." ] }, { "cell_type": "markdown", "id": "b11eee94-40e1-40a0-8796-aa2113aa229b", "metadata": { "tags": [] }, "source": [ "Configure the parameters to visualize your COVID-19 datasets using the Comparison Line Chart (CLC). The interface will include two choropleth maps, a chart displaying the top or bottom values of your selected variable, such as COVID-19 confirmed rates, within the geographic regions of your map, and the Comparison Line Chart (CLC). The CLC feature allows users to click on any county on the two choropleth maps to compare spatiotemporal patterns of selected variables, such as COVID-19 confirmed or death rates, in a single interactive line chart.\n", "\n", "     Your result visualization would be similar to the image below.
\n", "     " ] }, { "cell_type": "markdown", "id": "8dd2ef40-c5a7-4082-b835-ab88bd642056", "metadata": {}, "source": [ "- Specifying the map center and zoom levels is optional in CLC([latitude, longitude], zoom level). When CLC() is called without these parameters, the map center and zoom levels are automatically adjusted." ] }, { "cell_type": "code", "execution_count": 5, "id": "6fcbd279-ae86-4974-aaca-e60559157c45", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "dd24035628724b5c90241c7146a6b5ff", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(Tab(children=(VBox(children=(VBox(children=(HBox(children=(Text(value='attributes', description…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "CLC([38, -97], 4)" ] } ], "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.8.12" } }, "nbformat": 4, "nbformat_minor": 5 }