Skip to content

Commit a37d5a8

Browse files
committed
updated viewshed gpu example
1 parent 21bdc79 commit a37d5a8

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed

examples/datasets.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,7 @@ data:
4848
files: LC80030172015001LGN00_B11.TIF
4949
- url: https://xarrayspatial.blob.core.windows.net/examples-data/LC80030172015001LGN00_BQA.tiff
5050
title: 'qa'
51-
files: LC80030172015001LGN00_BQA.TIF
51+
files: LC80030172015001LGN00_BQA.TIF
52+
- url: https://makepath-gpu-dataset.s3.us-east-1.amazonaws.com/colorado_merge_3arc_resamp.tif
53+
title: 'Colorado Elevation Data'
54+
files: colorado_merge_3arc_resamp.tif

examples/viewshed_gpu.ipynb

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
11
{
22
"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-
},
173
{
184
"cell_type": "markdown",
195
"metadata": {
@@ -49,9 +35,12 @@
4935
"import xarray as xr\n",
5036
"import numpy as np\n",
5137
"import cupy\n",
38+
"import rioxarray\n",
5239
"\n",
5340
"from xrspatial import hillshade\n",
54-
"from xrspatial import viewshed"
41+
"from xrspatial import viewshed\n",
42+
"\n",
43+
"import rioxarray"
5544
]
5645
},
5746
{
@@ -64,7 +53,9 @@
6453
"\n",
6554
"#### Raster data\n",
6655
"\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"
6859
]
6960
},
7061
{
@@ -73,8 +64,9 @@
7364
"metadata": {},
7465
"outputs": [],
7566
"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",
7870
"raster.name = 'Colorado Elevation Raster'\n",
7971
"\n",
8072
"xmin, xmax = raster.x.data.min(), raster.x.data.max()\n",
@@ -236,10 +228,12 @@
236228
"for i, peak in top_peaks.iterrows():\n",
237229
" viewpoint_x, viewpoint_y = peak['geometry'].x, peak['geometry'].y\n",
238230
" viewshed_grid = viewshed(raster, x=viewpoint_x, y=viewpoint_y)\n",
231+
" print(type(viewshed_grid.data))\n",
239232
" # assign name for the output grid\n",
240233
" viewshed_grid.name = peak['NAME']\n",
241234
" # 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",
243237
" visibility_grids.append(viewshed_grid)"
244238
]
245239
},
@@ -321,10 +315,24 @@
321315
}
322316
],
323317
"metadata": {
318+
"kernelspec": {
319+
"display_name": "Python 3 (ipykernel)",
320+
"language": "python",
321+
"name": "python3"
322+
},
324323
"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"
326334
}
327335
},
328336
"nbformat": 4,
329-
"nbformat_minor": 0
337+
"nbformat_minor": 4
330338
}

0 commit comments

Comments
 (0)