def UrbanQTotal(NYrs, DaysMonth, NRur, NUrb, Temp, InitSnow_0, Prec, Area, CNI_0, AntMoist_0, Grow_0, CNP_0, Imper, ISRR, ISRA): nlu = NLU(NRur, NUrb) result = zeros((NYrs, 12, 31)) water = Water(NYrs, DaysMonth, InitSnow_0, Temp, Prec) urb_area_total = UrbAreaTotal(NRur, NUrb, Area) qrun_i = QrunI(NYrs, DaysMonth, NRur, NUrb, Temp, InitSnow_0, Prec, CNI_0, AntMoist_0, Grow_0) qrun_p = QrunP(NYrs, DaysMonth, NRur, NUrb, Temp, InitSnow_0, Prec, CNP_0, AntMoist_0, Grow_0) lu = LU(NRur, NUrb) for Y in range(NYrs): for i in range(12): for j in range(DaysMonth[Y][i]): if Temp[Y][i][j] > 0 and water[Y][i][j] > 0.01: if water[Y][i][j] < 0.05: pass else: for l in range(NRur, nlu): if urb_area_total > 0: result[Y][i][j] += ( (qrun_i[Y][i][j][l] * (Imper[l] * (1 - ISRR[lu[l]]) * (1 - ISRA[lu[l]])) + qrun_p[Y][i][j][l] * (1 - (Imper[l] * (1 - ISRR[lu[l]]) * (1 - ISRA[lu[l]])))) * Area[l] / urb_area_total) return result
def WashImperv_f(NYrs, DaysMonth, InitSnow_0, Temp, Prec, CNI_0, AntMoist_0, Grow_0, NRur, NUrb): nlu = NLU(NRur, NUrb) water = Water_f(NYrs, DaysMonth, InitSnow_0, Temp, Prec) qruni = QrunI_f(NYrs, DaysMonth, NRur, NUrb, Temp, InitSnow_0, Prec, CNI_0, AntMoist_0, Grow_0) return WashImperv_inner(NYrs, DaysMonth, Temp, NRur, nlu, water, qruni)
def CNI_f(NRur, NUrb, CNI_0): nlu = NLU(NRur, NUrb) result = zeros((3, nlu)) result[0] = CNI_0[1] / (2.334 - 0.01334 * CNI_0[1][1]) result[1] = CNI_0[1] result[2] = CNI_0[1] / (0.4036 + 0.0059 * CNI_0[1]) return result
def QrunI(NYrs, DaysMonth, NRur, NUrb, Temp, InitSnow_0, Prec, CNI_0, AntMoist_0, Grow_0): result = zeros((NYrs, 12, 31, 16)) # TODO: should this be nlu? nlu = NLU(NRur, NUrb) water = Water(NYrs, DaysMonth, InitSnow_0, Temp, Prec) cni = CNI(NRur, NUrb, CNI_0) c_num_imperv_reten = CNumImpervReten(NYrs, DaysMonth, Temp, Prec, InitSnow_0, AntMoist_0, NRur, NUrb, CNI_0, Grow_0) for Y in range(NYrs): for i in range(12): for j in range(DaysMonth[Y][i]): if Temp[Y][i][j] > 0 and water[Y][i][j] > 0.01: for l in range(NRur, nlu): # TODO: what is this for? result[Y][i][j][l] = 0 if water[Y][i][j] < 0.05: pass else: for l in range(NRur, nlu): if cni[1][l] > 0: if water[Y][i][j] >= 0.2 * c_num_imperv_reten[ Y][i][j][l]: result[Y][i][j][l] = ( water[Y][i][j] - 0.2 * c_num_imperv_reten[Y][i][j][l] )**2 / (water[Y][i][j] + 0.8 * c_num_imperv_reten[Y][i][j][l]) return result
def NetSolidLoad_f(NYrs, DaysMonth, Temp, InitSnow_0, Prec, NRur, NUrb, Area, CNI_0, AntMoist_0, Grow_0, CNP_0, Imper, ISRR, ISRA, Qretention, PctAreaInfil, Nqual, LoadRateImp, LoadRatePerv, Storm, UrbBMPRed, DisFract, FilterWidth, PctStrmBuf): nlu = NLU(NRur, NUrb) result = zeros((NYrs, 12, 31, nlu - NRur, Nqual)) water = Water_f(NYrs, DaysMonth, InitSnow_0, Temp, Prec) adjurbanqtotal = AdjUrbanQTotal_f(NYrs, DaysMonth, Temp, InitSnow_0, Prec, NRur, NUrb, Area, CNI_0, AntMoist_0, Grow_0, CNP_0, Imper, ISRR, ISRA, Qretention, PctAreaInfil) dissurfaceload = DisSurfLoad_f(NYrs, DaysMonth, InitSnow_0, Temp, Prec, Nqual, NRur, NUrb, Area, CNI_0, AntMoist_0, Grow_0, CNP_0, Imper, ISRR, ISRA, Qretention, PctAreaInfil, LoadRateImp, LoadRatePerv, Storm, UrbBMPRed, DisFract, FilterWidth, PctStrmBuf) surfaceload_1 = SurfaceLoad_1_f(NYrs, DaysMonth, InitSnow_0, Temp, Prec, NRur, NUrb, Area, CNI_0, AntMoist_0, Grow_0, CNP_0, Imper, ISRR, ISRA, Qretention, PctAreaInfil, Nqual, LoadRateImp, LoadRatePerv, Storm, UrbBMPRed, FilterWidth, PctStrmBuf) nonzero = where((Temp > 0) & (water > 0.01) & (adjurbanqtotal > 0.001)) result[nonzero] = surfaceload_1[nonzero] - dissurfaceload[nonzero] return sum(result, axis=3)
def WashPerv(NYrs, DaysMonth, InitSnow_0, Temp, Prec, CNP_0, AntMoist_0, Grow_0, NRur, NUrb): pervaccum = zeros(16) nlu = NLU(NRur, NUrb) water = Water(NYrs, DaysMonth, InitSnow_0, Temp, Prec) qrunp = QrunP(NYrs, DaysMonth, NRur, NUrb, Temp, InitSnow_0, Prec, CNP_0, AntMoist_0, Grow_0) washperv = zeros((NYrs, 12, 31, 16)) carryover = zeros(16) for Y in range(NYrs): for i in range(12): for j in range(DaysMonth[Y][i]): for l in range(nlu): pervaccum[l] = carryover[l] pervaccum[l] = (pervaccum[l] * exp(-0.12) + (1 / 0.12) * (1 - exp(-0.12))) if Temp[Y][i][j] > 0 and water[Y][i][j] > 0.01: if water[Y][i][j] < 0.05: pass else: for l in range(NRur, nlu): washperv[Y][i][j][l] = (1 - math.exp( -1.81 * qrunp[Y][i][j][l])) * pervaccum[l] pervaccum[l] -= washperv[Y][i][j][l] else: pass for l in range(nlu): carryover[l] = pervaccum[l] return washperv
def UrbQRunoff(NYrs, DaysMonth, InitSnow_0, Temp, Prec, NRur, NUrb, CNI_0, CNP_0, AntMoist_0, Grow_0, Imper, ISRR, ISRA): result = zeros((NYrs, 16, 12)) nlu = NLU(NRur, NUrb) water = Water(NYrs, DaysMonth, InitSnow_0, Temp, Prec) qruni = QrunI(NYrs, DaysMonth, NRur, NUrb, Temp, InitSnow_0, Prec, CNI_0, AntMoist_0, Grow_0) qrunp = QrunP(NYrs, DaysMonth, NRur, NUrb, Temp, InitSnow_0, Prec, CNP_0, AntMoist_0, Grow_0) lu = LU(NRur, NUrb) for Y in range(NYrs): for i in range(12): for l in range(nlu): result[Y, l, i] = 0 for Y in range(NYrs): for i in range(12): for j in range(DaysMonth[Y][i]): if Temp[Y][i][j] > 0 and water[Y][i][j] > 0.01: if water[Y][i][j] < 0.05: pass else: for l in range(NRur, nlu): result[Y][l][i] += (qruni[Y][i][j][l] * (Imper[l] * (1 - ISRR[lu[l]]) * (1 - ISRA[lu[l]])) + qrunp[Y][i][j][l] * (1 - (Imper[l] * (1 - ISRR[lu[l]]) * (1 - ISRA[lu[l]])))) else: pass return result
def LuTotPhos(NYrs, DaysMonth, InitSnow_0, Temp, Prec, AntMoist_0, NRur, NUrb, CN, Grow_0, Area, PhosConc, ManPhos, ManuredAreas, FirstManureMonth, LastManureMonth, FirstManureMonth2, LastManureMonth2, SedDelivRatio_0, KF, LS, C, P, CNP_0, Imper, ISRR, ISRA, Qretention, PctAreaInfil, Nqual, LoadRateImp, LoadRatePerv, Storm, UrbBMPRed, FilterWidth, PctStrmBuf, Acoef, SedPhos, CNI_0): result = zeros((NYrs, 16)) p_runoff = pRunoff(NYrs, DaysMonth, InitSnow_0, Temp, Prec, AntMoist_0, NRur, NUrb, CN, Grow_0, Area, PhosConc, ManuredAreas, FirstManureMonth, LastManureMonth, ManPhos, FirstManureMonth2, LastManureMonth2) sed_deliv_ratio = SedDelivRatio(SedDelivRatio_0) eros_washoff = ErosWashoff(NYrs, DaysMonth, InitSnow_0, Temp, Prec, NRur, NUrb, Acoef, KF, LS, C, P, Area) lu_load = LuLoad(NYrs, DaysMonth, Temp, InitSnow_0, Prec, NRur, NUrb, Area, CNI_0, AntMoist_0, Grow_0, CNP_0, Imper, ISRR, ISRA, Qretention, PctAreaInfil, Nqual, LoadRateImp, LoadRatePerv, Storm, UrbBMPRed, FilterWidth, PctStrmBuf) nlu = NLU(NRur, NUrb) for Y in range(NYrs): for i in range(12): # Add in the urban calucation for sediment for l in range(NRur): result[Y][l] += p_runoff[Y][i][l] result[Y][l] += 0.001 * sed_deliv_ratio * eros_washoff[Y][l][ i] * SedPhos for l in range(NRur, nlu): result[Y][l] += lu_load[Y][l][1] / NYrs / 2 return result
def SurfaceLoad_1_f(NYrs, DaysMonth, InitSnow_0, Temp, Prec, NRur, NUrb, Area, CNI_0, AntMoist_0, Grow_0, CNP_0, Imper, ISRR, ISRA, Qretention, PctAreaInfil, Nqual, LoadRateImp, LoadRatePerv, Storm, UrbBMPRed, FilterWidth, PctStrmBuf): nlu = NLU(NRur, NUrb) result = zeros((NYrs, 12, 31, nlu - NRur, Nqual)) water = Water_f(NYrs, DaysMonth, InitSnow_0, Temp, Prec) adjurbanqtotal = AdjUrbanQTotal_f(NYrs, DaysMonth, Temp, InitSnow_0, Prec, NRur, NUrb, Area, CNI_0, AntMoist_0, Grow_0, CNP_0, Imper, ISRR, ISRA, Qretention, PctAreaInfil) surfaceload = SurfaceLoad_f(NYrs, DaysMonth, InitSnow_0, Temp, Prec, NRur, NUrb, Area, CNI_0, AntMoist_0, Grow_0, CNP_0, Imper, ISRR, ISRA, Qretention, PctAreaInfil, Nqual, LoadRateImp, LoadRatePerv, Storm, UrbBMPRed) retentioneff = RetentionEff_f(NYrs, DaysMonth, InitSnow_0, Temp, Prec, Qretention, NRur, NUrb, Area, CNI_0, AntMoist_0, Grow_0, CNP_0, Imper, ISRR, ISRA, PctAreaInfil)[:, :, :, None, None] retentioneff = repeat(repeat(retentioneff, nlu - NRur, axis=3), Nqual, axis=4) filtereff = FilterEff_f(FilterWidth) nonzero = where((Temp > 0) & (water > 0.01) & (adjurbanqtotal > 0.001)) result[nonzero] = surfaceload[nonzero] * (1 - retentioneff[nonzero]) * ( 1 - (filtereff * PctStrmBuf)) return result
def RurQRunoff(NYrs, DaysMonth, InitSnow_0, Temp, Prec, AntMoist_0, NRur, NUrb, CN, Grow_0): result = zeros((NYrs, 16, 12)) nlu = NLU(NRur, NUrb) water = Water(NYrs, DaysMonth, InitSnow_0, Temp, Prec) retention = Retention(NYrs, DaysMonth, Temp, Prec, InitSnow_0, AntMoist_0, NRur, NUrb, CN, Grow_0) qrun = Qrun(NYrs, DaysMonth, Temp, InitSnow_0, Prec, NRur, NUrb, CN, AntMoist_0, Grow_0) for Y in range(NYrs): for i in range(12): for l in range(nlu): result[Y, l, i] = 0.0 for Y in range(NYrs): for i in range(12): for j in range(DaysMonth[Y][i]): if Temp[Y][i][j] > 0 and water[Y][i][j] > 0.01: for l in range(NRur): if CN[l] > 0: if water[Y][i][j] >= 0.2 * retention[Y][i][j][l]: result[Y][l][i] += qrun[Y][i][j][l] else: pass else: pass else: pass return result
def NewCN_f(NRur, NUrb, CN): nlu = NLU(NRur, NUrb) result = zeros((3, nlu)) result[0, :] = CN / (2.334 - 0.01334 * CN) result[2, :] = CN / (0.4036 + 0.0059 * CN) result[2, :][where(result[2, :] > 100)] = 100 return result
def WashImperv(NYrs, DaysMonth, InitSnow_0, Temp, Prec, CNI_0, AntMoist_0, Grow_0, NRur, NUrb): result = zeros((NYrs, 12, 31, 16)) impervaccum = zeros(16) carryover = zeros(16) nlu = NLU(NRur, NUrb) water = Water(NYrs, DaysMonth, InitSnow_0, Temp, Prec) qruni = QrunI(NYrs, DaysMonth, NRur, NUrb, Temp, InitSnow_0, Prec, CNI_0, AntMoist_0, Grow_0) for Y in range(NYrs): for i in range(12): for j in range(DaysMonth[Y][i]): for l in range(nlu): impervaccum[l] = carryover[l] impervaccum[l] = (impervaccum[l] * exp(-0.12) + (1 / 0.12) * (1 - exp(-0.12))) if Temp[Y][i][j] > 0 and water[Y][i][j] > 0.01: if water[Y][i][j] < 0.05: pass else: for l in range(NRur, nlu): result[Y][i][j][l] = (1 - math.exp( -1.81 * qruni[Y][i][j][l])) * impervaccum[l] impervaccum[l] -= result[Y][i][j][l] else: pass for l in range(nlu): carryover[l] = impervaccum[l] return result
def LuLoad(NYrs, DaysMonth, Temp, InitSnow_0, Prec, NRur, NUrb, Area, CNI_0, AntMoist_0, Grow_0, CNP_0, Imper, ISRR, ISRA, Qretention, PctAreaInfil, Nqual, LoadRateImp, LoadRatePerv, Storm, UrbBMPRed, FilterWidth, PctStrmBuf): result = zeros((NYrs, 16, 3)) water = Water(NYrs, DaysMonth, InitSnow_0, Temp, Prec) nlu = NLU(NRur, NUrb) adjurbanqtotal = AdjUrbanQTotal(NYrs, DaysMonth, Temp, InitSnow_0, Prec, NRur, NUrb, Area, CNI_0, AntMoist_0, Grow_0, CNP_0, Imper, ISRR, ISRA, Qretention, PctAreaInfil) surfaceload_1 = SurfaceLoad_1(NYrs, DaysMonth, InitSnow_0, Temp, Prec, NRur, NUrb, Area, CNI_0, AntMoist_0, Grow_0, CNP_0, Imper, ISRR, ISRA, Qretention, PctAreaInfil, Nqual, LoadRateImp, LoadRatePerv, Storm, UrbBMPRed, FilterWidth, PctStrmBuf) for Y in range(NYrs): for i in range(12): for j in range(DaysMonth[Y][i]): if Temp[Y][i][j] > 0 and water[Y][i][j] > 0.01: if adjurbanqtotal[Y][i][j] > 0.001: for l in range(NRur, nlu): for q in range(Nqual): result[Y][l][q] += surfaceload_1[Y][i][j][l][q] else: pass else: pass return result
def CNI(NRur, NUrb, CNI_0): nlu = NLU(NRur, NUrb) result = zeros((3, nlu)) for l in range(NRur, nlu): result[0][l] = CNI_0[1][l] / (2.334 - 0.01334 * CNI_0[1][1]) result[1][l] = CNI_0[1][l] result[2][l] = CNI_0[1][l] / (0.4036 + 0.0059 * CNI_0[1][l]) return result
def CNumPerv_f(NYrs, DaysMonth, Temp, NRur, NUrb, CNP_0, InitSnow_0, Prec, Grow_0, AntMoist_0): nlu = NLU(NRur, NUrb) cnp = CNP_f(NRur, NUrb, CNP_0) water = Water_f(NYrs, DaysMonth, InitSnow_0, Temp, Prec) melt = Melt_1_f(NYrs, DaysMonth, InitSnow_0, Temp, Prec) grow_factor = GrowFactor(Grow_0) # TODO: some bug in cnumperv_inner causes an error if this is switched to _f amc5 = AMC5_yesterday(NYrs, DaysMonth, Temp, Prec, InitSnow_0, AntMoist_0) return CNumPerv_inner(NYrs, DaysMonth, Temp, NRur, nlu, cnp, water, melt, grow_factor, amc5)
def AreaTotal(NRur, NUrb, Area): result = 0 nlu = NLU(NRur, NUrb) for l in range(NRur): result += Area[l] for l in range(NRur, nlu): result += Area[l] return result
def NewCN(NRur, NUrb, CN): nlu = NLU(NRur, NUrb) result = zeros((3, nlu)) for l in range(NRur): result[0][l] = CN[l] / (2.334 - 0.01334 * CN[l]) result[2][l] = CN[l] / (0.4036 + 0.0059 * CN[l]) if result[2][l] > 100: result[2][l] = 100 return result
def SurfaceLoad(NYrs, DaysMonth, InitSnow_0, Temp, Prec, NRur, NUrb, Area, CNI_0, AntMoist_0, Grow_0, CNP_0, Imper, ISRR, ISRA, Qretention, PctAreaInfil, Nqual, LoadRateImp, LoadRatePerv, Storm, UrbBMPRed): result = zeros((NYrs, 12, 31, 16, Nqual)) water = Water(NYrs, DaysMonth, InitSnow_0, Temp, Prec) adjurbanqtotal = AdjUrbanQTotal(NYrs, DaysMonth, Temp, InitSnow_0, Prec, NRur, NUrb, Area, CNI_0, AntMoist_0, Grow_0, CNP_0, Imper, ISRR, ISRA, Qretention, PctAreaInfil) nlu = NLU(NRur, NUrb) washimperv = WashImperv(NYrs, DaysMonth, InitSnow_0, Temp, Prec, CNI_0, AntMoist_0, Grow_0, NRur, NUrb) washperv = WashPerv(NYrs, DaysMonth, InitSnow_0, Temp, Prec, CNP_0, AntMoist_0, Grow_0, NRur, NUrb) lu_1 = LU_1(NRur, NUrb) urbloadred = UrbLoadRed(NYrs, DaysMonth, InitSnow_0, Temp, Prec, NRur, NUrb, Area, CNI_0, AntMoist_0, Grow_0, CNP_0, Imper, ISRR, ISRA, Qretention, PctAreaInfil, Nqual, Storm, UrbBMPRed) for Y in range(NYrs): for i in range(12): for j in range(DaysMonth[Y][i]): if Temp[Y][i][j] > 0 and water[Y][i][j] > 0.01: if adjurbanqtotal[Y][i][j] > 0.001: for l in range(NRur, nlu): for q in range(Nqual): if Area[l] > 0: result[Y][i][j][l][q] = ((( LoadRateImp[l][q] * washimperv[Y][i][j][l] * ((Imper[l] * (1 - ISRR[lu_1[l]]) * (1 - ISRA[lu_1[l]])) # * (SweepFrac[i] + ( # (1 - SweepFrac[i]) * ((1 - UrbSweepFrac) * Area[l]) / Area[l])) * 1 ) # TODO For some reason, this commented out code always needs to evaluate to 1 in order for the separation to occur + LoadRatePerv[l][q] * washperv[Y][i][j][l] * (1 - (Imper[l] * (1 - ISRR[lu_1[l]]) * (1 - ISRA[lu_1[l]])))) * Area[l]) - urbloadred[Y][i] [j][l][q]) else: result[Y][i][j][l][q] = 0 if result[Y][i][j][l][q] < 0: result[Y][i][j][l][q] = 0 else: pass else: pass else: pass return result
def CNumImperv_f(NYrs, NRur, NUrb, DaysMonth, InitSnow_0, Temp, Prec, CNI_0, Grow_0, AntMoist_0): nlu = NLU(NRur, NUrb) cni = CNI_f(NRur, NUrb, CNI_0) water = Water_f(NYrs, DaysMonth, InitSnow_0, Temp, Prec) melt = Melt_1_f(NYrs, DaysMonth, InitSnow_0, Temp, Prec) grow_factor = GrowFactor_f(Grow_0) amc5 = AMC5_yesterday(NYrs, DaysMonth, Temp, Prec, InitSnow_0, AntMoist_0) return CNumImperv_inner(NYrs, NRur, DaysMonth, Temp, nlu, cni, water, melt, grow_factor, amc5)
def NConc(NRur, NUrb, NitrConc, ManNitr, ManuredAreas, FirstManureMonth, LastManureMonth, FirstManureMonth2, LastManureMonth2): nlu = NLU(NRur, NUrb) result = zeros((12, nlu)) for i in range(12): for l in range(NRur): result[i][l] = NitrConc[l] if l < ManuredAreas and i >= FirstManureMonth and i <= LastManureMonth: result[i][l] = ManNitr[l] if l < ManuredAreas and i >= FirstManureMonth2 and i <= LastManureMonth2: result[i][l] = ManNitr[l] return result
def AvCNUrb(NRur, NUrb, CNI_0, CNP_0, Imper, Area): result = 0 nlu = NLU(NRur, NUrb) cni = CNI(NRur, NUrb, CNI_0) cnp = CNP(NRur, NUrb, CNP_0) urbareatotal = UrbAreaTotal(NRur, NUrb, Area) for l in range(NRur, nlu): # Calculate average area-weighted CN for urban areas if urbareatotal > 0: result += ((Imper[l] * cni[1][l] + (1 - Imper[l]) * cnp[1][l]) * Area[l] / urbareatotal) return result
def PConc(NRur, NUrb, PhosConc, ManPhos, ManuredAreas, FirstManureMonth, LastManureMonth, FirstManureMonth2, LastManureMonth2): nlu = NLU(NRur, NUrb) result = zeros((12, nlu)) for i in range(12): for l in range(NRur): result[i][l] = PhosConc[l] # MANURE SPREADING DAYS FOR FIRST SPREADING PERIOD if l < ManuredAreas and i >= FirstManureMonth and i <= LastManureMonth: result[i][l] = ManPhos[l] # MANURE SPREADING DAYS FOR SECOND SPREADING PERIOD if l < ManuredAreas and i >= FirstManureMonth2 and i <= LastManureMonth2: result[i][l] = ManPhos[l] return result
def Retention_f(NYrs, DaysMonth, Temp, Prec, InitSnow_0, AntMoist_0, NRur, NUrb, CN, Grow_0): nlu = NLU(NRur, NUrb) result = zeros((NYrs, 12, 31, nlu)) c_num = CNum_f(NYrs, DaysMonth, Temp, Prec, InitSnow_0, AntMoist_0, CN, NRur, NUrb, Grow_0) cnrur = tile(CN[:NRur][None, None, None, :], (NYrs, 12, 31, 1)) water = repeat(Water_f(NYrs, DaysMonth, InitSnow_0, Temp, Prec)[:, :, :, None], NRur, axis=3) TempE = repeat(Temp[:, :, :, None], NRur, axis=3) result[where((TempE > 0) & (water > 0.01) & (cnrur > 0))] = 2540 / c_num[where( (TempE > 0) & (water > 0.01) & (cnrur > 0))] - 25.4 result[where(result < 0)] = 0 return result
def CNumPerv(NYrs, DaysMonth, Temp, NRur, NUrb, CNP_0, InitSnow_0, Prec, Grow_0, AntMoist_0): nlu = NLU(NRur, NUrb) result = zeros((NYrs, 12, 31, nlu)) cnp = CNP(NRur, NUrb, CNP_0) water = Water(NYrs, DaysMonth, InitSnow_0, Temp, Prec) melt = Melt(NYrs, DaysMonth, Temp, InitSnow_0, Prec) grow_factor = GrowFactor(Grow_0) amc5 = AMC5(NYrs, DaysMonth, Temp, Prec, InitSnow_0, AntMoist_0) for Y in range(NYrs): for i in range(12): for j in range(DaysMonth[Y][i]): if Temp[Y][i][j] > 0 and water[Y][i][j] > 0.01: if water[Y][i][j] < 0.05: pass else: for l in range(NRur, nlu): if cnp[1][l] > 0: if melt[Y][i][j] <= 0: if grow_factor[i] > 0: # Growing season if get_value_for_yesterday(amc5, 0, Y, i, j, DaysMonth) >= 5.33: result[Y][i][j][l] = cnp[2][l] elif get_value_for_yesterday(amc5, 0, Y, i, j, DaysMonth) < 3.56: result[Y][i][j][l] = cnp[0][l] + ( cnp[1][l] - cnp[0][l]) * \ get_value_for_yesterday(amc5, 0, Y, i, j, DaysMonth) / 3.56 else: result[Y][i][j][l] = cnp[1][l] + (cnp[2][l] - cnp[1][l]) * ( get_value_for_yesterday(amc5, 0, Y, i, j, DaysMonth) - 3.56) / 1.77 else: # Dormant season if get_value_for_yesterday(amc5, 0, Y, i, j, DaysMonth) >= 2.79: result[Y][i][j][l] = cnp[2][l] elif get_value_for_yesterday(amc5, 0, Y, i, j, DaysMonth) < 1.27: result[Y][i][j][l] = cnp[0][l] + ( cnp[1][l] - cnp[0][l]) * \ get_value_for_yesterday(amc5, 0, Y, i, j, DaysMonth) / 1.27 else: result[Y][i][j][l] = cnp[1][l] + (cnp[2][l] - cnp[1][l]) * ( get_value_for_yesterday(amc5, 0, Y, i, j, DaysMonth) - 1.27) / 1.52 else: result[Y][i][j][l] = cnp[2][l] return result
def LuRunoff(NYrs, DaysMonth, InitSnow_0, Temp, Prec, NRur, NUrb, CNI_0, CNP_0, AntMoist_0, Grow_0, Imper, ISRR, ISRA, CN): result = zeros((NYrs, 16)) nlu = NLU(NRur, NUrb) urb_q_runoff = UrbQRunoff(NYrs, DaysMonth, InitSnow_0, Temp, Prec, NRur, NUrb, CNI_0, CNP_0, AntMoist_0, Grow_0, Imper, ISRR, ISRA) rur_q_runoff = RurQRunoff(NYrs, DaysMonth, InitSnow_0, Temp, Prec, AntMoist_0, NRur, NUrb, CN, Grow_0) for Y in range(NYrs): for i in range(12): # Calculate landuse runoff for rural areas for l in range(NRur): result[Y][l] += rur_q_runoff[Y][l][i] for i in range(12): # Calculate landuse runoff for urban areas for l in range(NRur, nlu): result[Y][l] += urb_q_runoff[Y][l][i] return result
def Qrun_f(NYrs, DaysMonth, Temp, InitSnow_0, Prec, NRur, NUrb, CN, AntMoist_0, Grow_0): nlu = NLU(NRur, NUrb) result = zeros((NYrs, 12, 31, nlu)) water = repeat(Water_f(NYrs, DaysMonth, InitSnow_0, Temp, Prec)[:, :, :, None], nlu, axis=3) TempE = repeat(Temp[:, :, :, None], nlu, axis=3) cnrur = tile(CN[None, None, None, :], (NYrs, 12, 31, 1)) retention = Retention_f(NYrs, DaysMonth, Temp, Prec, InitSnow_0, AntMoist_0, NRur, NUrb, CN, Grow_0) retention02 = 0.2 * retention nonzero = where((TempE > 0) & (water > 0.01) & (water >= retention02) & (cnrur > 0)) result[nonzero] = (water[nonzero] - retention02[nonzero])**2 / ( water[nonzero] + 0.8 * retention[nonzero]) return result
def Retention(NYrs, DaysMonth, Temp, Prec, InitSnow_0, AntMoist_0, NRur, NUrb, CN, Grow_0): nlu = NLU(NRur, NUrb) result = zeros((NYrs, 12, 31, nlu)) # Why nlu ? c_num = CNum(NYrs, DaysMonth, Temp, Prec, InitSnow_0, AntMoist_0, CN, NRur, NUrb, Grow_0) water = Water(NYrs, DaysMonth, InitSnow_0, Temp, Prec) for Y in range(NYrs): for i in range(12): for j in range(DaysMonth[Y][i]): if Temp[Y][i][j] > 0 and water[Y][i][j] > 0.01: for l in range(NRur): if CN[l] > 0: # TODO:CN is set to zero in datamodel result[Y][i][j][ l] = 2540 / c_num[Y][i][j][l] - 25.4 if result[Y][i][j][l] < 0: result[Y][i][j][l] = 0 return result
def CNumImpervReten_f(NYrs, DaysMonth, Temp, Prec, InitSnow_0, AntMoist_0, NRur, NUrb, CNI_0, Grow_0): cni = CNI_f(NRur, NUrb, CNI_0) cni_1 = tile(cni[1][None, None, None, :], (NYrs, 12, 31, 1)) c_num_imperv = CNumImperv_f(NYrs, NRur, NUrb, DaysMonth, InitSnow_0, Temp, Prec, CNI_0, Grow_0, AntMoist_0) nlu = NLU(NRur, NUrb) water = repeat(Water_f(NYrs, DaysMonth, InitSnow_0, Temp, Prec)[:, :, :, None], nlu, axis=3) result = zeros((NYrs, 12, 31, nlu)) TempE = repeat(Temp[:, :, :, None], nlu, axis=3) result[where((TempE > 0) & (water >= 0.05) & (cni_1 > 0))] = 2540 / c_num_imperv[where( (TempE > 0) & (water >= 0.05) & (cni_1 > 0))] - 25.4 result[where(result < 0)] = 0 return result
def QrunP_f(NYrs, DaysMonth, NRur, NUrb, Temp, InitSnow_0, Prec, CNP_0, AntMoist_0, Grow_0): nlu = NLU(NRur, NUrb) result = zeros((NYrs, 12, 31, nlu)) water = repeat(Water_f(NYrs, DaysMonth, InitSnow_0, Temp, Prec)[:, :, :, None], nlu, axis=3) TempE = repeat(Temp[:, :, :, None], nlu, axis=3) c_num_perv_reten = CNumPervReten_f(NYrs, DaysMonth, Temp, Prec, InitSnow_0, AntMoist_0, NRur, NUrb, CNP_0, Grow_0) c_num_perv_reten02 = 0.2 * c_num_perv_reten cnp = CNP_f(NRur, NUrb, CNP_0) cnp_1 = tile(cnp[1][None, None, None, :], (NYrs, 12, 31, 1)) nonzero = where((TempE > 0) & (water >= 0.05) & (cnp_1 > 0) & (water >= c_num_perv_reten02)) result[nonzero] = (water[nonzero] - c_num_perv_reten02[nonzero])**2 / ( water[nonzero] + 0.8 * c_num_perv_reten[nonzero]) return result
def ErosWashoff(NYrs, DaysMonth, InitSnow_0, Temp, Prec, NRur, NUrb, Acoef, KF, LS, C, P, Area): result = zeros((NYrs, 16, 12)) nlu = NLU(NRur, NUrb) water = Water(NYrs, DaysMonth, InitSnow_0, Temp, Prec) rureros = RurEros(NYrs, DaysMonth, Temp, InitSnow_0, Prec, Acoef, NRur, KF, LS, C, P, Area) for Y in range(NYrs): for i in range(12): for l in range(nlu): result[Y, l, i] = 0 for Y in range(NYrs): for i in range(12): for j in range(DaysMonth[Y][i]): if Temp[Y][i][j] > 0 and water[Y][i][j] > 0.01: for l in range(NRur): result[Y][l][i] = result[Y][l][i] + rureros[Y][i][j][l] else: pass return result