-
Notifications
You must be signed in to change notification settings - Fork 2
/
soil_moisture_dynamics_lb_pap.py
676 lines (612 loc) · 29.5 KB
/
soil_moisture_dynamics_lb_pap.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
from landlab import Component
from landlab.utils.decorators import use_file_name_or_kwds
import numpy as np
import six
_VALID_METHODS = set(['Grid', 'Multi'])
def assert_method_is_valid(method):
if method not in _VALID_METHODS:
raise ValueError('%s: Invalid method name' % method)
class SoilMoisture(Component):
"""
Landlab component that simulates root-zone average soil moisture at each
cell using inputs of potential evapotranspiration, live leaf area index,
and vegetation cover.
.. codeauthor:: Sai Nudurupati and Erkan Istanbulluoglu
Construction::
SoilMoisture(grid, runon=0., f_bare=0.7, soil_ew=0.1,
intercept_cap_grass= 1., zr_grass=0.3, I_B_grass=20.,
I_V_grass=24., K_s_grass=42., pc_grass=0.43, fc_grass=0.56,
sc_grass=0.33, wp_grass=0.13, hgw_grass=0.1, beta_grass=13.8,
LAI_max_grass=2., LAIR_max_grass=2.88,
intercept_cap_shrub=1.5, zr_shrub=0.5, I_B_shrub=20.,
I_V_shrub=40., K_s_shrub=42., pc_shrub=0.43, fc_shrub=0.56,
sc_shrub=0.24, wp_shrub=0.13, hgw_shrub=0.1, beta_shrub=13.8,
LAI_max_shrub=2., LAIR_max_shrub=2.,
intercept_cap_tree=2., zr_tree=1.3, I_B_tree=20.,
I_V_tree=40., K_s_tree=42., pc_tree=0.43, fc_tree=0.56,
sc_tree=0.22, wp_tree=0.15, hgw_tree=0.1, beta_tree=13.8,
LAI_max_tree=4., LAIR_max_tree=4.,
intercept_cap_bare=1., zr_bare=0.15, I_B_bare=20.,
I_V_bare=20., K_s_bare=42., pc_bare=0.43, fc_bare=0.56, sc_bare=0.33,
wp_bare=0.13, hgw_bare=0.1, beta_bare=13.8,
LAI_max_bare=0.01, LAIR_max_bare=0.01)
Parameters
----------
grid: RasterModelGrid
A grid.
runon: float, optional
Runon from higher elevation (mm).
f_bare: float, optional
Fraction to partition PET for bare soil (None).
soil_ew: float, optional
Residual Evaporation after wilting (mm/day).
intercept_cap: float, optional
Plant Functional Type (PFT) specific full canopy interception
capacity.
zr: float, optional
Root depth (m).
I_B: float, optional
Infiltration capacity of bare soil (mm/h).
I_V: float, optional
Infiltration capacity of vegetated soil (mm/h).
K_s: float, optional
Hydraulic conductivity of soil (mm/h).
pc: float, optional
Soil porosity (None).
fc: float, optional
Soil saturation degree at field capacity (None).
sc: float, optional
Soil saturation degree at stomatal closure (None).
wp: float, optional
Soil saturation degree at wilting point (None).
hgw: float, optional
Soil saturation degree at hygroscopic point (None).
beta: float, optional
Deep percolation constant = 2*b+3 where b is
water retention (None).
LAI_max: float, optional
Maximum leaf area index (m^2/m^2).
LAIR_max: float, optional
Reference leaf area index (m^2/m^2).
Examples
--------
>>> from landlab import RasterModelGrid
>>> from landlab.components.soil_moisture import SoilMoisture
>>> grid = RasterModelGrid((5, 4), spacing=(0.2, 0.2))
>>> SoilMoisture.name
'Soil Moisture'
>>> sorted(SoilMoisture.output_var_names) # doctest: +NORMALIZE_WHITESPACE
['soil_moisture__root_zone_leakage',
'soil_moisture__saturation_fraction',
'surface__evapotranspiration',
'surface__runoff',
'vegetation__water_stress']
>>> sorted(SoilMoisture.units) # doctest: +NORMALIZE_WHITESPACE
[('rainfall__daily_depth', 'mm'),
('soil_moisture__initial_saturation_fraction', 'None'),
('soil_moisture__root_zone_leakage', 'mm'),
('soil_moisture__saturation_fraction', 'None'),
('surface__evapotranspiration', 'mm'),
('surface__potential_evapotranspiration_rate', 'mm'),
('surface__runoff', 'mm'),
('vegetation__cover_fraction', 'None'),
('vegetation__live_leaf_area_index', 'None'),
('vegetation__plant_functional_type', 'None'),
('vegetation__water_stress', 'None')]
>>> grid['cell']['vegetation__plant_functional_type']= (
... np.zeros(grid.number_of_cells, dtype=int))
>>> SM = SoilMoisture(grid)
>>> SM.grid.number_of_cell_rows
3
>>> SM.grid.number_of_cell_columns
2
>>> SM.grid is grid
True
>>> import numpy as np
>>> np.allclose(grid.at_cell['soil_moisture__saturation_fraction'], 0.)
True
>>> grid['cell']['surface__potential_evapotranspiration_rate']= np.array([
... 0.2554777, 0.2554777 , 0.22110221, 0.22110221,
... 0.24813062, 0.24813062])
>>> grid['cell']['soil_moisture__initial_saturation_fraction']= (
... 0.75 * np.ones(grid.number_of_cells))
>>> grid['cell']['vegetation__live_leaf_area_index']= (
... 2. * np.ones(grid.number_of_cells))
>>> grid['cell']['vegetation__cover_fraction']= (
... np.ones(grid.number_of_cells))
>>> current_time = 0.5
>>> grid['cell']['rainfall__daily_depth'] = (
... 25. * np.ones(grid.number_of_cells))
>>> current_time = SM.update(current_time)
>>> np.allclose(grid.at_cell['soil_moisture__saturation_fraction'], 0.)
False
"""
_name = 'Soil Moisture'
_input_var_names = (
'vegetation__cover_fraction',
'vegetation__live_leaf_area_index',
'surface__potential_evapotranspiration_rate',
'surface__potential_evapotranspiration_rate__grass',
'soil_moisture__initial_saturation_fraction',
'vegetation__plant_functional_type',
'rainfall__daily_depth',
)
_output_var_names = (
'vegetation__water_stress',
'soil_moisture__saturation_fraction',
'soil_moisture__root_zone_leakage',
'surface__runoff',
'surface__runon',
'surface__evapotranspiration',
)
_var_units = {
'vegetation__cover_fraction': 'None',
'vegetation__live_leaf_area_index': 'None',
'surface__potential_evapotranspiration_rate': 'mm',
'surface__potential_evapotranspiration_rate__grass': 'mm',
'vegetation__plant_functional_type': 'None',
'vegetation__water_stress': 'None',
'soil_moisture__saturation_fraction': 'None',
'soil_moisture__initial_saturation_fraction': 'None',
'soil_moisture__root_zone_leakage': 'mm',
'surface__runoff': 'mm',
'surface__runon': 'mm',
'surface__evapotranspiration': 'mm',
'rainfall__daily_depth': 'mm',
}
_var_mapping = {
'vegetation__cover_fraction': 'cell',
'vegetation__live_leaf_area_index': 'cell',
'surface__potential_evapotranspiration_rate': 'cell',
'surface__potential_evapotranspiration_rate__grass': 'cell',
'vegetation__plant_functional_type': 'cell',
'vegetation__water_stress': 'cell',
'soil_moisture__saturation_fraction': 'cell',
'soil_moisture__initial_saturation_fraction': 'cell',
'soil_moisture__root_zone_leakage': 'cell',
'surface__runoff': 'cell',
'surface__runon': 'cell',
'surface__evapotranspiration': 'cell',
'rainfall__daily_depth': 'cell',
}
_var_doc = {
'vegetation__cover_fraction':
'fraction of land covered by vegetation',
'vegetation__live_leaf_area_index':
'one-sided green leaf area per unit ground surface area',
'surface__potential_evapotranspiration_rate':
'potential sum of evaporation and plant transpiration',
'surface__potential_evapotranspiration_rate__grass':
'potential sum of evaporation and grass transpiration, \
for partitioning bare soil evapotranspiration rate',
'vegetation__plant_functional_type':
'classification of plants (int), grass=0, shrub=1, tree=2, \
bare=3, shrub_seedling=4, tree_seedling=5',
'vegetation__water_stress':
'parameter that represents nonlinear effects of water deficit \
on plants',
'soil_moisture__saturation_fraction':
'relative volumetric water content (theta) - limits=[0,1]',
'soil_moisture__initial_saturation_fraction':
'initial soil_moisture__saturation_fraction',
'soil_moisture__root_zone_leakage':
'leakage of water into deeper portions of the soil not accessible \
to the plant',
'surface__runoff':
'infiltration excess runoff from ground surface',
'surface__runon':
'infiltration excess runon',
'surface__evapotranspiration':
'actual sum of evaporation and plant transpiration',
'rainfall__daily_depth':
'Rain in (mm) as a field, allowing spatio-temporal soil moisture \
saturation analysis.',
}
@use_file_name_or_kwds
def __init__(self, grid, ordered_cells=None, runon_switch=0,
f_bare=0.7, soil_ew=0.1,
intercept_cap_grass=1., zr_grass=0.3, I_B_grass=20.,
I_V_grass=24., K_s_grass=42., pc_grass=0.43, fc_grass=0.56,
sc_grass=0.33, wp_grass=0.13, hgw_grass=0.1, beta_grass=13.8,
LAI_max_grass=2., LAIR_max_grass=2.88,
intercept_cap_shrub=1.5, zr_shrub=0.5, I_B_shrub=20.,
I_V_shrub=40., K_s_shrub=42., pc_shrub=0.43, fc_shrub=0.56,
sc_shrub=0.24, wp_shrub=0.13, hgw_shrub=0.1, beta_shrub=13.8,
LAI_max_shrub=2., LAIR_max_shrub=2.,
intercept_cap_tree=2., zr_tree=1.3, I_B_tree=20.,
I_V_tree=40., K_s_tree=42., pc_tree=0.43, fc_tree=0.56,
sc_tree=0.22, wp_tree=0.15, hgw_tree=0.1, beta_tree=13.8,
LAI_max_tree=4., LAIR_max_tree=4.,
intercept_cap_bare=1., zr_bare=0.15, I_B_bare=20.,
I_V_bare=20., K_s_bare=42., pc_bare=0.43, fc_bare=0.56,
sc_bare=0.33, wp_bare=0.13, hgw_bare=0.1, beta_bare=13.8,
LAI_max_bare=0.01, LAIR_max_bare=0.01, **kwds):
"""
Parameters
----------
grid: RasterModelGrid
A grid.
runon_switch: int, optional
To indicate whether runon needs to considered (mm);
0 - No runon, 1 - runon.
ordered_cells: numpy.array, required if runon_switch = 1
ordered_cells has the grid cells sorted in an order of descending
channel length in a delineated watershed
f_bare: float, optional
Fraction to partition PET for bare soil (None).
soil_ew: float, optional
Residual Evaporation after wilting (mm/day).
intercept_cap: float, optional
Plant Functional Type (PFT) specific full canopy interception
capacity.
zr: float, optional
Root depth (m).
I_B: float, optional
Infiltration capacity of bare soil (mm/h).
I_V: float, optional
Infiltration capacity of vegetated soil (mm/h).
K_s: float, optional
Hydraulic conductivity of soil (mm/h).
pc: float, optional
Soil porosity (None).
fc: float, optional
Soil saturation degree at field capacity (None).
sc: float, optional
Soil saturation degree at stomatal closure (None).
wp: float, optional
Soil saturation degree at wilting point (None).
hgw: float, optional
Soil saturation degree at hygroscopic point (None).
beta: float, optional
Deep percolation constant = 2*b+4 where b is
water retention (None).
LAI_max: float, optional
Maximum leaf area index (m^2/m^2).
LAIR_max: float, optional
Reference leaf area index (m^2/m^2).
"""
self._method = kwds.pop('method', 'Grid')
assert_method_is_valid(self._method)
super(SoilMoisture, self).__init__(grid)
self.initialize(ordered_cells=ordered_cells, runon_switch=runon_switch,
f_bare=f_bare, soil_ew=soil_ew,
intercept_cap_grass=intercept_cap_grass,
zr_grass=zr_grass, I_B_grass=I_B_grass,
I_V_grass=I_V_grass, K_s_grass=K_s_grass,
pc_grass=pc_grass, fc_grass=fc_grass,
sc_grass=sc_grass, wp_grass=wp_grass,
hgw_grass=hgw_grass, beta_grass=beta_grass,
LAI_max_grass=LAI_max_grass,
LAIR_max_grass=LAIR_max_grass,
intercept_cap_shrub=intercept_cap_shrub,
zr_shrub=zr_shrub, I_B_shrub=I_B_shrub,
I_V_shrub=I_V_shrub, K_s_shrub=K_s_shrub,
pc_shrub=pc_shrub, fc_shrub=fc_shrub,
sc_shrub=sc_shrub, wp_shrub=wp_shrub,
hgw_shrub=hgw_shrub, beta_shrub=beta_shrub,
LAI_max_shrub=LAI_max_shrub,
LAIR_max_shrub=LAIR_max_shrub,
intercept_cap_tree=intercept_cap_tree, zr_tree=zr_tree,
I_B_tree=I_B_tree, I_V_tree=I_V_tree,
K_s_tree=K_s_tree, pc_tree=pc_tree,
fc_tree=fc_tree, sc_tree=sc_tree, wp_tree=wp_tree,
hgw_tree=hgw_tree, beta_tree=beta_tree,
LAI_max_tree=LAI_max_tree, LAIR_max_tree=LAIR_max_tree,
intercept_cap_bare=intercept_cap_bare, zr_bare=zr_bare,
I_B_bare=I_B_bare, I_V_bare=I_V_bare,
K_s_bare=K_s_bare, pc_bare=pc_bare,
fc_bare=fc_bare, sc_bare=sc_bare, wp_bare=wp_bare,
hgw_bare=hgw_bare, beta_bare=beta_bare,
LAI_max_bare=LAI_max_bare,
LAIR_max_bare=LAIR_max_bare, **kwds)
for name in self._input_var_names:
if name not in self.grid.at_cell:
self.grid.add_zeros('cell', name, units=self._var_units[name])
for name in self._output_var_names:
if name not in self.grid.at_cell:
self.grid.add_zeros('cell', name, units=self._var_units[name])
self._nodal_values = self.grid['node']
self._cell_values = self.grid['cell']
def initialize(self, ordered_cells=None, runon_switch=0, f_bare=0.7,
soil_ew=0.1, intercept_cap_grass=1., zr_grass=0.3,
I_B_grass=20., I_V_grass=24., K_s_grass=42.,
pc_grass=0.43, fc_grass=0.56,
sc_grass=0.33, wp_grass=0.13, hgw_grass=0.1,
beta_grass=13.8, LAI_max_grass=2., LAIR_max_grass=2.88,
intercept_cap_shrub=1.5, zr_shrub=0.5, I_B_shrub=20.,
I_V_shrub=40., K_s_shrub=42., pc_shrub=0.43,
fc_shrub=0.56, sc_shrub=0.24,
wp_shrub=0.13, hgw_shrub=0.1, beta_shrub=13.8,
LAI_max_shrub=2., LAIR_max_shrub=2.,
intercept_cap_tree=2., zr_tree=1.3, I_B_tree=20.,
I_V_tree=40., K_s_tree=42., pc_tree=0.43,
fc_tree=0.56, sc_tree=0.22,
wp_tree=0.15, hgw_tree=0.1, beta_tree=13.8,
LAI_max_tree=4., LAIR_max_tree=4.,
intercept_cap_bare=1., zr_bare=0.15, I_B_bare=20.,
I_V_bare=20., K_s_bare=42., pc_bare=0.43,
fc_bare=0.56, sc_bare=0.33,
wp_bare=0.13, hgw_bare=0.1, beta_bare=13.8,
LAI_max_bare=0.01, LAIR_max_bare=0.01, **kwds):
# GRASS = 0; SHRUB = 1; TREE = 2; BARE = 3;
# SHRUBSEEDLING = 4; TREESEEDLING = 5
"""
Parameters
----------
grid: RasterModelGrid
A grid.
runon_switch: int, optional
To indicate whether runon needs to considered (mm);
0 - No runon, 1 - runon.
ordered_cells: numpy.array, required if runon_switch = 1
ordered_cells has the grid cells sorted in an order of descending
channel length in a delineated watershed
f_bare: float, optional
Fraction to partition PET for bare soil (None).
soil_ew: float, optional
Residual Evaporation after wilting (mm/day).
intercept_cap: float, optional
Plant Functional Type (PFT) specific full canopy interception
capacity.
zr: float, optional
Root depth (m).
I_B: float, optional
Infiltration capacity of bare soil (mm/h).
I_V: float, optional
Infiltration capacity of vegetated soil (mm/h).
K_s: float, optional
Hydraulic conductivity of soil (mm/h).
pc: float, optional
Soil porosity (None).
fc: float, optional
Soil saturation degree at field capacity (None).
sc: float, optional
Soil saturation degree at stomatal closure (None).
wp: float, optional
Soil saturation degree at wilting point (None).
hgw: float, optional
Soil saturation degree at hygroscopic point (None).
beta: float, optional
Deep percolation constant = 2*b+4 where b is
water retention (None).
parameter (None)
LAI_max: float, optional
Maximum leaf area index (m^2/m^2).
LAIR_max: float, optional
Reference leaf area index (m^2/m^2).
"""
self._vegtype = self.grid['cell']['vegetation__plant_functional_type']
self._runon_switch = runon_switch
self._fbare = f_bare
self.ordered_cells = ordered_cells
self._interception_cap = np.choose(self._vegtype, [
intercept_cap_grass, intercept_cap_shrub, intercept_cap_tree,
intercept_cap_bare, intercept_cap_shrub, intercept_cap_tree])
self._zr = np.choose(self._vegtype, [
zr_grass, zr_shrub, zr_tree, zr_bare, zr_shrub, zr_tree])
self._soil_Ib = np.choose(self._vegtype, [
I_B_grass, I_B_shrub, I_B_tree, I_B_bare, I_B_shrub, I_B_tree])
self._soil_Iv = np.choose(self._vegtype, [
I_V_grass, I_V_shrub, I_V_tree, I_V_bare, I_V_shrub, I_V_tree])
self._soil_Ks = np.choose(self._vegtype, [
K_s_grass, K_s_shrub, K_s_tree, K_s_bare, K_s_shrub, K_s_tree])
self._soil_Ew = soil_ew
self._soil_pc = np.choose(self._vegtype, [
pc_grass, pc_shrub, pc_tree, pc_bare, pc_shrub, pc_tree])
self._soil_fc = np.choose(self._vegtype, [
fc_grass, fc_shrub, fc_tree, fc_bare, fc_shrub, fc_tree])
self._soil_sc = np.choose(self._vegtype, [
sc_grass, sc_shrub, sc_tree, sc_bare, sc_shrub, sc_tree])
self._soil_wp = np.choose(self._vegtype, [
wp_grass, wp_shrub, wp_tree, wp_bare, wp_shrub, wp_tree])
self._soil_hgw = np.choose(self._vegtype, [
hgw_grass, hgw_shrub, hgw_tree, hgw_bare, hgw_shrub, hgw_tree])
self._soil_beta = np.choose(self._vegtype, [
beta_grass, beta_shrub, beta_tree,
beta_bare, beta_shrub, beta_tree])
self._LAI_max = np.choose(self._vegtype, [
LAI_max_grass, LAI_max_shrub, LAI_max_tree,
LAI_max_bare, LAI_max_shrub, LAI_max_tree])
self._LAIR_max = np.choose(self._vegtype, [
LAIR_max_grass, LAIR_max_shrub, LAIR_max_tree,
LAIR_max_bare, LAIR_max_shrub, LAIR_max_tree])
def update(self, current_time, Tb=24., Tr=0., **kwds):
"""
Update fields with current loading conditions.
Parameters
----------
current_time: float
Current time (years).
Tr: float, optional
Storm duration (hours).
Tb: float, optional
Inter-storm duration (hours).
"""
P_ = self._cell_values['rainfall__daily_depth']
self._PET = (
self._cell_values['surface__potential_evapotranspiration_rate'])
self._pet_g = (
self._cell_values['surface__potential_evapotranspiration_rate__grass'])
self._SO = (
self._cell_values['soil_moisture__initial_saturation_fraction'])
self._vegcover = self._cell_values['vegetation__cover_fraction']
self._water_stress = self._cell_values['vegetation__water_stress']
self._S = self._cell_values['soil_moisture__saturation_fraction']
self._D = self._cell_values['soil_moisture__root_zone_leakage']
self._ETA = self._cell_values['surface__evapotranspiration']
self._fr = (self._cell_values['vegetation__live_leaf_area_index'] /
self._LAIR_max)
self._runoff = self._cell_values['surface__runoff']
self._runon = self._cell_values['surface__runon']
self._runoff[:] = 0. # Initializing runoff to zero
self._runon[:] = 0. # Initializing runon to zero
# LAIl = self._cell_values['vegetation__live_leaf_area_index']
# LAIt = LAIl+self._cell_values['DeadLeafAreaIndex']
# if LAIt.all() == 0.:
# self._fr = np.zeros(self.grid.number_of_cells)
# else:
# self._fr = (self._vegcover[0]*LAIl/LAIt)
self._fr[self._fr > 1.] = 1.
self._Sini = np.zeros(self._SO.shape)
self._ETmax = np.zeros(self._SO.shape)
self._ts = np.zeros(self._SO.shape) # record Time to Saturation
self._precip_int = np.zeros(self._SO.shape)
# Adding routine to add runon & runoff
if self._runon_switch:
# Make sure that flow_router has been called before
r_cell = (self.grid.cell_at_node[
self.grid.at_node['flow__receiver_node']])
r_cell = r_cell[r_cell != -1]
# finding cells that aren't part of
# ordered cells (delineated watershed)
diff_cells = (np.setdiff1d(
range(0, self.grid.number_of_cells), self.ordered_cells))
# trvrsl_order has ordered cells computed first and then the rest
# of the cells
trvrsl_order = np.concatenate((self.ordered_cells, diff_cells),
axis=0)
else:
# trvrsl_order is just regular 'all cells' if no runon is computed
trvrsl_order = range(0, self.grid.number_of_cells)
for cell in trvrsl_order:
# Routine to calculate runon
if self._runon_switch:
if cell in self.ordered_cells:
donors = []
donors = list(np.where(r_cell == cell)[0])
if len(donors) != 0:
for k in range(0, len(donors)):
self._runon[cell] += self._runoff[donors[k]]
P = P_[cell]
runon = self._runon[cell]
if runon < 0:
six._print('Runon < 0!')
# print cell
s = self._SO[cell]
fbare = self._fbare
ZR = self._zr[cell]
pc = self._soil_pc[cell]
fc = self._soil_fc[cell]
scc = self._soil_sc[cell]
wp = self._soil_wp[cell]
hgw = self._soil_hgw[cell]
beta = self._soil_beta[cell]
Ks = self._soil_Ks[cell]
if self._vegtype[cell] == 0: # 0 - GRASS
sc = scc*self._fr[cell]+(1-self._fr[cell])*fc
else:
sc = scc
# Infiltration capacity
Inf_cap = (self._soil_Ib[cell]*(1-self._vegcover[cell]) +
self._soil_Iv[cell]*self._vegcover[cell])
# Interception capacity
Int_cap = min(self._vegcover[cell]*self._interception_cap[cell],
P*self._vegcover[cell])
# Effective precipitation depth
Peff = max((P + max(runon, 0.) - Int_cap), 0.)
mu = (Ks/1000.0)/(pc*ZR*(np.exp(beta*(1.-fc))-1.))
if self._vegtype[cell] == 3:
Ep = max((fbare*self._pet_g[cell]), 0.0001)
else:
Ep = max((self._PET[cell]*self._fr[cell] +
fbare*self._pet_g[cell]*(1.-self._fr[cell])) -
Int_cap, 0.0001) # mm/d
self._ETmax[cell] = Ep
nu = ((Ep / 24.) / 1000.) / (pc*ZR) # Loss function parameter
# Loss function parameter
nuw = ((self._soil_Ew/24.)/1000.)/(pc*ZR)
# Precipitation Intensity
precip_int = Peff/Tr
self._precip_int[cell] = precip_int
# Time to saturation Ts
if precip_int <= 0.:
Ts = np.inf
else:
Ts = (((1 - self._SO[cell]) * (pc * ZR * 1000.)) /
(precip_int*(1-np.exp((-1)*Inf_cap/precip_int))))
self._ts[cell] = Ts
# Computing runoff
# If using Poisson storms with Tr = 0, (Precip_int * Tr = Precip)
if Tr == 0.:
self._runoff[cell] = max((Peff - Inf_cap), 0.)
sini = min(self._SO[cell] + ((Peff -
self._runoff[cell])/(pc*ZR*1000.)), 1.)
# If using regular storms with (Tr != 0.)
elif Tr < Ts:
self._runoff[cell] = max((precip_int - Inf_cap)*Tr, 0.)
sini = min(self._SO[cell] + ((precip_int * Tr -
self._runoff[cell])/(pc*ZR*1000.)), 1.)
else:
sini = 1
self._runoff[cell] = max(((precip_int-Inf_cap)*Ts +
(precip_int*(Tr-Ts))), 0.)
if sini >= fc:
tfc = (1./(beta*(mu-nu)))*(beta*(fc-sini) + np.log((
nu-mu+mu*np.exp(beta*(sini-fc)))/nu))
tsc = ((fc-sc)/nu)+tfc
twp = ((sc-wp)/(nu-nuw))*np.log(nu/nuw)+tsc
if Tb < tfc:
s = abs(sini-(1./beta)*np.log(((nu-mu+mu *
np.exp(beta*(sini-fc)))*np.exp(beta*(nu-mu)*Tb) -
mu*np.exp(beta*(sini-fc)))/(nu-mu)))
self._D[cell] = ((pc*ZR*1000.)*(sini-s))-(Tb*(Ep/24.))
self._ETA[cell] = (Tb*(Ep/24.))
elif Tb >= tfc and Tb < tsc:
s = fc-(nu*(Tb-tfc))
self._D[cell] = ((pc*ZR*1000.)*(sini-fc))-((tfc)*(Ep/24.))
self._ETA[cell] = (Tb*(Ep/24.))
elif Tb >= tsc and Tb < twp:
s = (wp+(sc-wp)*((nu/(nu-nuw))*np.exp((-1)*((nu-nuw) /
(sc-wp))*(Tb-tsc))-(nuw/(nu-nuw))))
self._D[cell] = ((pc*ZR*1000.)*(sini-fc))-(tfc*Ep/24.)
self._ETA[cell] = (1000.*ZR*pc*(sini-s))-self._D[cell]
else:
s = (hgw+(wp-hgw)*np.exp((-1)*(nuw/(wp-hgw)) *
max(Tb-twp, 0.)))
self._D[cell] = ((pc*ZR*1000.)*(sini-fc))-(tfc*Ep/24.)
self._ETA[cell] = (1000.*ZR*pc*(sini-s))-self._D[cell]
elif sini < fc and sini >= sc:
tfc = 0.
tsc = (sini-sc)/nu
twp = ((sc-wp)/(nu-nuw))*np.log(nu/nuw)+tsc
if Tb < tsc:
s = sini - nu*Tb
self._D[cell] = 0.
self._ETA[cell] = 1000.*ZR*pc*(sini-s)
elif Tb >= tsc and Tb < twp:
s = (wp+(sc-wp)*((nu/(nu-nuw))*np.exp((-1) *
((nu-nuw)/(sc-wp))*(Tb-tsc))-(nuw/(nu-nuw))))
self._D[cell] = 0
self._ETA[cell] = (1000.*ZR*pc*(sini-s))
else:
s = hgw+(wp-hgw)*np.exp((-1)*(nuw/(wp-hgw))*(Tb-twp))
self._D[cell] = 0.
self._ETA[cell] = (1000.*ZR*pc*(sini-s))
elif sini < sc and sini >= wp:
tfc = 0
tsc = 0
twp = (((sc-wp)/(nu-nuw))*np.log(1+(nu-nuw)*(sini-wp) /
(nuw*(sc-wp))))
if Tb < twp:
s = (wp+((sc-wp)/(nu-nuw))*((np.exp((-1)*((nu-nuw) /
(sc-wp))*Tb))*(nuw+((nu-nuw)/(sc-wp))*(sini-wp))-nuw))
self._D[cell] = 0.
self._ETA[cell] = (1000.*ZR*pc*(sini-s))
else:
s = hgw+(wp-hgw)*np.exp((-1)*(nuw/(wp-hgw))*(Tb-twp))
self._D[cell] = 0.
self._ETA[cell] = (1000.*ZR*pc*(sini-s))
else:
tfc = 0.
tsc = 0.
twp = 0.
s = hgw+(sini-hgw)*np.exp((-1)*(nuw/(wp-hgw))*Tb)
self._D[cell] = 0.
self._ETA[cell] = (1000.*ZR*pc*(sini-s))
self._water_stress[cell] = min(((max(((sc - (s+sini)/2.) /
(sc - wp)), 0.))**4.), 1.0)
self._S[cell] = s
self._SO[cell] = s
self._Sini[cell] = sini
current_time += (Tb+Tr)/(24.*365.25)
return current_time