forked from WikiWatershed/gwlf-e
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgwlfe.py
executable file
·164 lines (130 loc) · 6.68 KB
/
gwlfe.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
"""
Runs the GWLF-E MapShed model.
Imported from GWLF-E.frm
"""
import logging
from numpy import zeros
from numpy import seterr
from . import ReadGwlfDataFile
from . import PrelimCalculations
from . import AFOS_old
from . import CalcLoads
from . import StreamBank
from . import AnnualMeans
from . import WriteOutputFiles
from .Input.WaterBudget.InitSnow import InitSnow_f
from .Input.WaterBudget.GrowFactor import GrowFactor_f
from .Input.LandUse.TotAreaMeters import TotAreaMeters
from .Input.LandUse.Ag.AvTileDrain import AvTileDrain_f
from .Input.WaterBudget.AvWithdrawal import AvWithdrawal_f
from .Input.WaterBudget.AvGroundWater import AvGroundWater_f
from .MultiUse_Fxns.Runoff.AvRunoff import AvRunoff_f
from .Memoization import resetMemoization
log = logging.getLogger(__name__)
def run(z):
resetMemoization()
log.debug('Running model...')
# Raise exception instead of printing a warning for floating point
# overflow, underflow, and division by 0 errors.
seterr(all='raise')
# MODEL CALCULATIONS FOR EACH YEAR OF ANALYSIS - WATER BALANCE,
# NUTRIENTS AND SEDIMENT LOADS
ReadGwlfDataFile.ReadAllData(z)
# --------- run the remaining parts of the model ---------------------
# CALCLULATE PRELIMINARY INITIALIZATIONS AND VALUES FOR
# WATER BALANCE AND NUTRIENTS
PrelimCalculations.InitialCalculations(z)
for Y in range(z.NYrs):
# Initialize monthly septic system variables
z.MonthPondNitr = zeros(12)
z.MonthPondPhos = zeros(12)
z.MonthNormNitr = zeros(12)
z.MonthShortNitr = zeros(12)
z.MonthShortPhos = zeros(12)
z.MonthDischargeNitr = zeros(12)
z.MonthDischargePhos = zeros(12)
# FOR EACH MONTH...
for i in range(12):
# LOOP THROUGH NUMBER OF LANDUSES IN THE BASIN TO GET QRUNOFF
for l in range(z.NLU):
z.QRunoff[l, i] = 0
z.AgQRunoff[l, i] = 0
# DAILY CALCULATIONS
for j in range(z.DaysMonth[Y][i]):
# ***** END WEATHER DATA ANALYSIS *****
# ***** WATERSHED WATER BALANCE *****
z.PondNitrLoad = (z.NumPondSys[i] *
(z.NitrSepticLoad - z.NitrPlantUptake * GrowFactor_f(z.Grow_0)[i]))
z.PondPhosLoad = (z.NumPondSys[i] *
(z.PhosSepticLoad - z.PhosPlantUptake * GrowFactor_f(z.Grow_0)[i]))
# UPDATE MASS BALANCE ON PONDED EFFLUENT
if (z.Temp[Y][i][j] <= 0 or InitSnow_f(z.NYrs, z.DaysMonth, z.InitSnow_0, z.Temp, z.Prec)[Y][i][j] > 0):
# ALL INPUTS GO TO FROZEN STORAGE
z.FrozenPondNitr = z.FrozenPondNitr + z.PondNitrLoad
z.FrozenPondPhos = z.FrozenPondPhos + z.PondPhosLoad
# NO NUTIENT OVERFLOW
z.NitrPondOverflow = 0
z.PhosPondOverflow = 0
else:
z.NitrPondOverflow = z.FrozenPondNitr + z.PondNitrLoad
z.PhosPondOverflow = z.FrozenPondPhos + z.PondPhosLoad
z.FrozenPondNitr = 0
z.FrozenPondPhos = 0
# Obtain the monthly Pond nutrients
z.MonthPondNitr[i] = z.MonthPondNitr[i] + z.NitrPondOverflow
z.MonthPondPhos[i] = z.MonthPondPhos[i] + z.PhosPondOverflow
# Obtain the monthly Normal Nitrogen
z.MonthNormNitr[i] = (z.MonthNormNitr[i] + z.NitrSepticLoad -
z.NitrPlantUptake * GrowFactor_f(z.Grow_0)[i])
# 0.56 IS ATTENUATION FACTOR FOR SOIL LOSS
# 0.66 IS ATTENUATION FACTOR FOR SUBSURFACE FLOW LOSS
z.MonthShortNitr[i] = (z.MonthShortNitr[i] + z.NitrSepticLoad -
z.NitrPlantUptake * GrowFactor_f(z.Grow_0)[i])
z.MonthShortPhos[i] = (z.MonthShortPhos[i] + z.PhosSepticLoad -
z.PhosPlantUptake * GrowFactor_f(z.Grow_0)[i])
z.MonthDischargeNitr[i] = z.MonthDischargeNitr[i] + z.NitrSepticLoad
z.MonthDischargePhos[i] = z.MonthDischargePhos[i] + z.PhosSepticLoad
# CALCULATE ANIMAL FEEDING OPERATIONS OUTPUT
AFOS_old.AnimalOperations(z, Y)
# CALCULATE NUTRIENT AND SEDIMENT LOADS
CalcLoads.CalculateLoads(z, Y)
# CALCULATE STREAM BANK EROSION
StreamBank.CalculateStreamBankEros(z, Y)
# CALCULATE FINAL ANNUAL MEAN LOADS
AnnualMeans.CalculateAnnualMeanLoads(z, Y)
# CALCULATE FINAL MONTHLY AND ANNUAL WATER BALANCE FOR
# AVERAGE STREAM FLOW
for i in range(12):
z.AvStreamFlow[i] = (
AvRunoff_f(z.NYrs, z.DaysMonth, z.Temp, z.InitSnow_0, z.Prec, z.NRur, z.NUrb, z.Area, z.CNI_0,
z.AntMoist_0, z.Grow_0, z.CNP_0, z.Imper, z.ISRR, z.ISRA, z.Qretention, z.PctAreaInfil,
z.n25b, z.CN, z.Landuse, z.TileDrainDensity)[i] +
AvGroundWater_f(z.NYrs, z.DaysMonth, z.Temp, z.InitSnow_0, z.Prec, z.NRur, z.NUrb, z.Area, z.CNI_0,
z.AntMoist_0, z.Grow_0, z.CNP_0, z.Imper, z.ISRR, z.ISRA, z.CN, z.UnsatStor_0, z.KV,
z.PcntET, z.DayHrs, z.MaxWaterCap,
z.SatStor_0, z.RecessionCoef, z.SeepCoef, z.Landuse, z.TileDrainDensity)[i] +
z.AvPtSrcFlow[i] +
AvTileDrain_f(z.NYrs, z.DaysMonth, z.Temp, z.InitSnow_0, z.Prec, z.NRur, z.NUrb, z.Area,
z.CNI_0, z.AntMoist_0, z.Grow_0, z.CNP_0, z.Imper,
z.ISRR, z.ISRA, z.CN, z.UnsatStor_0, z.KV, z.PcntET, z.DayHrs, z.MaxWaterCap,
z.SatStor_0, z.RecessionCoef, z.SeepCoef,
z.Landuse, z.TileDrainDensity)[i] -
AvWithdrawal_f(z.NYrs, z.StreamWithdrawal, z.GroundWithdrawal)[i])
z.AvCMStream[i] = (z.AvStreamFlow[i] / 100) * TotAreaMeters(z.NRur, z.NUrb, z.Area)
if z.AvCMStream[i] > 0:
z.AvOrgConc[i] = (z.AvTotalOrgs[i] / (z.AvCMStream[i] * 1000)) / 10
else:
z.AvOrgConc[i] = 0
z.AvOrgConc[0] = 0
z.AvStreamFlowSum = (z.AvRunoffSum + z.AvGroundWaterSum +
z.AvPtSrcFlowSum + z.AvTileDrainSum -
z.AvWithdrawalSum)
log.debug("Model run complete for " + str(z.NYrs) + " years of data.")
output = WriteOutputFiles.WriteOutput(z)
# WriteOutputFiles.WriteOutputSumFiles()
return output, z