-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathr.sim.terrain.py
executable file
·2039 lines (1833 loc) · 57.5 KB
/
r.sim.terrain.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
"""
MODULE: r.sim.terrain
AUTHOR(S): Brendan Harmon <[email protected]>
PURPOSE: Dynamic landscape evolution model
COPYRIGHT: (C) 2016 Brendan Harmon and the GRASS Development Team
This program is free software under the GNU General Public
License (>=v2). Read the file COPYING that comes with GRASS
for details.
"""
#%module
#% description: Dynamic landscape evolution model
#% keyword: raster
#% keyword: terrain
#% keyword: landscape
#% keyword: evolution
#%end
#%option G_OPT_R_ELEV
#% key: elevation
#% required: yes
#% guisection: Basic
#%end
#%option
#% key: runs
#% type: string
#% required: yes
#% multiple: no
#% answer: event
#% options: event,series
#% description: Run for a single rainfall event or a series of events
#% descriptions: event;single rainfall event;series;series of rainfall events
#% guisection: Basic
#%end
#%option
#% key: mode
#% type: string
#% required: yes
#% multiple: no
#% answer: simwe_mode
#% options: simwe_mode,usped_mode,rusle_mode
#% description: SIMWE erosion deposition, USPED transport limited, or RUSLE 3D detachment limited mode
#% descriptions: simwe_mode;SIMWE erosion deposition mode;usped_mode;USPED transport limited mode;rusle_mode;RUSLE 3D detachment limited mode
#% guisection: Basic
#%end
#%option
#% key: rain_intensity
#% type: integer
#% description: Rainfall intensity in mm/hr
#% answer: 50
#% multiple: no
#% required: no
#% guisection: Event
#%end
#%option
#% key: rain_duration
#% type: integer
#% description: Total duration of storm event in minutes
#% answer: 60
#% multiple: no
#% required: no
#% guisection: Event
#%end
#%option G_OPT_F_INPUT
#% key: precipitation
#% description: Name of input precipitation file
#% label: Precipitation file
#% required: no
#% guisection: Series
#%end
#%option G_OPT_R_INPUT
#% key: k_factor
#% description: Soil erodibility factor
#% label: K factor
#% required: no
#% guisection: Input
#%end
#%option
#% key: k_factor_value
#% type: double
#% description: Soil erodibility constant
#% label: K factor constant
#% answer: 0.25
#% multiple: no
#% guisection: Input
#%end
#%option G_OPT_R_INPUT
#% key: c_factor
#% description: Land cover factor
#% label: C factor
#% required: no
#% guisection: Input
#%end
#%option
#% key: c_factor_value
#% type: double
#% description: Land cover constant
#% label: C factor constant
#% answer: 0.1
#% multiple: no
#% guisection: Input
#%end
#%option
#% key: m
#% type: double
#% description: Water flow exponent
#% label: Water flow exponent
#% answer: 1.5
#% multiple: no
#% guisection: Input
#%end
#%option
#% key: n
#% type: double
#% description: Slope exponent
#% label: Slope exponent
#% answer: 1.2
#% multiple: no
#% guisection: Input
#%end
#%option
#% key: walkers
#% type: integer
#% description: Number of walkers (max = 7000000)
#% answer: 1000000
#% multiple: no
#% guisection: Input
#%end
#%option G_OPT_R_INPUT
#% key: runoff
#% description: Runoff coefficient (0.6 for bare earth, 0.35 for grass or crops, 0.5 for shrubs and trees, 0.25 for forest, 0.95 for roads)
#% label: Runoff coefficient
#% required: no
#% guisection: Input
#%end
#%option
#% key: runoff_value
#% type: double
#% description: Runoff coefficient (0.6 for bare earth, 0.35 for grass or crops, 0.5 for shrubs and trees, 0.25 for forest, 0.95 for roads)
#% label: Runoff coefficient
#% answer: 0.35
#% multiple: no
#% guisection: Input
#%end
#%option G_OPT_R_INPUT
#% key: mannings
#% description: Manning's roughness coefficient
#% label: Manning's roughness coefficient
#% required: no
#% guisection: Input
#%end
#%option
#% key: mannings_value
#% type: double
#% description: Manning's roughness coefficient
#% label: Manning's roughness coefficient
#% answer: 0.04
#% multiple: no
#% guisection: Input
#%end
#%option G_OPT_R_INPUT
#% key: detachment
#% description: Detachment coefficient
#% label: Detachment coefficient
#% required: no
#% guisection: Input
#%end
#%option
#% key: detachment_value
#% type: double
#% description: Detachment coefficient
#% label: Detachment coefficient
#% answer: 0.01
#% multiple: no
#% guisection: Input
#%end
#%option G_OPT_R_INPUT
#% key: transport
#% description: Transport coefficient
#% label: Transport coefficient
#% required: no
#% guisection: Input
#%end
#%option
#% key: transport_value
#% type: double
#% description: Transport coefficient
#% label: Transport coefficient
#% answer: 0.01
#% multiple: no
#% guisection: Input
#%end
#%option G_OPT_R_INPUT
#% key: shearstress
#% description: Shear stress coefficient
#% label: Shear stress coefficient
#% required: no
#% guisection: Input
#%end
#%option
#% key: shearstress_value
#% type: double
#% description: Shear stress coefficient
#% label: Shear stress coefficient
#% answer: 0.0
#% multiple: no
#% guisection: Input
#%end
#%option G_OPT_R_INPUT
#% key: density
#% description: Sediment mass density in g/cm^3
#% label: Sediment mass density
#% required: no
#% guisection: Input
#%end
#%option
#% key: density_value
#% type: double
#% description: Sediment mass density in g/cm^3
#% label: Sediment mass density
#% answer: 1.4
#% multiple: no
#% guisection: Input
#%end
#%option G_OPT_R_INPUT
#% key: mass
#% description: Mass of sediment per unit area in kg/m^2
#% label: Mass of sediment per unit area
#% required: no
#% guisection: Input
#%end
#%option
#% key: mass_value
#% type: double
#% description: Mass of sediment per unit area in kg/m^2
#% label: Mass of sediment per unit area
#% answer: 116.
#% multiple: no
#% guisection: Input
#%end
#%option
#% key: grav_diffusion
#% type: double
#% description: Gravitational diffusion coefficient in m^2/s
#% label: Gravitational diffusion coefficient
#% answer: 0.1
#% multiple: no
#% guisection: Input
#%end
#%option
#% key: erdepmin
#% type: double
#% description: Minimum values for erosion-deposition in kg/m^2s
#% label: Minimum values for erosion-deposition
#% answer: -0.5
#% multiple: no
#% guisection: Input
#%end
#%option
#% key: erdepmax
#% type: double
#% description: Maximum values for erosion-deposition in kg/m^2s
#% label: Maximum values for erosion-deposition
#% answer: 0.5
#% multiple: no
#% guisection: Input
#%end
#%option
#% key: start
#% type: string
#% description: Start time in year-month-day hour:minute:second format
#% answer: 2016-01-01 00:00:00
#% multiple: no
#% required: yes
#% guisection: Temporal
#%end
#%option
#% key: rain_interval
#% type: integer
#% description: Time interval between evolution events in minutes
#% answer: 1
#% multiple: no
#% required: yes
#% guisection: Temporal
#%end
#%option G_OPT_T_TYPE
#% key: temporaltype
#% answer: absolute
#% required: yes
#% guisection: Temporal
#%end
#%option
#% key: threads
#% type: integer
#% description: Number of threads for multiprocessing
#% answer: 1
#% multiple: no
#% required: no
#% guisection: Multiprocessing
#%end
#%option G_OPT_STRDS_OUTPUT
#% key: elevation_timeseries
#% answer: elevation_timeseries
#% required: yes
#% guisection: Output
#%end
#%option G_OPT_STRDS_OUTPUT
#% key: depth_timeseries
#% answer: depth_timeseries
#% required: no
#% guisection: Output
#%end
#%option G_OPT_STRDS_OUTPUT
#% key: erdep_timeseries
#% answer: erdep_timeseries
#% required: no
#% guisection: Output
#%end
#%option G_OPT_STRDS_OUTPUT
#% key: flux_timeseries
#% answer: flux_timeseries
#% required: no
#% guisection: Output
#%end
#%option G_OPT_STRDS_OUTPUT
#% key: difference_timeseries
#% answer: difference_timeseries
#% required: no
#% guisection: Output
#%end
#%flag
#% key: f
#% description: Fill depressions
#%end
import sys
import atexit
import csv
import datetime
import grass.script as gscript
from grass.exceptions import CalledModuleError
difference_colors = """\
0% 100 0 100
-1 magenta
-0.75 red
-0.5 orange
-0.25 yellow
-0.1 grey
0 white
0.1 grey
0.25 cyan
0.5 aqua
0.75 blue
1 0 0 100
100% black
"""
erosion_colors = """\
0% 100 0 100
-100 magenta
-10 red
-1 orange
-0.1 yellow
0 200 255 200
0.1 cyan
1 aqua
10 blue
100 0 0 100
100% black
"""
def main():
options, flags = gscript.parser()
elevation = options["elevation"]
runs = options["runs"]
mode = options["mode"]
precipitation = options["precipitation"]
start = options["start"]
rain_intensity = options["rain_intensity"]
rain_duration = options["rain_duration"]
rain_interval = options["rain_interval"]
temporaltype = options["temporaltype"]
elevation_timeseries = options["elevation_timeseries"]
elevation_title = "Evolved elevation"
elevation_description = "Time-series of evolved digital elevation models"
depth_timeseries = options["depth_timeseries"]
depth_title = "Evolved depth"
depth_description = "Time-series of evolved water depth"
erdep_timeseries = options["erdep_timeseries"]
erdep_title = "Evolved erosion-deposition"
erdep_description = "Time-series of evolved erosion-deposition"
flux_timeseries = options["flux_timeseries"]
flux_title = "Evolved flux"
flux_description = "Time-series of evolved sediment flux"
difference_timeseries = options["difference_timeseries"]
difference_title = "Evolved difference"
difference_description = "Time-series of evolved difference in elevation"
walkers = options["walkers"]
runoff = options["runoff"]
runoff_value = options["runoff_value"]
mannings = options["mannings"]
mannings_value = options["mannings_value"]
detachment = options["detachment"]
detachment_value = options["detachment_value"]
transport = options["transport"]
transport_value = options["transport_value"]
shearstress = options["shearstress"]
shearstress_value = options["shearstress_value"]
density = None
density_raster = options["density"]
density_value = options["density_value"]
mass = options["mass"]
mass_value = options["mass_value"]
grav_diffusion = options["grav_diffusion"]
erdepmin = options["erdepmin"]
erdepmax = options["erdepmax"]
k_factor = options["k_factor"]
c_factor = options["c_factor"]
k_factor_value = options["k_factor_value"]
c_factor_value = options["c_factor_value"]
m = options["m"]
n = options["n"]
threads = options["threads"]
fill_depressions = flags["f"]
# check for alternative input parameters
if not runoff:
runoff = "runoff"
gscript.mapcalc("runoff = {runoff_value}".format(**locals()), overwrite=True)
if not mannings:
mannings = "mannings"
gscript.mapcalc(
"mannings = {mannings_value}".format(**locals()), overwrite=True
)
if not detachment:
detachment = "detachment"
gscript.mapcalc(
"detachment = {detachment_value}".format(**locals()), overwrite=True
)
if not transport:
transport = "transport"
gscript.mapcalc(
"transport = {transport_value}".format(**locals()), overwrite=True
)
if not shearstress:
shearstress = "shearstress"
gscript.mapcalc(
"shearstress = {shearstress_value}".format(**locals()), overwrite=True
)
if not mass:
mass = "mass"
gscript.mapcalc("mass = {mass_value}".format(**locals()), overwrite=True)
density = "density"
if density_raster:
# convert g/cm^3 to kg/m^3
gscript.mapcalc(
"density = {density_raster} * 1000".format(**locals()), overwrite=True
)
else:
# convert g/cm^3 to kg/m^3
gscript.mapcalc(
"density = {density_value} * 1000".format(**locals()), overwrite=True
)
if not c_factor:
c_factor = "c_factor"
gscript.mapcalc(
"c_factor = {c_factor_value}".format(**locals()), overwrite=True
)
if not k_factor:
k_factor = "k_factor"
gscript.mapcalc(
"k_factor = {k_factor_value}".format(**locals()), overwrite=True
)
# copy the elevation raster if it is not in the current mapset
name = elevation.split("@")[0]
filename = gscript.read_command(
"g.list", type="raster", pattern=name, mapset=".", flags="m"
)
if not filename:
gscript.run_command("g.copy", raster=f"{elevation},{name}", overwrite=True)
elevation = name
# create dynamic evolution object
dynamics = DynamicEvolution(
elevation=elevation,
mode=mode,
precipitation=precipitation,
rain_intensity=rain_intensity,
rain_duration=rain_duration,
rain_interval=rain_interval,
temporaltype=temporaltype,
elevation_timeseries=elevation_timeseries,
elevation_title=elevation_title,
elevation_description=elevation_description,
depth_timeseries=depth_timeseries,
depth_title=depth_title,
depth_description=depth_description,
erdep_timeseries=erdep_timeseries,
erdep_title=erdep_title,
erdep_description=erdep_description,
flux_timeseries=flux_timeseries,
flux_title=flux_title,
flux_description=flux_description,
difference_timeseries=difference_timeseries,
difference_title=difference_title,
difference_description=difference_description,
start=start,
walkers=walkers,
runoff=runoff,
mannings=mannings,
detachment=detachment,
transport=transport,
shearstress=shearstress,
density=density,
mass=mass,
grav_diffusion=grav_diffusion,
erdepmin=erdepmin,
erdepmax=erdepmax,
k_factor=k_factor,
c_factor=c_factor,
m=m,
n=n,
threads=threads,
fill_depressions=fill_depressions,
)
# determine type of model and run
if runs == "series":
elevation = dynamics.rainfall_series()
if runs == "event":
elevation = dynamics.rainfall_event()
atexit.register(cleanup)
sys.exit(0)
class Evolution:
def __init__(
self,
elevation,
precipitation,
start,
rain_intensity,
rain_interval,
rain_duration,
walkers,
runoff,
mannings,
detachment,
transport,
shearstress,
density,
mass,
grav_diffusion,
erdepmin,
erdepmax,
k_factor,
c_factor,
m,
n,
threads,
fill_depressions,
):
self.elevation = elevation
self.precipitation = precipitation
self.start = start
self.rain_intensity = float(rain_intensity)
self.rain_interval = int(rain_interval)
self.rain_duration = int(rain_duration)
self.walkers = walkers
self.runoff = runoff
self.mannings = mannings
self.detachment = detachment
self.transport = transport
self.shearstress = shearstress
self.density = density
self.mass = mass
self.grav_diffusion = grav_diffusion
self.erdepmin = erdepmin
self.erdepmax = erdepmax
self.k_factor = k_factor
self.c_factor = c_factor
self.m = m
self.n = n
self.threads = threads
self.fill_depressions = fill_depressions
def parse_time(self):
"""parse, advance, and stamp time"""
# parse time
year = int(self.start[:4])
month = int(self.start[5:7])
day = int(self.start[8:10])
hours = int(self.start[11:13])
minutes = int(self.start[14:16])
seconds = int(self.start[17:19])
time = datetime.datetime(year, month, day, hours, minutes, seconds)
# advance time
time = time + datetime.timedelta(minutes=self.rain_interval)
time = time.isoformat(" ")
# timestamp
# elevation (m)
evolved_elevation = "elevation_" + time.replace(" ", "_").replace(
"-", "_"
).replace(":", "_")
# water depth (m)
depth = "depth_" + time.replace(" ", "_").replace("-", "_").replace(":", "_")
# sediment flux (kg/ms)
sediment_flux = "flux_" + time.replace(" ", "_").replace("-", "_").replace(
":", "_"
)
# erosion-deposition (kg/m2s)
erosion_deposition = "erosion_deposition_" + time.replace(" ", "_").replace(
"-", "_"
).replace(":", "_")
# elevation difference (m)
difference = "difference_" + time.replace(" ", "_").replace("-", "_").replace(
":", "_"
)
return (
evolved_elevation,
time,
depth,
sediment_flux,
erosion_deposition,
difference,
)
def compute_slope(self):
"""compute slope and partial derivatives"""
# assign variables
slope = "slope"
dx = "dx"
dy = "dy"
# compute slope and partial derivatives
gscript.run_command(
"r.slope.aspect",
elevation=self.elevation,
slope=slope,
dx=dx,
dy=dy,
flags="e",
overwrite=True,
)
return slope, dx, dy
def simwe(self, dx, dy, depth):
"""hydrologic simulation using a monte carlo path sampling method
to solve the shallow water flow equations"""
# assign variable
rain = "rain"
# hydrology parameters
gscript.mapcalc(f"{rain} = {self.rain_intensity}*{self.runoff}", overwrite=True)
# hydrologic simulation
gscript.run_command(
"r.sim.water",
elevation=self.elevation,
dx=dx,
dy=dy,
rain=rain,
man=self.mannings,
depth=depth,
niterations=self.rain_interval,
nwalkers=self.walkers,
nprocs=self.threads,
overwrite=True,
)
# remove temporary maps
gscript.run_command("g.remove", type="raster", name=["rain"], flags="f")
return depth
def event_based_r_factor(self):
"""compute event-based erosivity (R) factor (MJ mm ha^-1 hr^-1)"""
# assign variables
rain_energy = "rain_energy"
rain_volume = "rain_volume"
erosivity = "erosivity"
r_factor = "r_factor"
# derive rainfall energy (MJ ha^-1 mm^-1)
gscript.mapcalc(
f"{rain_energy}" f"=0.29*(1.-(0.72*exp(-0.05*{self.rain_intensity})))",
overwrite=True,
)
# derive rainfall volume
"""
rainfall volume (mm)
= rainfall intensity (mm/hr)
* (rainfall interval (min)
* (1 hr / 60 min))
"""
gscript.mapcalc(
f"{rain_volume}"
f"= {self.rain_intensity}"
f"*({self.rain_interval}"
f"/60.)",
overwrite=True,
)
# derive event erosivity index (MJ mm ha^-1 hr^-1)
gscript.mapcalc(
f"{erosivity}"
f"=({rain_energy}"
f"*{rain_volume})"
f"*{self.rain_intensity}"
f"*1.",
overwrite=True,
)
# derive R factor (MJ mm ha^-1 hr^-1 yr^1)
"""
R factor (MJ mm ha^-1 hr^-1 yr^1)
= EI (MJ mm ha^-1 hr^-1)
/ (rainfall interval (min)
* (1 yr / 525600 min))
"""
gscript.mapcalc(
f"{r_factor}" f"={erosivity}" f"/({self.rain_interval}" f"/525600.)",
overwrite=True,
)
# remove temporary maps
gscript.run_command(
"g.remove",
type="raster",
name=["rain_energy", "rain_volume", "erosivity"],
flags="f",
)
return r_factor
def gravitational_diffusion(self, evolved_elevation):
"""settling of sediment due to gravitational diffusion"""
# assign variables
dxx = "dxx"
dyy = "dyy"
divergence = "divergence"
settled_elevation = "settled_elevation"
# compute second order partial derivatives of evolved elevation
gscript.run_command(
"r.slope.aspect",
elevation=evolved_elevation,
dxx=dxx,
dyy=dyy,
flags="e",
overwrite=True,
)
# compute the laplacian (m^-1)
# i.e. the divergence of the elevation gradient
# from the sum of the second order derivatives of elevation
gscript.mapcalc(f"{divergence} = {dxx}+{dyy}", overwrite=True)
# compute settling caused by gravitational diffusion
"""
change in elevation (m)
= elevation (m)
- (change in time (s)
/ sediment mass density (kg/m^3)
* gravitational diffusion coefficient (m^2/s)
* divergence (m^-1))
"""
gscript.mapcalc(
f"{settled_elevation}"
f"={evolved_elevation}"
f"-({self.rain_interval}*60"
f"/{self.density}"
f"*{self.grav_diffusion}"
f"*{divergence})",
overwrite=True,
)
# update elevation
gscript.mapcalc(f"{evolved_elevation} = {settled_elevation}", overwrite=True)
gscript.run_command("r.colors", map=evolved_elevation, color="elevation")
# remove temporary maps
gscript.run_command(
"g.remove",
type="raster",
name=["settled_elevation", "divergence", "dxx", "dyy"],
flags="f",
)
return evolved_elevation
def fill_sinks(self, evolved_elevation):
"""fill sinks in digital elevation model"""
# assign variables
depressionless_elevation = "depressionless_elevation"
direction = "flow_direction"
# fill sinks
gscript.run_command(
"r.fill.dir",
input=evolved_elevation,
output=depressionless_elevation,
direction=direction,
overwrite=True,
)
# update elevation
gscript.mapcalc(
f"{evolved_elevation} = {depressionless_elevation}", overwrite=True
)
gscript.run_command("r.colors", map=evolved_elevation, color="elevation")
# remove temporary maps
gscript.run_command(
"g.remove",
type="raster",
name=["depressionless_elevation", "flow_direction"],
flags="f",
)
return evolved_elevation
def compute_difference(self, evolved_elevation, difference):
"""compute the change in elevation"""
gscript.mapcalc(
f"{difference} = {evolved_elevation}-{self.elevation}", overwrite=True
)
gscript.run_command("r.colors", map=difference, color="differences")
return difference
def erosion_deposition(self):
"""a process-based landscape evolution model using simulated
erosion and deposition to evolve a digital elevation model"""
# assign variables
erdep = "erdep" # kg/m^2s
# parse, advance, and stamp time
(
evolved_elevation,
time,
depth,
sediment_flux,
erosion_deposition,
difference,
) = self.parse_time()
# compute slope and partial derivatives
slope, dx, dy = self.compute_slope()
# hydrologic simulation
depth = self.simwe(dx, dy, depth)
# erosion-deposition simulation
gscript.run_command(
"r.sim.sediment",
elevation=self.elevation,
water_depth=depth,
dx=dx,
dy=dy,
detachment_coeff=self.detachment,
transport_coeff=self.transport,
shear_stress=self.shearstress,
man=self.mannings,
erosion_deposition=erdep,
niterations=self.rain_interval,
nwalkers=self.walkers,
nprocs=self.threads,
overwrite=True,
)
# filter outliers
gscript.mapcalc(
f"{erosion_deposition}"
f"=if({erdep}<{self.erdepmin},"
f"{self.erdepmin},"
f"if({erdep}>{self.erdepmax},{self.erdepmax},{erdep}))",
overwrite=True,
)
gscript.run_command("r.colors", map=erosion_deposition, raster=erdep)
# evolve landscape
"""
change in elevation (m)
= change in time (s)
* net erosion-deposition (kg/m^2s)
/ sediment mass density (kg/m^3)
"""
gscript.mapcalc(
f"{evolved_elevation}"
f"={self.elevation}"
f"+({self.rain_interval}*60"
f"*{erosion_deposition}"
f"/{self.density})",
overwrite=True,
)
# fill sinks
if self.fill_depressions:
evolved_elevation = self.fill_sinks(evolved_elevation)
# gravitational diffusion
evolved_elevation = self.gravitational_diffusion(evolved_elevation)
# compute elevation change
difference = self.compute_difference(evolved_elevation, difference)
# remove temporary maps
gscript.run_command(
"g.remove", type="raster", name=["erdep", "dx", "dy"], flags="f"
)
return (evolved_elevation, time, depth, erosion_deposition, difference)
def usped(self):
"""a transport limited landscape evolution model
using the USPED (Unit Stream Power Based Model) model to evolve
a digital elevation model"""
# assign variables
ls_factor = "ls_factor"
slope = "slope"
aspect = "aspect"
flowacc = "flowacc"
qsx = "qsx"
qsxdx = "qsxdx"
qsy = "qsy"
qsydy = "qsydy"
erdep = "erdep" # kg/m^2s
sedflow = "sedflow"