Skip to content

Commit 0fb9dc9

Browse files
committed
import NED right away
1 parent e017384 commit 0fb9dc9

File tree

1 file changed

+44
-61
lines changed

1 file changed

+44
-61
lines changed

content/tutorials/parallelization/SIMWE_parallelization.qmd

Lines changed: 44 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ tools.g_extension(extension="r.in.usgs")
282282
```
283283

284284
First, we will set the computational region to match the river subwatersheds and then list available datasets
285-
for that region:
285+
for that region (the output at the time of creating this tutorial, it may vary later on):
286286

287287
```{python}
288288
tools.g_region(vector="river_basins")
@@ -297,41 +297,42 @@ print(
297297
```
298298

299299
```text
300-
USGS file(s) to download:
301-
-------------------------
302-
Total download size: 4.83 GB
303-
Tile count: 16
304-
USGS SRS: wgs84
305-
USGS tile titles:
306-
USGS 1/3 Arc Second n36w081 20240510
307-
USGS 1/3 Arc Second n36w082 20220504
308-
USGS 1/3 Arc Second n36w082 20220512
309-
USGS 1/3 Arc Second n36w082 20240510
310-
USGS 1/3 Arc Second n37w080 20210305
311-
USGS 1/3 Arc Second n37w081 20210305
312-
USGS 1/3 Arc Second n37w081 20240510
313-
USGS 1/3 Arc Second n37w082 20210305
314-
USGS 1/3 Arc Second n37w082 20220512
315-
USGS 1/3 Arc Second n37w082 20240510
316-
USGS 13 arc-second n36w080 1 x 1 degree
317-
USGS 13 arc-second n36w081 1 x 1 degree
318-
USGS 13 arc-second n36w082 1 x 1 degree
319-
USGS 13 arc-second n37w080 1 x 1 degree
320-
USGS 13 arc-second n37w081 1 x 1 degree
321-
USGS 13 arc-second n37w082 1 x 1 degree
322-
-------------------------
300+
USGS file(s) to download:
301+
-------------------------
302+
Total download size: 5.32 GB
303+
Tile count: 17
304+
USGS SRS: wgs84
305+
USGS tile titles:
306+
USGS 1/3 Arc Second n36w080 20240611
307+
USGS 1/3 Arc Second n36w081 20240611
308+
USGS 1/3 Arc Second n36w082 20220504
309+
USGS 1/3 Arc Second n36w082 20220512
310+
USGS 1/3 Arc Second n36w082 20240611
311+
USGS 1/3 Arc Second n37w080 20210305
312+
USGS 1/3 Arc Second n37w081 20210305
313+
USGS 1/3 Arc Second n37w081 20240611
314+
USGS 1/3 Arc Second n37w082 20210305
315+
USGS 1/3 Arc Second n37w082 20220512
316+
USGS 1/3 Arc Second n37w082 20240611
317+
USGS 13 arc-second n36w080 1 x 1 degree
318+
USGS 13 arc-second n36w081 1 x 1 degree
319+
USGS 13 arc-second n36w082 1 x 1 degree
320+
USGS 13 arc-second n37w080 1 x 1 degree
321+
USGS 13 arc-second n37w081 1 x 1 degree
322+
USGS 13 arc-second n37w082 1 x 1 degree
323+
-------------------------
323324
```
324325

325326
We will select the 2024 data and use the `title_filter` option to filter them.
326-
We will first only download the datasets and use them later.
327+
We will download and import the datasets.
327328

328329
```{python}
329330
tools.r_in_usgs(
330331
product="ned",
331332
ned_dataset="ned13sec",
332-
flags="d",
333333
output_directory=os.getcwd(),
334-
title_filter="20240510",
334+
title_filter="20240611",
335+
output_name="ned",
335336
)
336337
```
337338

@@ -362,31 +363,22 @@ Set the computational region with [g.region](https://grass.osgeo.org/grass-devel
362363
tools.g_region(vector=f"basin_{huc12}")
363364
```
364365

365-
Import the NED data for that subwatershed. r.in.usgs will use already downloaded data.
366+
Display the NED data for that region:
366367

367368
```{python}
368-
tools.r_in_usgs(
369-
product="ned",
370-
ned_dataset="ned13sec",
371-
cache_size_tolerance=int(1e10),
372-
output_directory=os.getcwd(),
373-
title_filter="20240510",
374-
output_name=f"ned_{huc12}",
375-
)
376-
377-
basin_map = gj.Map()
378-
basin_map.d_rast(map=f"ned_{huc12}")
369+
basin_map = gj.Map(current_region=True)
370+
basin_map.d_rast(map="ned")
379371
basin_map.d_vect(map=f"basin_{huc12}", fill_color="none")
380372
basin_map.show()
381373
```
382374

383375
![](SIMWE_images/basin_030401010402.webp)
384376

385-
Set the region to match the elevation raster.
377+
Set the region to match the extent of the basin and align resolution with the elevation raster.
386378
Convert the selected vector to a raster using [v.to.rast](https://grass.osgeo.org/grass-devel/manuals/v.to.rast.html).
387379

388380
```{python}
389-
tools.g_region(raster=f"ned_{huc12}")
381+
tools.g_region(raster="ned", vector=f"basin_{huc12}")
390382
tools.v_to_rast(input=f"basin_{huc12}", output=f"basin_{huc12}", use="val")
391383
```
392384

@@ -397,10 +389,10 @@ MaskManager is new in GRASS version 8.5. Alternatively, you can use [r.mask](htt
397389
mask = gs.MaskManager(mask_name=f"basin_{huc12}")
398390
mask.activate()
399391
400-
basin_map = gj.Map()
401-
basin_map.d_rast(map=f"ned_{huc12}")
392+
basin_map = gj.Map(current_region=True)
393+
basin_map.d_rast(map="ned")
402394
basin_map.d_legend(
403-
raster=f"ned_{huc12}",
395+
raster="ned",
404396
flags="t",
405397
at=[10, 15, 40, 95],
406398
title="Elevation [m]",
@@ -476,7 +468,7 @@ tools.r_recode(input=f"nlcd_{huc12}", output=f"runoff_{huc12}", rules="runoff.tx
476468
Then, compute slope components (dx and dy) from the elevation raster to support hydrologic modeling.
477469

478470
```{python}
479-
tools.r_slope_aspect(elevation=f"ned_{huc12}", dx=f"dx_{huc12}", dy=f"dy_{huc12}")
471+
tools.r_slope_aspect(elevation="ned", dx=f"dx_{huc12}", dy=f"dy_{huc12}")
480472
```
481473

482474
Run hydrologic and sediment simulations for the selected subwatershed.
@@ -487,7 +479,7 @@ Running the simulation may take a while.
487479
```{python}
488480
simulation_time = 180
489481
tools.r_sim_water(
490-
elevation=f"ned_{huc12}",
482+
elevation="ned",
491483
dx=f"dx_{huc12}",
492484
dy=f"dy_{huc12}",
493485
depth=f"depth_{huc12}",
@@ -519,7 +511,7 @@ tools.r_mapcalc(expression=f"transport_capacity_{huc12} = 0.001")
519511
tools.r_mapcalc(expression=f"detachment_coef_{huc12} = 0.001")
520512
tools.r_mapcalc(expression=f"shear_stress_{huc12} = 0.01")
521513
tools.r_sim_sediment(
522-
elevation=f"ned_{huc12}",
514+
elevation="ned",
523515
water_depth=f"depth_{huc12}",
524516
dx=f"dx_{huc12}",
525517
dy=f"dy_{huc12}",
@@ -645,17 +637,8 @@ def compute(huc12):
645637
where=f"huc12 == '{huc12}'",
646638
flags="t",
647639
)
648-
# Set the computational region to match non-null area in the new raster.
649-
with gs.RegionManager(vector=f"basin_{huc12}"):
650-
tools.r_in_usgs(
651-
product="ned",
652-
ned_dataset="ned13sec",
653-
cache_size_tolerance=int(1e10),
654-
output_directory=os.getcwd(),
655-
title_filter="20240510",
656-
output_name=f"ned_{huc12}",
657-
)
658-
with gs.RegionManager(raster=f"ned_{huc12}"):
640+
# Set the computational region to match the basin
641+
with gs.RegionManager(vector=f"basin_{huc12}", raster="ned"):
659642
tools.v_to_rast(
660643
input=f"basin_{huc12}",
661644
output=f"basin_{huc12}",
@@ -680,12 +663,12 @@ def compute(huc12):
680663
rules="runoff.txt",
681664
)
682665
tools.r_slope_aspect(
683-
elevation=f"ned_{huc12}",
666+
elevation="ned",
684667
dx=f"dx_{huc12}",
685668
dy=f"dy_{huc12}",
686669
)
687670
tools.r_sim_water(
688-
elevation=f"ned_{huc12}",
671+
elevation="ned",
689672
dx=f"dx_{huc12}",
690673
dy=f"dy_{huc12}",
691674
depth=f"depth_{huc12}",
@@ -698,7 +681,7 @@ def compute(huc12):
698681
tools.r_mapcalc(expression=f"shear_stress_{huc12} = 0.01")
699682
region = tools.g_region(flags="p", format="json")
700683
tools.r_sim_sediment(
701-
elevation=f"ned_{huc12}",
684+
elevation="ned",
702685
water_depth=f"depth_{huc12}",
703686
dx=f"dx_{huc12}",
704687
dy=f"dy_{huc12}",

0 commit comments

Comments
 (0)