|
1 | 1 | { |
2 | 2 | "cells": [ |
3 | | - { |
4 | | - "cell_type": "code", |
5 | | - "execution_count": null, |
6 | | - "metadata": {}, |
7 | | - "outputs": [], |
8 | | - "source": [ |
9 | | - "!pip install rasterio==1.2.10\n", |
10 | | - "!pip install xarray-spatial==0.3.5\n", |
11 | | - "!pip install rtxpy\n", |
12 | | - "!pip install numba==0.55.1\n", |
13 | | - "!pip install geopandas\n", |
14 | | - "!pip install spatialpandas" |
15 | | - ] |
16 | | - }, |
17 | 3 | { |
18 | 4 | "cell_type": "markdown", |
19 | 5 | "metadata": { |
|
49 | 35 | "import xarray as xr\n", |
50 | 36 | "import numpy as np\n", |
51 | 37 | "import cupy\n", |
| 38 | + "import rioxarray\n", |
52 | 39 | "\n", |
53 | 40 | "from xrspatial import hillshade\n", |
54 | | - "from xrspatial import viewshed" |
| 41 | + "from xrspatial import viewshed\n", |
| 42 | + "\n", |
| 43 | + "import rioxarray" |
55 | 44 | ] |
56 | 45 | }, |
57 | 46 | { |
|
64 | 53 | "\n", |
65 | 54 | "#### Raster data\n", |
66 | 55 | "\n", |
67 | | - "The input ***elevation raster*** data covers the state of Colorado, USA. We'll load it from a local input file and calculate its bounding box to define the study area." |
| 56 | + "The input ***elevation raster*** data covers the state of Colorado, USA. We'll load it from a local input file and calculate its bounding box to define the study area.\n", |
| 57 | + "\n", |
| 58 | + "Example data available here: https://makepath-gpu-dataset.s3.us-east-1.amazonaws.com/colorado_merge_3arc_resamp.tif" |
68 | 59 | ] |
69 | 60 | }, |
70 | 61 | { |
|
73 | 64 | "metadata": {}, |
74 | 65 | "outputs": [], |
75 | 66 | "source": [ |
76 | | - "file_name = 'colorado_merge_3arc_resamp.tif'\n", |
77 | | - "raster = xr.open_rasterio(file_name).sel(band=1).drop('band', dim=None)\n", |
| 67 | + "file_name = './data/colorado_merge_3arc_resamp.tif'\n", |
| 68 | + "\n", |
| 69 | + "raster = rioxarray.open_rasterio(file_name).sel(band=1).drop_vars('band')\n", |
78 | 70 | "raster.name = 'Colorado Elevation Raster'\n", |
79 | 71 | "\n", |
80 | 72 | "xmin, xmax = raster.x.data.min(), raster.x.data.max()\n", |
|
236 | 228 | "for i, peak in top_peaks.iterrows():\n", |
237 | 229 | " viewpoint_x, viewpoint_y = peak['geometry'].x, peak['geometry'].y\n", |
238 | 230 | " viewshed_grid = viewshed(raster, x=viewpoint_x, y=viewpoint_y)\n", |
| 231 | + " print(type(viewshed_grid.data))\n", |
239 | 232 | " # assign name for the output grid\n", |
240 | 233 | " viewshed_grid.name = peak['NAME']\n", |
241 | 234 | " # set visible cells to VISIBLE\n", |
242 | | - " viewshed_grid = viewshed_grid.where(viewshed_grid == INVISIBLE, other=VISIBLE)\n", |
| 235 | + " mask_invisible = (viewshed_grid == INVISIBLE)\n", |
| 236 | + " viewshed_grid = mask_invisible * INVISIBLE + (~mask_invisible) * VISIBLE\n", |
243 | 237 | " visibility_grids.append(viewshed_grid)" |
244 | 238 | ] |
245 | 239 | }, |
|
321 | 315 | } |
322 | 316 | ], |
323 | 317 | "metadata": { |
| 318 | + "kernelspec": { |
| 319 | + "display_name": "Python 3 (ipykernel)", |
| 320 | + "language": "python", |
| 321 | + "name": "python3" |
| 322 | + }, |
324 | 323 | "language_info": { |
325 | | - "name": "python" |
| 324 | + "codemirror_mode": { |
| 325 | + "name": "ipython", |
| 326 | + "version": 3 |
| 327 | + }, |
| 328 | + "file_extension": ".py", |
| 329 | + "mimetype": "text/x-python", |
| 330 | + "name": "python", |
| 331 | + "nbconvert_exporter": "python", |
| 332 | + "pygments_lexer": "ipython3", |
| 333 | + "version": "3.14.2" |
326 | 334 | } |
327 | 335 | }, |
328 | 336 | "nbformat": 4, |
329 | | - "nbformat_minor": 0 |
| 337 | + "nbformat_minor": 4 |
330 | 338 | } |
0 commit comments