|
40 | 40 | "\n", |
41 | 41 | "import rasterio\n", |
42 | 42 | "\n", |
43 | | - "from landlab import imshow_grid, RasterModelGrid, VoronoiDelaunayGrid\n", |
| 43 | + "from landlab import imshow_grid, RasterModelGrid, HexModelGrid\n", |
44 | 44 | "\n", |
45 | 45 | "from umami import Metric" |
46 | 46 | ] |
|
252 | 252 | "cell_type": "markdown", |
253 | 253 | "metadata": {}, |
254 | 254 | "source": [ |
255 | | - "## Step 3: Use irregular data and a `VoronoiDelaunayGrid`\n", |
| 255 | + "## Step 3: Use irregular data and a `HexModelGrid`\n", |
256 | 256 | "\n", |
257 | 257 | "As a final example, we will look at specifying umami with an irregular grid. We won't import any standard format of irregular data but will create some by interpolating the regular data using the scipy tool [RegularGridInterpolator](https://docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.interpolate.RegularGridInterpolator.html).\n", |
258 | 258 | "\n", |
259 | | - "We use a tenth as many grid nodes as we had in the prior example. This is just for speed, feel free to adjust the value for `factor` to change this. \n", |
| 259 | + "We use a smaller number of nodes as we had in the prior example. This is just for speed, feel free to adjust the value for `factor` to change this. \n", |
260 | 260 | "\n", |
261 | 261 | "We start by creating a set of grid node locations in x and y. " |
262 | 262 | ] |
|
267 | 267 | "metadata": {}, |
268 | 268 | "outputs": [], |
269 | 269 | "source": [ |
270 | | - "factor = 11\n", |
271 | | - "nnodes = int(rmg.x_of_node.size / factor)\n", |
272 | | - "np.random.seed(27)\n", |
| 270 | + "factor = 5\n", |
| 271 | + "dx = rmg.spacing[0] * factor\n", |
273 | 272 | "\n", |
274 | | - "# select a random subset of x_of_node and y_of_node and permute by a small quantity.\n", |
275 | | - "# permute only in x, which allows the ordering of nodes to be maintained \n", |
276 | | - "index = np.linspace(0, rmg.x_of_node.size-1, nnodes, dtype=int)\n", |
277 | | - "random_x = rmg.x_of_node[index] + 0.4 * rmg.spacing[0] * np.random.randn(index.size)\n", |
278 | | - "random_y = rmg.y_of_node[index] " |
| 273 | + "hmg = HexModelGrid((int(rmg.shape[0]/factor*1.2), int(rmg.shape[1]/factor)+1), \n", |
| 274 | + " dx, \n", |
| 275 | + " node_layout=\"rect\", \n", |
| 276 | + " xy_of_lower_left=rmg.xy_of_lower_left)" |
279 | 277 | ] |
280 | 278 | }, |
281 | 279 | { |
|
292 | 290 | "outputs": [], |
293 | 291 | "source": [ |
294 | 292 | "plt.plot(rmg.x_of_node, rmg.y_of_node, 'k.', markersize=2, label=\"Raster Points\")\n", |
295 | | - "plt.plot(random_x, random_y, 'm.', label=\"Irregular Points\")\n", |
| 293 | + "plt.plot(hmg.x_of_node, hmg.y_of_node, 'm.', label=\"Irregular Points\")\n", |
296 | 294 | "plt.xlim(-105.40, -105.375)\n", |
297 | 295 | "plt.ylim(40.00, 40.025)" |
298 | 296 | ] |
|
314 | 312 | " rmg.x_of_node.reshape(rmg.shape)[0, :]),\n", |
315 | 313 | " z.reshape(rmg.shape), bounds_error=False, fill_value=None)\n", |
316 | 314 | "\n", |
317 | | - "interp_z = interp_obj((random_y, random_x))" |
| 315 | + "interp_z = interp_obj((hmg.y_of_node, hmg.x_of_node))" |
318 | 316 | ] |
319 | 317 | }, |
320 | 318 | { |
321 | 319 | "cell_type": "markdown", |
322 | 320 | "metadata": {}, |
323 | 321 | "source": [ |
324 | | - "Next we create a `VoronoiDelaunayGrid` and add `topographic__elevation` to it. \n", |
| 322 | + "Next we create a `HexModelGrid` and add `topographic__elevation` to it. \n", |
325 | 323 | "\n", |
326 | 324 | "One nice feature of the `imshow_grid` function is that it works for both regular and irregular grids. " |
327 | 325 | ] |
|
332 | 330 | "metadata": {}, |
333 | 331 | "outputs": [], |
334 | 332 | "source": [ |
335 | | - "vdg = VoronoiDelaunayGrid(random_x, random_y)\n", |
336 | | - "z = vdg.add_field(\"topographic__elevation\", interp_z, at=\"node\")\n", |
| 333 | + "z = hmg.add_field(\"topographic__elevation\", interp_z, at=\"node\")\n", |
337 | 334 | "\n", |
338 | | - "imshow_grid(vdg, z, cmap=\"terrain\")" |
| 335 | + "imshow_grid(hmg, z, cmap=\"terrain\")" |
339 | 336 | ] |
340 | 337 | }, |
341 | 338 | { |
|
367 | 364 | " }\n", |
368 | 365 | "}\n", |
369 | 366 | "\n", |
370 | | - "vmg_metric = Metric(vdg, metrics=metrics)\n", |
371 | | - "vmg_metric.calculate()" |
| 367 | + "hmg_metric = Metric(hmg, metrics=metrics)\n", |
| 368 | + "hmg_metric.calculate()" |
372 | 369 | ] |
373 | 370 | }, |
374 | 371 | { |
|
377 | 374 | "metadata": {}, |
378 | 375 | "outputs": [], |
379 | 376 | "source": [ |
380 | | - "vmg_metric.names" |
| 377 | + "hmg_metric.names" |
381 | 378 | ] |
382 | 379 | }, |
383 | 380 | { |
|
386 | 383 | "metadata": {}, |
387 | 384 | "outputs": [], |
388 | 385 | "source": [ |
389 | | - "vmg_metric.values" |
| 386 | + "hmg_metric.values" |
390 | 387 | ] |
391 | 388 | }, |
392 | 389 | { |
|
402 | 399 | "metadata": {}, |
403 | 400 | "outputs": [], |
404 | 401 | "source": [ |
405 | | - "for n in vmg_metric.names:\n", |
406 | | - " abs_change = np.abs(vmg_metric.value(n) - rmg_metric.value(n))\n", |
407 | | - " pct_change = abs_change /( 2* (vmg_metric.value(n) + rmg_metric.value(n)))\n", |
| 402 | + "for n in hmg_metric.names:\n", |
| 403 | + " abs_change = np.abs(hmg_metric.value(n) - rmg_metric.value(n))\n", |
| 404 | + " pct_change = abs_change /( (hmg_metric.value(n) + rmg_metric.value(n))/2)\n", |
408 | 405 | " print(n, \"\\n abs_change: \", abs_change, \"\\n pct_change: \", pct_change)" |
409 | 406 | ] |
410 | 407 | }, |
|
0 commit comments