Created
August 25, 2023 16:00
-
-
Save knaaptime/d17b2d233c663aeec3e0e95487910560 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"id": "1e11c85e-61e7-43c5-a8d4-21af7358a495", | |
"metadata": { | |
"execution": { | |
"iopub.execute_input": "2023-08-25T15:58:52.630289Z", | |
"iopub.status.busy": "2023-08-25T15:58:52.629974Z", | |
"iopub.status.idle": "2023-08-25T15:58:53.266336Z", | |
"shell.execute_reply": "2023-08-25T15:58:53.265841Z", | |
"shell.execute_reply.started": "2023-08-25T15:58:52.630268Z" | |
}, | |
"tags": [] | |
}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"/var/folders/79/cknfb1sx2pv16rztkpg6wzlw0000gn/T/ipykernel_86490/600507547.py:8: FutureWarning: Currently, index_parts defaults to True, but in the future, it will default to False to be consistent with Pandas. Use `index_parts=True` to keep the current behavior and True/False to silence the warning.\n", | |
" liq = geopandas.read_file(geodatasets.get_path(\"geoda liquor_stores\")).explode().reset_index()\n" | |
] | |
} | |
], | |
"source": [ | |
"import geodatasets\n", | |
"import geopandas\n", | |
"import numpy\n", | |
"import pytest\n", | |
"import shapely\n", | |
"\n", | |
"\n", | |
"liq = geopandas.read_file(geodatasets.get_path(\"geoda liquor_stores\")).explode().reset_index()\n", | |
"liq['intID'] = liq.index.values + 1\n", | |
"liq['strID'] = liq.placeid\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"id": "38ceaed3-74d9-43a0-b060-6e6756917534", | |
"metadata": { | |
"execution": { | |
"iopub.execute_input": "2023-08-25T15:58:53.267958Z", | |
"iopub.status.busy": "2023-08-25T15:58:53.267784Z", | |
"iopub.status.idle": "2023-08-25T15:58:53.415041Z", | |
"shell.execute_reply": "2023-08-25T15:58:53.414063Z", | |
"shell.execute_reply.started": "2023-08-25T15:58:53.267947Z" | |
}, | |
"tags": [] | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"<Derived Projected CRS: PROJCS[\"Transverse_Mercator\",GEOGCS[\"GCS_GRS 1980( ...>\n", | |
"Name: Transverse_Mercator\n", | |
"Axis Info [cartesian]:\n", | |
"- [east]: Easting (US survey foot)\n", | |
"- [north]: Northing (US survey foot)\n", | |
"Area of Use:\n", | |
"- undefined\n", | |
"Coordinate Operation:\n", | |
"- name: unnamed\n", | |
"- method: Transverse Mercator\n", | |
"Datum: D_unknown\n", | |
"- Ellipsoid: GRS80\n", | |
"- Prime Meridian: Greenwich" | |
] | |
}, | |
"execution_count": 2, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"liq.crs" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"id": "e6a0f2f8-a4d7-44bc-9f4d-5756e2abba44", | |
"metadata": { | |
"execution": { | |
"iopub.execute_input": "2023-08-25T15:58:53.415932Z", | |
"iopub.status.busy": "2023-08-25T15:58:53.415811Z", | |
"iopub.status.idle": "2023-08-25T15:58:54.202710Z", | |
"shell.execute_reply": "2023-08-25T15:58:54.202056Z", | |
"shell.execute_reply.started": "2023-08-25T15:58:53.415923Z" | |
}, | |
"tags": [] | |
}, | |
"outputs": [], | |
"source": [ | |
"from libpysal.graph import Graph" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"id": "7e48d23d-28a6-4cdd-8304-a7180e13092f", | |
"metadata": { | |
"execution": { | |
"iopub.execute_input": "2023-08-25T15:58:54.204439Z", | |
"iopub.status.busy": "2023-08-25T15:58:54.204022Z", | |
"iopub.status.idle": "2023-08-25T15:58:54.216961Z", | |
"shell.execute_reply": "2023-08-25T15:58:54.216484Z", | |
"shell.execute_reply.started": "2023-08-25T15:58:54.204419Z" | |
}, | |
"tags": [] | |
}, | |
"outputs": [], | |
"source": [ | |
"liq = liq.sort_values('placeid').set_index('placeid')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"id": "1bb2cdd3-768e-42e8-9f19-19f06bf2ed94", | |
"metadata": { | |
"execution": { | |
"iopub.execute_input": "2023-08-25T15:58:54.217689Z", | |
"iopub.status.busy": "2023-08-25T15:58:54.217554Z", | |
"iopub.status.idle": "2023-08-25T15:58:54.228258Z", | |
"shell.execute_reply": "2023-08-25T15:58:54.227827Z", | |
"shell.execute_reply.started": "2023-08-25T15:58:54.217679Z" | |
}, | |
"tags": [] | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>level_0</th>\n", | |
" <th>level_1</th>\n", | |
" <th>id</th>\n", | |
" <th>geometry</th>\n", | |
" <th>intID</th>\n", | |
" <th>strID</th>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>placeid</th>\n", | |
" <th></th>\n", | |
" <th></th>\n", | |
" <th></th>\n", | |
" <th></th>\n", | |
" <th></th>\n", | |
" <th></th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>ChIJ-0QKQWzJD4gRe1U3ezWmfQs</th>\n", | |
" <td>506</td>\n", | |
" <td>0</td>\n", | |
" <td>802</td>\n", | |
" <td>POINT (1128536.653 1941110.538)</td>\n", | |
" <td>507</td>\n", | |
" <td>ChIJ-0QKQWzJD4gRe1U3ezWmfQs</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJ-1OEIf_LD4gRDYFUeNKgUOk</th>\n", | |
" <td>345</td>\n", | |
" <td>0</td>\n", | |
" <td>548</td>\n", | |
" <td>POINT (1135119.550 1933498.360)</td>\n", | |
" <td>346</td>\n", | |
" <td>ChIJ-1OEIf_LD4gRDYFUeNKgUOk</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJ-1wybl3OD4gR-urBcDiFAHM</th>\n", | |
" <td>162</td>\n", | |
" <td>0</td>\n", | |
" <td>241</td>\n", | |
" <td>POINT (1148514.059 1942110.631)</td>\n", | |
" <td>163</td>\n", | |
" <td>ChIJ-1wybl3OD4gR-urBcDiFAHM</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJ-2qpdNYwDogRqiQGkV4hh1o</th>\n", | |
" <td>482</td>\n", | |
" <td>0</td>\n", | |
" <td>758</td>\n", | |
" <td>POINT (1137611.945 1862042.572)</td>\n", | |
" <td>483</td>\n", | |
" <td>ChIJ-2qpdNYwDogRqiQGkV4hh1o</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJ-70fxe0nDogR8D_7ejum_eg</th>\n", | |
" <td>472</td>\n", | |
" <td>0</td>\n", | |
" <td>739</td>\n", | |
" <td>POINT (1197782.798 1841163.151)</td>\n", | |
" <td>473</td>\n", | |
" <td>ChIJ-70fxe0nDogR8D_7ejum_eg</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" level_0 level_1 id \\\n", | |
"placeid \n", | |
"ChIJ-0QKQWzJD4gRe1U3ezWmfQs 506 0 802 \n", | |
"ChIJ-1OEIf_LD4gRDYFUeNKgUOk 345 0 548 \n", | |
"ChIJ-1wybl3OD4gR-urBcDiFAHM 162 0 241 \n", | |
"ChIJ-2qpdNYwDogRqiQGkV4hh1o 482 0 758 \n", | |
"ChIJ-70fxe0nDogR8D_7ejum_eg 472 0 739 \n", | |
"\n", | |
" geometry intID \\\n", | |
"placeid \n", | |
"ChIJ-0QKQWzJD4gRe1U3ezWmfQs POINT (1128536.653 1941110.538) 507 \n", | |
"ChIJ-1OEIf_LD4gRDYFUeNKgUOk POINT (1135119.550 1933498.360) 346 \n", | |
"ChIJ-1wybl3OD4gR-urBcDiFAHM POINT (1148514.059 1942110.631) 163 \n", | |
"ChIJ-2qpdNYwDogRqiQGkV4hh1o POINT (1137611.945 1862042.572) 483 \n", | |
"ChIJ-70fxe0nDogR8D_7ejum_eg POINT (1197782.798 1841163.151) 473 \n", | |
"\n", | |
" strID \n", | |
"placeid \n", | |
"ChIJ-0QKQWzJD4gRe1U3ezWmfQs ChIJ-0QKQWzJD4gRe1U3ezWmfQs \n", | |
"ChIJ-1OEIf_LD4gRDYFUeNKgUOk ChIJ-1OEIf_LD4gRDYFUeNKgUOk \n", | |
"ChIJ-1wybl3OD4gR-urBcDiFAHM ChIJ-1wybl3OD4gR-urBcDiFAHM \n", | |
"ChIJ-2qpdNYwDogRqiQGkV4hh1o ChIJ-2qpdNYwDogRqiQGkV4hh1o \n", | |
"ChIJ-70fxe0nDogR8D_7ejum_eg ChIJ-70fxe0nDogR8D_7ejum_eg " | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"liq.head()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"id": "7f40ba00-0f80-42b8-94b2-79568b463fb2", | |
"metadata": { | |
"execution": { | |
"iopub.execute_input": "2023-08-25T15:58:54.228903Z", | |
"iopub.status.busy": "2023-08-25T15:58:54.228783Z", | |
"iopub.status.idle": "2023-08-25T15:58:54.243571Z", | |
"shell.execute_reply": "2023-08-25T15:58:54.242890Z", | |
"shell.execute_reply.started": "2023-08-25T15:58:54.228893Z" | |
}, | |
"tags": [] | |
}, | |
"outputs": [], | |
"source": [ | |
"w_with_isos = Graph.build_distance_band(liq, threshold=2000)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"id": "2ee710ab-0f7d-433c-9c7d-cc51ffa89764", | |
"metadata": { | |
"execution": { | |
"iopub.execute_input": "2023-08-25T15:58:54.247741Z", | |
"iopub.status.busy": "2023-08-25T15:58:54.247494Z", | |
"iopub.status.idle": "2023-08-25T15:58:54.252629Z", | |
"shell.execute_reply": "2023-08-25T15:58:54.251902Z", | |
"shell.execute_reply.started": "2023-08-25T15:58:54.247726Z" | |
}, | |
"tags": [] | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"Index(['ChIJ-0QKQWzJD4gRe1U3ezWmfQs', 'ChIJ-1OEIf_LD4gRDYFUeNKgUOk',\n", | |
" 'ChIJ-1wybl3OD4gR-urBcDiFAHM', 'ChIJ-2qpdNYwDogRqiQGkV4hh1o',\n", | |
" 'ChIJ-70fxe0nDogR8D_7ejum_eg', 'ChIJ-w6hcAXLD4gRvplWx5DHhlQ',\n", | |
" 'ChIJ03AYs6YxDogRbkQJ9ZjdPco', 'ChIJ0x8oEnLMD4gRmWwQHHdCa0E',\n", | |
" 'ChIJ18rtoXIoDogRpa6EmkKJ128', 'ChIJ307q9KwuDogRFU6YPNlneIU',\n", | |
" ...\n", | |
" 'ChIJsyj0954tDogRo7WzfK0_n1g', 'ChIJt5KZV60xDogRLylc2EppTEY',\n", | |
" 'ChIJv5vzGIrLD4gRx8IYhemnDRo', 'ChIJvZIjgyYpDogRKEXyA0DIWqY',\n", | |
" 'ChIJvwAIMD8vDogRLQdZCI2iJBs', 'ChIJwYJyjSk3DogRckmY6uMzBkk',\n", | |
" 'ChIJyTmNDjbND4gRnMNszkNXBoM', 'ChIJyeKq5ewuDogREo4_IyRcJ5Q',\n", | |
" 'ChIJz0hnPZQyDogR2r4rR1j_0M4', 'ChIJzb37GXIpDogRD2izg17RYhg'],\n", | |
" dtype='object', name='focal', length=113)" | |
] | |
}, | |
"execution_count": 7, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"w_with_isos.isolates" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"id": "c584cdba-5017-4597-8fd2-9f8477b0b2b4", | |
"metadata": { | |
"execution": { | |
"iopub.execute_input": "2023-08-25T15:58:54.253881Z", | |
"iopub.status.busy": "2023-08-25T15:58:54.253741Z", | |
"iopub.status.idle": "2023-08-25T15:58:54.585640Z", | |
"shell.execute_reply": "2023-08-25T15:58:54.585079Z", | |
"shell.execute_reply.started": "2023-08-25T15:58:54.253868Z" | |
}, | |
"tags": [] | |
}, | |
"outputs": [], | |
"source": [ | |
"w_without_isos = Graph.build_knn(liq, k=5)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"id": "27515b11-c085-4fb9-b7cb-3daa27b77843", | |
"metadata": { | |
"execution": { | |
"iopub.execute_input": "2023-08-25T15:58:54.586512Z", | |
"iopub.status.busy": "2023-08-25T15:58:54.586305Z", | |
"iopub.status.idle": "2023-08-25T15:58:54.594385Z", | |
"shell.execute_reply": "2023-08-25T15:58:54.593699Z", | |
"shell.execute_reply.started": "2023-08-25T15:58:54.586500Z" | |
}, | |
"tags": [] | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"Index([], dtype='object', name='focal')" | |
] | |
}, | |
"execution_count": 9, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"w_without_isos.isolates" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"id": "f5e8cdda-580f-4885-a472-7d2b087b627d", | |
"metadata": { | |
"execution": { | |
"iopub.execute_input": "2023-08-25T15:58:54.596209Z", | |
"iopub.status.busy": "2023-08-25T15:58:54.595900Z", | |
"iopub.status.idle": "2023-08-25T15:58:54.603953Z", | |
"shell.execute_reply": "2023-08-25T15:58:54.603160Z", | |
"shell.execute_reply.started": "2023-08-25T15:58:54.596190Z" | |
}, | |
"tags": [] | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>neighbor</th>\n", | |
" <th>weight</th>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>focal</th>\n", | |
" <th></th>\n", | |
" <th></th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>ChIJ-0QKQWzJD4gRe1U3ezWmfQs</th>\n", | |
" <td>ChIJ-0QKQWzJD4gRe1U3ezWmfQs</td>\n", | |
" <td>0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJ-1OEIf_LD4gRDYFUeNKgUOk</th>\n", | |
" <td>ChIJ-1OEIf_LD4gRDYFUeNKgUOk</td>\n", | |
" <td>0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJ-1wybl3OD4gR-urBcDiFAHM</th>\n", | |
" <td>ChIJ-1wybl3OD4gR-urBcDiFAHM</td>\n", | |
" <td>0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJ-2qpdNYwDogRqiQGkV4hh1o</th>\n", | |
" <td>ChIJ-2qpdNYwDogRqiQGkV4hh1o</td>\n", | |
" <td>0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJ-70fxe0nDogR8D_7ejum_eg</th>\n", | |
" <td>ChIJ-70fxe0nDogR8D_7ejum_eg</td>\n", | |
" <td>0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>...</th>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJzR6nQgXSD4gRmTwu5InSYPg</th>\n", | |
" <td>ChIJ-aCcig_SD4gRgbEENEsCDrk</td>\n", | |
" <td>1</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJzb37GXIpDogRD2izg17RYhg</th>\n", | |
" <td>ChIJzb37GXIpDogRD2izg17RYhg</td>\n", | |
" <td>0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJzcg3nN3SD4gReo--4FAHoV4</th>\n", | |
" <td>ChIJaaOQRebSD4gRbdAAnxuL8SA</td>\n", | |
" <td>1</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJzcg3nN3SD4gReo--4FAHoV4</th>\n", | |
" <td>ChIJv6kU2-fSD4gRdTbuPbN8mNg</td>\n", | |
" <td>1</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJzcg3nN3SD4gReo--4FAHoV4</th>\n", | |
" <td>ChIJd5udnlXAD4gRkc5MhMAbEkY</td>\n", | |
" <td>1</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>1935 rows × 2 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" neighbor weight\n", | |
"focal \n", | |
"ChIJ-0QKQWzJD4gRe1U3ezWmfQs ChIJ-0QKQWzJD4gRe1U3ezWmfQs 0\n", | |
"ChIJ-1OEIf_LD4gRDYFUeNKgUOk ChIJ-1OEIf_LD4gRDYFUeNKgUOk 0\n", | |
"ChIJ-1wybl3OD4gR-urBcDiFAHM ChIJ-1wybl3OD4gR-urBcDiFAHM 0\n", | |
"ChIJ-2qpdNYwDogRqiQGkV4hh1o ChIJ-2qpdNYwDogRqiQGkV4hh1o 0\n", | |
"ChIJ-70fxe0nDogR8D_7ejum_eg ChIJ-70fxe0nDogR8D_7ejum_eg 0\n", | |
"... ... ...\n", | |
"ChIJzR6nQgXSD4gRmTwu5InSYPg ChIJ-aCcig_SD4gRgbEENEsCDrk 1\n", | |
"ChIJzb37GXIpDogRD2izg17RYhg ChIJzb37GXIpDogRD2izg17RYhg 0\n", | |
"ChIJzcg3nN3SD4gReo--4FAHoV4 ChIJaaOQRebSD4gRbdAAnxuL8SA 1\n", | |
"ChIJzcg3nN3SD4gReo--4FAHoV4 ChIJv6kU2-fSD4gRdTbuPbN8mNg 1\n", | |
"ChIJzcg3nN3SD4gReo--4FAHoV4 ChIJd5udnlXAD4gRkc5MhMAbEkY 1\n", | |
"\n", | |
"[1935 rows x 2 columns]" | |
] | |
}, | |
"execution_count": 10, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"w_with_isos.adjacency" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"id": "1a895852-88c4-486e-9b27-ae1c27e2a131", | |
"metadata": { | |
"execution": { | |
"iopub.execute_input": "2023-08-25T15:58:54.606443Z", | |
"iopub.status.busy": "2023-08-25T15:58:54.606027Z", | |
"iopub.status.idle": "2023-08-25T15:58:54.619377Z", | |
"shell.execute_reply": "2023-08-25T15:58:54.618983Z", | |
"shell.execute_reply.started": "2023-08-25T15:58:54.606338Z" | |
}, | |
"tags": [] | |
}, | |
"outputs": [], | |
"source": [ | |
"sparse_g_with_isos = Graph.from_sparse(w_with_isos.sparse, liq.index.values)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 12, | |
"id": "821c0981-a2e1-4647-98c0-5b6484419ac8", | |
"metadata": { | |
"execution": { | |
"iopub.execute_input": "2023-08-25T15:58:54.619984Z", | |
"iopub.status.busy": "2023-08-25T15:58:54.619897Z", | |
"iopub.status.idle": "2023-08-25T15:58:54.627423Z", | |
"shell.execute_reply": "2023-08-25T15:58:54.626897Z", | |
"shell.execute_reply.started": "2023-08-25T15:58:54.619975Z" | |
}, | |
"tags": [] | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>neighbor</th>\n", | |
" <th>weight</th>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>focal</th>\n", | |
" <th></th>\n", | |
" <th></th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>ChIJ-0QKQWzJD4gRe1U3ezWmfQs</th>\n", | |
" <td>True</td>\n", | |
" <td>True</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJ-1OEIf_LD4gRDYFUeNKgUOk</th>\n", | |
" <td>True</td>\n", | |
" <td>True</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJ-1wybl3OD4gR-urBcDiFAHM</th>\n", | |
" <td>True</td>\n", | |
" <td>True</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJ-2qpdNYwDogRqiQGkV4hh1o</th>\n", | |
" <td>True</td>\n", | |
" <td>True</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJ-70fxe0nDogR8D_7ejum_eg</th>\n", | |
" <td>True</td>\n", | |
" <td>True</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>...</th>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJzR6nQgXSD4gRmTwu5InSYPg</th>\n", | |
" <td>False</td>\n", | |
" <td>True</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJzb37GXIpDogRD2izg17RYhg</th>\n", | |
" <td>True</td>\n", | |
" <td>True</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJzcg3nN3SD4gReo--4FAHoV4</th>\n", | |
" <td>False</td>\n", | |
" <td>True</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJzcg3nN3SD4gReo--4FAHoV4</th>\n", | |
" <td>False</td>\n", | |
" <td>True</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJzcg3nN3SD4gReo--4FAHoV4</th>\n", | |
" <td>True</td>\n", | |
" <td>True</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>1935 rows × 2 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" neighbor weight\n", | |
"focal \n", | |
"ChIJ-0QKQWzJD4gRe1U3ezWmfQs True True\n", | |
"ChIJ-1OEIf_LD4gRDYFUeNKgUOk True True\n", | |
"ChIJ-1wybl3OD4gR-urBcDiFAHM True True\n", | |
"ChIJ-2qpdNYwDogRqiQGkV4hh1o True True\n", | |
"ChIJ-70fxe0nDogR8D_7ejum_eg True True\n", | |
"... ... ...\n", | |
"ChIJzR6nQgXSD4gRmTwu5InSYPg False True\n", | |
"ChIJzb37GXIpDogRD2izg17RYhg True True\n", | |
"ChIJzcg3nN3SD4gReo--4FAHoV4 False True\n", | |
"ChIJzcg3nN3SD4gReo--4FAHoV4 False True\n", | |
"ChIJzcg3nN3SD4gReo--4FAHoV4 True True\n", | |
"\n", | |
"[1935 rows x 2 columns]" | |
] | |
}, | |
"execution_count": 12, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"sparse_g_with_isos.adjacency == w_with_isos.adjacency" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 13, | |
"id": "7c89cf1c-d293-4a17-b3e4-93e98ef3468b", | |
"metadata": { | |
"execution": { | |
"iopub.execute_input": "2023-08-25T15:58:54.628311Z", | |
"iopub.status.busy": "2023-08-25T15:58:54.628084Z", | |
"iopub.status.idle": "2023-08-25T15:58:54.642501Z", | |
"shell.execute_reply": "2023-08-25T15:58:54.642025Z", | |
"shell.execute_reply.started": "2023-08-25T15:58:54.628290Z" | |
}, | |
"tags": [] | |
}, | |
"outputs": [], | |
"source": [ | |
"sparse_g_without_isos = Graph.from_sparse(w_without_isos.sparse, liq.index.values)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"id": "40fc062c-a5a2-40a6-986c-c5c516478b1a", | |
"metadata": { | |
"execution": { | |
"iopub.execute_input": "2023-08-25T15:58:54.643281Z", | |
"iopub.status.busy": "2023-08-25T15:58:54.643124Z", | |
"iopub.status.idle": "2023-08-25T15:58:54.649768Z", | |
"shell.execute_reply": "2023-08-25T15:58:54.648828Z", | |
"shell.execute_reply.started": "2023-08-25T15:58:54.643269Z" | |
}, | |
"tags": [] | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>neighbor</th>\n", | |
" <th>weight</th>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>focal</th>\n", | |
" <th></th>\n", | |
" <th></th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>ChIJ-0QKQWzJD4gRe1U3ezWmfQs</th>\n", | |
" <td>ChIJNZ4sJ1HJD4gRPk9rj1L1R50</td>\n", | |
" <td>1</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJ-0QKQWzJD4gRe1U3ezWmfQs</th>\n", | |
" <td>ChIJYedBUDcuDogRyUGOfOJBe_o</td>\n", | |
" <td>1</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJ-0QKQWzJD4gRe1U3ezWmfQs</th>\n", | |
" <td>ChIJNYa7SqfJD4gRJ7u1fNSoutk</td>\n", | |
" <td>1</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJ-0QKQWzJD4gRe1U3ezWmfQs</th>\n", | |
" <td>ChIJmTqTRfzRD4gRW86Yd1wsBvQ</td>\n", | |
" <td>1</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJ-0QKQWzJD4gRe1U3ezWmfQs</th>\n", | |
" <td>ChIJeRishgLMD4gRAV62Pe_diS8</td>\n", | |
" <td>1</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>...</th>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJz0hnPZQyDogR2r4rR1j_0M4</th>\n", | |
" <td>ChIJaYqsbtDND4gRoju1ga49yVA</td>\n", | |
" <td>1</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJz0hnPZQyDogR2r4rR1j_0M4</th>\n", | |
" <td>ChIJubIDU1gsDogRQLRiqkhBR6g</td>\n", | |
" <td>1</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJz0hnPZQyDogR2r4rR1j_0M4</th>\n", | |
" <td>ChIJxVWybJzMD4gRHzgya78Gelw</td>\n", | |
" <td>1</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJz0hnPZQyDogR2r4rR1j_0M4</th>\n", | |
" <td>ChIJEbKjAsTSD4gR7RjgP80Z7ak</td>\n", | |
" <td>1</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>ChIJz0hnPZQyDogR2r4rR1j_0M4</th>\n", | |
" <td>ChIJd5KysUAoDogRzhRxm4k3T5I</td>\n", | |
" <td>1</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>2835 rows × 2 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" neighbor weight\n", | |
"focal \n", | |
"ChIJ-0QKQWzJD4gRe1U3ezWmfQs ChIJNZ4sJ1HJD4gRPk9rj1L1R50 1\n", | |
"ChIJ-0QKQWzJD4gRe1U3ezWmfQs ChIJYedBUDcuDogRyUGOfOJBe_o 1\n", | |
"ChIJ-0QKQWzJD4gRe1U3ezWmfQs ChIJNYa7SqfJD4gRJ7u1fNSoutk 1\n", | |
"ChIJ-0QKQWzJD4gRe1U3ezWmfQs ChIJmTqTRfzRD4gRW86Yd1wsBvQ 1\n", | |
"ChIJ-0QKQWzJD4gRe1U3ezWmfQs ChIJeRishgLMD4gRAV62Pe_diS8 1\n", | |
"... ... ...\n", | |
"ChIJz0hnPZQyDogR2r4rR1j_0M4 ChIJaYqsbtDND4gRoju1ga49yVA 1\n", | |
"ChIJz0hnPZQyDogR2r4rR1j_0M4 ChIJubIDU1gsDogRQLRiqkhBR6g 1\n", | |
"ChIJz0hnPZQyDogR2r4rR1j_0M4 ChIJxVWybJzMD4gRHzgya78Gelw 1\n", | |
"ChIJz0hnPZQyDogR2r4rR1j_0M4 ChIJEbKjAsTSD4gR7RjgP80Z7ak 1\n", | |
"ChIJz0hnPZQyDogR2r4rR1j_0M4 ChIJd5KysUAoDogRzhRxm4k3T5I 1\n", | |
"\n", | |
"[2835 rows x 2 columns]" | |
] | |
}, | |
"execution_count": 14, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"sparse_g_without_isos.adjacency" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"id": "dc9ba700-5e19-4c2f-9e26-ae7d6b81ac81", | |
"metadata": { | |
"execution": { | |
"iopub.execute_input": "2023-08-25T15:58:54.650426Z", | |
"iopub.status.busy": "2023-08-25T15:58:54.650321Z", | |
"iopub.status.idle": "2023-08-25T15:58:54.665801Z", | |
"shell.execute_reply": "2023-08-25T15:58:54.665343Z", | |
"shell.execute_reply.started": "2023-08-25T15:58:54.650416Z" | |
}, | |
"tags": [] | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"False" | |
] | |
}, | |
"execution_count": 15, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"sparse_g_without_isos == w_without_isos" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 16, | |
"id": "90e585fa-395b-4bbe-903b-92bf142dd8df", | |
"metadata": { | |
"execution": { | |
"iopub.execute_input": "2023-08-25T15:58:54.666645Z", | |
"iopub.status.busy": "2023-08-25T15:58:54.666523Z", | |
"iopub.status.idle": "2023-08-25T15:58:54.670077Z", | |
"shell.execute_reply": "2023-08-25T15:58:54.669712Z", | |
"shell.execute_reply.started": "2023-08-25T15:58:54.666636Z" | |
}, | |
"tags": [] | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"Index(['ChIJ-0QKQWzJD4gRe1U3ezWmfQs', 'ChIJ-0QKQWzJD4gRe1U3ezWmfQs',\n", | |
" 'ChIJ-0QKQWzJD4gRe1U3ezWmfQs', 'ChIJ-0QKQWzJD4gRe1U3ezWmfQs',\n", | |
" 'ChIJ-0QKQWzJD4gRe1U3ezWmfQs', 'ChIJ-1OEIf_LD4gRDYFUeNKgUOk',\n", | |
" 'ChIJ-1OEIf_LD4gRDYFUeNKgUOk', 'ChIJ-1OEIf_LD4gRDYFUeNKgUOk',\n", | |
" 'ChIJ-1OEIf_LD4gRDYFUeNKgUOk', 'ChIJ-1OEIf_LD4gRDYFUeNKgUOk',\n", | |
" ...\n", | |
" 'ChIJzb37GXIpDogRD2izg17RYhg', 'ChIJzb37GXIpDogRD2izg17RYhg',\n", | |
" 'ChIJzb37GXIpDogRD2izg17RYhg', 'ChIJzb37GXIpDogRD2izg17RYhg',\n", | |
" 'ChIJzb37GXIpDogRD2izg17RYhg', 'ChIJzcg3nN3SD4gReo--4FAHoV4',\n", | |
" 'ChIJzcg3nN3SD4gReo--4FAHoV4', 'ChIJzcg3nN3SD4gReo--4FAHoV4',\n", | |
" 'ChIJzcg3nN3SD4gReo--4FAHoV4', 'ChIJzcg3nN3SD4gReo--4FAHoV4'],\n", | |
" dtype='object', name='focal', length=2835)" | |
] | |
}, | |
"execution_count": 16, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
" w_without_isos.adjacency.index" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 18, | |
"id": "cfe1e32b-608c-4301-8d25-21daa2a14d2d", | |
"metadata": { | |
"execution": { | |
"iopub.execute_input": "2023-08-25T15:59:00.346947Z", | |
"iopub.status.busy": "2023-08-25T15:59:00.346394Z", | |
"iopub.status.idle": "2023-08-25T15:59:00.361961Z", | |
"shell.execute_reply": "2023-08-25T15:59:00.361329Z", | |
"shell.execute_reply.started": "2023-08-25T15:59:00.346920Z" | |
}, | |
"tags": [] | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"<571x571 sparse array of type '<class 'numpy.int64'>'\n", | |
"\twith 1935 stored elements in COOrdinate format>" | |
] | |
}, | |
"execution_count": 18, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"w_with_isos.sparse" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 19, | |
"id": "460ae65c-70f2-469e-b4bc-9b08531c6234", | |
"metadata": { | |
"execution": { | |
"iopub.execute_input": "2023-08-25T15:59:00.593926Z", | |
"iopub.status.busy": "2023-08-25T15:59:00.593494Z", | |
"iopub.status.idle": "2023-08-25T15:59:00.612791Z", | |
"shell.execute_reply": "2023-08-25T15:59:00.611488Z", | |
"shell.execute_reply.started": "2023-08-25T15:59:00.593899Z" | |
}, | |
"tags": [] | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"Index(['ChIJ-0QKQWzJD4gRe1U3ezWmfQs', 'ChIJ-1OEIf_LD4gRDYFUeNKgUOk',\n", | |
" 'ChIJ-1wybl3OD4gR-urBcDiFAHM', 'ChIJ-2qpdNYwDogRqiQGkV4hh1o',\n", | |
" 'ChIJ-70fxe0nDogR8D_7ejum_eg', 'ChIJ-w6hcAXLD4gRvplWx5DHhlQ',\n", | |
" 'ChIJ03AYs6YxDogRbkQJ9ZjdPco', 'ChIJ0x8oEnLMD4gRmWwQHHdCa0E',\n", | |
" 'ChIJ18rtoXIoDogRpa6EmkKJ128', 'ChIJ307q9KwuDogRFU6YPNlneIU',\n", | |
" ...\n", | |
" 'ChIJsyj0954tDogRo7WzfK0_n1g', 'ChIJt5KZV60xDogRLylc2EppTEY',\n", | |
" 'ChIJv5vzGIrLD4gRx8IYhemnDRo', 'ChIJvZIjgyYpDogRKEXyA0DIWqY',\n", | |
" 'ChIJvwAIMD8vDogRLQdZCI2iJBs', 'ChIJwYJyjSk3DogRckmY6uMzBkk',\n", | |
" 'ChIJyTmNDjbND4gRnMNszkNXBoM', 'ChIJyeKq5ewuDogREo4_IyRcJ5Q',\n", | |
" 'ChIJz0hnPZQyDogR2r4rR1j_0M4', 'ChIJzb37GXIpDogRD2izg17RYhg'],\n", | |
" dtype='object', name='focal', length=113)" | |
] | |
}, | |
"execution_count": 19, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"w_with_isos.isolates" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "65434c0a-59e7-4b52-81b8-35a847532fa6", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python [conda env:libpysal]", | |
"language": "python", | |
"name": "conda-env-libpysal-py" | |
}, | |
"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.8" | |
}, | |
"widgets": { | |
"application/vnd.jupyter.widget-state+json": { | |
"state": {}, | |
"version_major": 2, | |
"version_minor": 0 | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment