|
33 | 33 | "import shapely\n",
|
34 | 34 | "from palettable.colorbrewer.diverging import BrBG_10\n",
|
35 | 35 | "\n",
|
36 |
| - "from lonboard import ScatterplotLayer\n", |
| 36 | + "from lonboard import ScatterplotLayer, viz\n", |
37 | 37 | "from lonboard.colormap import apply_continuous_cmap"
|
38 | 38 | ]
|
39 | 39 | },
|
|
211 | 211 | },
|
212 | 212 | {
|
213 | 213 | "cell_type": "markdown",
|
214 |
| - "id": "63537833-887d-4d40-acd2-8e212dc0412c", |
| 214 | + "id": "65436a4a-c498-4f40-ba79-1082062376bf", |
215 | 215 | "metadata": {},
|
216 | 216 | "source": [
|
217 |
| - "This is all we need to get data onto the map! Let's render a simple `ScatterplotLayer`, drawing each point as blue:" |
| 217 | + "To ensure that this demo is snappy on most computers, we'll filter to a bounding box over Europe." |
218 | 218 | ]
|
219 | 219 | },
|
220 | 220 | {
|
221 | 221 | "cell_type": "code",
|
222 | 222 | "execution_count": 8,
|
223 |
| - "id": "498d466e-0f9f-497a-b4b7-8e274dffd9cf", |
| 223 | + "id": "80326895-70ba-4f4b-a7b3-106b4bbd36d9", |
| 224 | + "metadata": {}, |
| 225 | + "outputs": [], |
| 226 | + "source": [ |
| 227 | + "gdf = gdf.cx[-11.83:25.5, 34.9:59]" |
| 228 | + ] |
| 229 | + }, |
| 230 | + { |
| 231 | + "cell_type": "markdown", |
| 232 | + "id": "3cc2215e-7706-4ab3-b674-3de4ca41899c", |
| 233 | + "metadata": {}, |
| 234 | + "source": [ |
| 235 | + "Even this filtered data frame still has 800,000 rows, so it's still a lot of data to explore:" |
| 236 | + ] |
| 237 | + }, |
| 238 | + { |
| 239 | + "cell_type": "code", |
| 240 | + "execution_count": 9, |
| 241 | + "id": "a34a6a27-0259-4da9-94c4-923466da05fb", |
| 242 | + "metadata": {}, |
| 243 | + "outputs": [ |
| 244 | + { |
| 245 | + "data": { |
| 246 | + "text/html": [ |
| 247 | + "<div>\n", |
| 248 | + "<style scoped>\n", |
| 249 | + " .dataframe tbody tr th:only-of-type {\n", |
| 250 | + " vertical-align: middle;\n", |
| 251 | + " }\n", |
| 252 | + "\n", |
| 253 | + " .dataframe tbody tr th {\n", |
| 254 | + " vertical-align: top;\n", |
| 255 | + " }\n", |
| 256 | + "\n", |
| 257 | + " .dataframe thead th {\n", |
| 258 | + " text-align: right;\n", |
| 259 | + " }\n", |
| 260 | + "</style>\n", |
| 261 | + "<table border=\"1\" class=\"dataframe\">\n", |
| 262 | + " <thead>\n", |
| 263 | + " <tr style=\"text-align: right;\">\n", |
| 264 | + " <th></th>\n", |
| 265 | + " <th>avg_d_kbps</th>\n", |
| 266 | + " <th>geometry</th>\n", |
| 267 | + " </tr>\n", |
| 268 | + " </thead>\n", |
| 269 | + " <tbody>\n", |
| 270 | + " <tr>\n", |
| 271 | + " <th>383429</th>\n", |
| 272 | + " <td>13570</td>\n", |
| 273 | + " <td>POINT (-2.94159 58.99673)</td>\n", |
| 274 | + " </tr>\n", |
| 275 | + " <tr>\n", |
| 276 | + " <th>383430</th>\n", |
| 277 | + " <td>18108</td>\n", |
| 278 | + " <td>POINT (-3.29865 58.96276)</td>\n", |
| 279 | + " </tr>\n", |
| 280 | + " <tr>\n", |
| 281 | + " <th>383431</th>\n", |
| 282 | + " <td>5569</td>\n", |
| 283 | + " <td>POINT (-3.29315 58.97125)</td>\n", |
| 284 | + " </tr>\n", |
| 285 | + " <tr>\n", |
| 286 | + " <th>383432</th>\n", |
| 287 | + " <td>9349</td>\n", |
| 288 | + " <td>POINT (-3.29315 58.96842)</td>\n", |
| 289 | + " </tr>\n", |
| 290 | + " <tr>\n", |
| 291 | + " <th>383433</th>\n", |
| 292 | + " <td>11216</td>\n", |
| 293 | + " <td>POINT (-3.23273 58.98541)</td>\n", |
| 294 | + " </tr>\n", |
| 295 | + " <tr>\n", |
| 296 | + " <th>...</th>\n", |
| 297 | + " <td>...</td>\n", |
| 298 | + " <td>...</td>\n", |
| 299 | + " </tr>\n", |
| 300 | + " <tr>\n", |
| 301 | + " <th>1840929</th>\n", |
| 302 | + " <td>104723</td>\n", |
| 303 | + " <td>POINT (25.38666 35.09519)</td>\n", |
| 304 | + " </tr>\n", |
| 305 | + " <tr>\n", |
| 306 | + " <th>1840930</th>\n", |
| 307 | + " <td>62540</td>\n", |
| 308 | + " <td>POINT (25.44708 35.04124)</td>\n", |
| 309 | + " </tr>\n", |
| 310 | + " <tr>\n", |
| 311 | + " <th>1840931</th>\n", |
| 312 | + " <td>88068</td>\n", |
| 313 | + " <td>POINT (25.47455 35.04124)</td>\n", |
| 314 | + " </tr>\n", |
| 315 | + " <tr>\n", |
| 316 | + " <th>1840938</th>\n", |
| 317 | + " <td>38255</td>\n", |
| 318 | + " <td>POINT (25.38116 35.00075)</td>\n", |
| 319 | + " </tr>\n", |
| 320 | + " <tr>\n", |
| 321 | + " <th>1840939</th>\n", |
| 322 | + " <td>91750</td>\n", |
| 323 | + " <td>POINT (25.45807 34.99175)</td>\n", |
| 324 | + " </tr>\n", |
| 325 | + " </tbody>\n", |
| 326 | + "</table>\n", |
| 327 | + "<p>807221 rows × 2 columns</p>\n", |
| 328 | + "</div>" |
| 329 | + ], |
| 330 | + "text/plain": [ |
| 331 | + " avg_d_kbps geometry\n", |
| 332 | + "383429 13570 POINT (-2.94159 58.99673)\n", |
| 333 | + "383430 18108 POINT (-3.29865 58.96276)\n", |
| 334 | + "383431 5569 POINT (-3.29315 58.97125)\n", |
| 335 | + "383432 9349 POINT (-3.29315 58.96842)\n", |
| 336 | + "383433 11216 POINT (-3.23273 58.98541)\n", |
| 337 | + "... ... ...\n", |
| 338 | + "1840929 104723 POINT (25.38666 35.09519)\n", |
| 339 | + "1840930 62540 POINT (25.44708 35.04124)\n", |
| 340 | + "1840931 88068 POINT (25.47455 35.04124)\n", |
| 341 | + "1840938 38255 POINT (25.38116 35.00075)\n", |
| 342 | + "1840939 91750 POINT (25.45807 34.99175)\n", |
| 343 | + "\n", |
| 344 | + "[807221 rows x 2 columns]" |
| 345 | + ] |
| 346 | + }, |
| 347 | + "execution_count": 9, |
| 348 | + "metadata": {}, |
| 349 | + "output_type": "execute_result" |
| 350 | + } |
| 351 | + ], |
| 352 | + "source": [ |
| 353 | + "gdf" |
| 354 | + ] |
| 355 | + }, |
| 356 | + { |
| 357 | + "cell_type": "markdown", |
| 358 | + "id": "81a61ec4-2a09-40c0-aa92-7dca570bbd49", |
| 359 | + "metadata": {}, |
| 360 | + "source": [ |
| 361 | + "The simplest way to get data on the map is to use `viz`:" |
| 362 | + ] |
| 363 | + }, |
| 364 | + { |
| 365 | + "cell_type": "code", |
| 366 | + "execution_count": 10, |
| 367 | + "id": "326f5f4e-a8f7-425b-8e9f-6744ba65cf62", |
224 | 368 | "metadata": {},
|
225 | 369 | "outputs": [
|
226 | 370 | {
|
227 | 371 | "data": {
|
228 | 372 | "application/vnd.jupyter.widget-view+json": {
|
229 |
| - "model_id": "bcbf7e3fa1bc4dc3ac46bbf3f97d48da", |
| 373 | + "model_id": "30ba30dd2b9f4d47b307fa98ea9bf896", |
230 | 374 | "version_major": 2,
|
231 | 375 | "version_minor": 0
|
232 | 376 | },
|
233 | 377 | "text/plain": [
|
234 |
| - "ScatterplotLayer(get_fill_color=[0, 0, 200, 30], table=pyarrow.Table\n", |
235 |
| - "geometry: fixed_size_list<item: double>[2…" |
| 378 | + "ScatterplotLayer(table=pyarrow.Table\n", |
| 379 | + "avg_d_kbps: int64\n", |
| 380 | + "__index_level_0__: int64\n", |
| 381 | + "geometry: fixed_size_list<item…" |
| 382 | + ] |
| 383 | + }, |
| 384 | + "execution_count": 10, |
| 385 | + "metadata": {}, |
| 386 | + "output_type": "execute_result" |
| 387 | + } |
| 388 | + ], |
| 389 | + "source": [ |
| 390 | + "map_ = viz(gdf)\n", |
| 391 | + "map_" |
| 392 | + ] |
| 393 | + }, |
| 394 | + { |
| 395 | + "cell_type": "markdown", |
| 396 | + "id": "91af2a88-9363-4c00-8e54-f06a635ff991", |
| 397 | + "metadata": {}, |
| 398 | + "source": [ |
| 399 | + "This map object is a `ScatterplotLayer` type. You could have created the same map by using\n", |
| 400 | + "```py\n", |
| 401 | + "map_ = lonboard.ScatterplotLayer.from_geopandas(gdf)\n", |
| 402 | + "```" |
| 403 | + ] |
| 404 | + }, |
| 405 | + { |
| 406 | + "cell_type": "code", |
| 407 | + "execution_count": 11, |
| 408 | + "id": "7d0f6f03-ca11-4842-8e53-4a619ad7d3dd", |
| 409 | + "metadata": {}, |
| 410 | + "outputs": [ |
| 411 | + { |
| 412 | + "data": { |
| 413 | + "text/plain": [ |
| 414 | + "lonboard.layer.ScatterplotLayer" |
236 | 415 | ]
|
237 | 416 | },
|
238 |
| - "execution_count": 8, |
| 417 | + "execution_count": 11, |
239 | 418 | "metadata": {},
|
240 | 419 | "output_type": "execute_result"
|
241 | 420 | }
|
242 | 421 | ],
|
243 | 422 | "source": [
|
244 |
| - "layer = ScatterplotLayer.from_geopandas(gdf[[\"geometry\"]], get_fill_color=[0, 0, 200, 30])\n", |
245 |
| - "layer" |
| 423 | + "type(map_)" |
| 424 | + ] |
| 425 | + }, |
| 426 | + { |
| 427 | + "cell_type": "markdown", |
| 428 | + "id": "6f4d89c3-282a-4beb-9f35-68eb9645e8c0", |
| 429 | + "metadata": {}, |
| 430 | + "source": [ |
| 431 | + "We can look at the [documentation for `ScatterplotLayer`](https://developmentseed.org/lonboard/api/layers/scatterplot-layer/) to see what other rendering options it allows. Let's set the fill color to something other than black:" |
| 432 | + ] |
| 433 | + }, |
| 434 | + { |
| 435 | + "cell_type": "code", |
| 436 | + "execution_count": 12, |
| 437 | + "id": "3912b241-577f-4ac3-b78f-2702e89d6010", |
| 438 | + "metadata": {}, |
| 439 | + "outputs": [], |
| 440 | + "source": [ |
| 441 | + "map_.get_fill_color = [0, 0, 200, 200]" |
246 | 442 | ]
|
247 | 443 | },
|
248 | 444 | {
|
|
258 | 454 | "id": "ce630455-3e19-47f1-bb69-81fdcd99b126",
|
259 | 455 | "metadata": {},
|
260 | 456 | "source": [
|
261 |
| - "Here we compute a linear statistic for the download speed. Given a minimum bound of `1000` and a maximum bound of `30,000` the normalized speed is linearly scaled to between 0 and 1." |
| 457 | + "Here we compute a linear statistic for the download speed. Given a minimum bound of `5000` and a maximum bound of `50,000` the normalized speed is linearly scaled to between 0 and 1." |
262 | 458 | ]
|
263 | 459 | },
|
264 | 460 | {
|
265 | 461 | "cell_type": "code",
|
266 |
| - "execution_count": 9, |
| 462 | + "execution_count": 13, |
267 | 463 | "id": "179071b3",
|
268 | 464 | "metadata": {},
|
269 | 465 | "outputs": [],
|
270 | 466 | "source": [
|
271 |
| - "min_bound = 1000\n", |
272 |
| - "max_bound = 30000\n", |
| 467 | + "min_bound = 5000\n", |
| 468 | + "max_bound = 50000\n", |
273 | 469 | "download_speed = gdf['avg_d_kbps']\n",
|
274 | 470 | "normalized_download_speed = (download_speed - min_bound) / (max_bound - min_bound)"
|
275 | 471 | ]
|
|
284 | 480 | },
|
285 | 481 | {
|
286 | 482 | "cell_type": "code",
|
287 |
| - "execution_count": 10, |
| 483 | + "execution_count": 14, |
288 | 484 | "id": "a8df3963-2bc2-4f89-8a38-20e232a13932",
|
289 | 485 | "metadata": {},
|
290 | 486 | "outputs": [
|
291 | 487 | {
|
292 | 488 | "data": {
|
293 | 489 | "text/plain": [
|
294 |
| - "0 0.171828\n", |
295 |
| - "1 0.094759\n", |
296 |
| - "2 0.081517\n", |
297 |
| - "3 0.047621\n", |
298 |
| - "4 0.070586\n", |
| 490 | + "383429 0.190444\n", |
| 491 | + "383430 0.291289\n", |
| 492 | + "383431 0.012644\n", |
| 493 | + "383432 0.096644\n", |
| 494 | + "383433 0.138133\n", |
299 | 495 | " ... \n",
|
300 |
| - "3231240 0.638897\n", |
301 |
| - "3231241 0.506655\n", |
302 |
| - "3231242 0.887828\n", |
303 |
| - "3231243 2.310172\n", |
304 |
| - "3231244 0.007931\n", |
305 |
| - "Name: avg_d_kbps, Length: 3231245, dtype: float64" |
| 496 | + "1840929 2.216067\n", |
| 497 | + "1840930 1.278667\n", |
| 498 | + "1840931 1.845956\n", |
| 499 | + "1840938 0.739000\n", |
| 500 | + "1840939 1.927778\n", |
| 501 | + "Name: avg_d_kbps, Length: 807221, dtype: float64" |
306 | 502 | ]
|
307 | 503 | },
|
308 |
| - "execution_count": 10, |
| 504 | + "execution_count": 14, |
309 | 505 | "metadata": {},
|
310 | 506 | "output_type": "execute_result"
|
311 | 507 | }
|
|
324 | 520 | },
|
325 | 521 | {
|
326 | 522 | "cell_type": "code",
|
327 |
| - "execution_count": 11, |
| 523 | + "execution_count": 15, |
328 | 524 | "id": "9d5347e2-84c7-40bc-af45-c8638188709e",
|
329 | 525 | "metadata": {},
|
330 | 526 | "outputs": [
|
|
335 | 531 | "<div style=\"vertical-align: middle;\"><strong>BrBG</strong> </div><div class=\"cmap\"><img alt=\"BrBG colormap\" title=\"BrBG\" style=\"border: 1px solid #555;\" src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAABACAYAAABsv8+/AAAAE3RFWHRUaXRsZQBCckJHIGNvbG9ybWFwMTXIUAAAABl0RVh0RGVzY3JpcHRpb24AQnJCRyBjb2xvcm1hcLqHWMgAAAAwdEVYdEF1dGhvcgBNYXRwbG90bGliIHYzLjcuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZ7rJ3hAAAAAydEVYdFNvZnR3YXJlAE1hdHBsb3RsaWIgdjMuNy4zLCBodHRwczovL21hdHBsb3RsaWIub3JnlG9BNwAAAilJREFUeJzt1k1u2zAURlGSQffTxXT/O7GYgSUHejahBPGgwHfOROWPKCYBitv//f0zW2ut99Zaa21cPu//GOPd+/t5/O7949h/39iP8WP+GI/TfO9l3yj79vXn88bL9/riO/Ueva4v7tHLd/rHx/7+6+d4rI/z+uq9sn8s18u5i/PG4tyrexz3bsffr5f3HvP7vnEer/a3Xu6x2N/K+V/7X8+3i++u7jn3v/Ns9+fWxv6s8+f15/lvnvPj7/32fne3Oe/j/XmbWxkf69ti/2/XV9970/q2nZ5bGd+2uZg/9pdzZj1nlv3fO/9p3/zhPco5x88763xZr/NzMb967+n8i/eX56/us1hv+++97b+Hr/GxPi/G/+n7+779fysAIIkAAIBAAgAAAgkAAAgkAAAgkAAAgEACAAACCQAACCQAACCQAACAQAIAAAIJAAAIJAAAIJAAAIBAAgAAAgkAAAgkAAAgkAAAgEACAAACCQAACCQAACCQAACAQAIAAAIJAAAIJAAAIJAAAIBAAgAAAgkAAAgkAAAgkAAAgEACAAACCQAACCQAACCQAACAQAIAAAIJAAAIJAAAIJAAAIBAAgAAAgkAAAgkAAAgkAAAgEACAAACCQAACCQAACCQAACAQAIAAAIJAAAIJAAAIJAAAIBAAgAAAgkAAAgkAAAgkAAAgEACAAACCQAACCQAACCQAACAQAIAAAIJAAAIJAAAIJAAAIBAAgAAAn0CyK5V+uT9Ti4AAAAASUVORK5CYII=\"></div><div style=\"vertical-align: middle; max-width: 514px; display: flex; justify-content: space-between;\"><div style=\"float: left;\"><div title=\"#543005ff\" style=\"display: inline-block; width: 1em; height: 1em; margin: 0; vertical-align: middle; border: 1px solid #555; background-color: #543005ff;\"></div> under</div><div style=\"margin: 0 auto; display: inline-block;\">bad <div title=\"#00000000\" style=\"display: inline-block; width: 1em; height: 1em; margin: 0; vertical-align: middle; border: 1px solid #555; background-color: #00000000;\"></div></div><div style=\"float: right;\">over <div title=\"#003c30ff\" style=\"display: inline-block; width: 1em; height: 1em; margin: 0; vertical-align: middle; border: 1px solid #555; background-color: #003c30ff;\"></div></div>"
|
336 | 532 | ],
|
337 | 533 | "text/plain": [
|
338 |
| - "<matplotlib.colors.LinearSegmentedColormap at 0x156515290>" |
| 534 | + "<matplotlib.colors.LinearSegmentedColormap at 0x1105c2950>" |
339 | 535 | ]
|
340 | 536 | },
|
341 |
| - "execution_count": 11, |
| 537 | + "execution_count": 15, |
342 | 538 | "metadata": {},
|
343 | 539 | "output_type": "execute_result"
|
344 | 540 | }
|
|
357 | 553 | },
|
358 | 554 | {
|
359 | 555 | "cell_type": "code",
|
360 |
| - "execution_count": 19, |
| 556 | + "execution_count": 16, |
361 | 557 | "id": "5a77f728-9cbe-4372-9bfd-d6dee4b93a01",
|
362 | 558 | "metadata": {},
|
363 | 559 | "outputs": [],
|
364 | 560 | "source": [
|
365 |
| - "layer.get_fill_color = apply_continuous_cmap(normalized_download_speed, BrBG_10, alpha=0.3)" |
| 561 | + "map_.get_fill_color = apply_continuous_cmap(normalized_download_speed, BrBG_10)" |
366 | 562 | ]
|
367 | 563 | },
|
368 | 564 | {
|
|
385 | 581 | },
|
386 | 582 | {
|
387 | 583 | "cell_type": "code",
|
388 |
| - "execution_count": 13, |
| 584 | + "execution_count": 17, |
389 | 585 | "id": "579233ef-e077-4c8f-a111-f33d44f30a0d",
|
390 | 586 | "metadata": {},
|
391 | 587 | "outputs": [],
|
392 | 588 | "source": [
|
393 | 589 | "# for now, cast to a numpy array until the layer is updated to support pandas series\n",
|
394 |
| - "layer.get_radius = np.array(normalized_download_speed) * 200\n", |
395 |
| - "layer.radius_units = \"meters\"\n", |
396 |
| - "layer.radius_min_pixels = 0.5" |
| 590 | + "map_.get_radius = np.array(normalized_download_speed) * 200\n", |
| 591 | + "map_.radius_units = \"meters\"\n", |
| 592 | + "map_.radius_min_pixels = 0.5" |
397 | 593 | ]
|
398 | 594 | },
|
399 | 595 | {
|
|
407 | 603 | ],
|
408 | 604 | "metadata": {
|
409 | 605 | "kernelspec": {
|
410 |
| - "display_name": "lonboard", |
| 606 | + "display_name": "Python 3 (ipykernel)", |
411 | 607 | "language": "python",
|
412 |
| - "name": "lonboard" |
| 608 | + "name": "python3" |
413 | 609 | },
|
414 | 610 | "language_info": {
|
415 | 611 | "codemirror_mode": {
|
|
0 commit comments