-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTa_module_new.py
159 lines (131 loc) · 6.34 KB
/
Ta_module_new.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
# -*- coding: utf-8 -*-
"""
calculates canyon air temperature (Tac)
see section 3.5 tech notes for details
inputs:
H = average building height
W = average street width
qH = average sensible heat flux
Tsurf = average surface temperature
cs = constants dictionary
cfM = main control file
Dats = dates dictionary
obs = observed wind speed
i = current index
Outputs:
Ta_f = canyon air temperature (Tac)
Tb = air temperature above the canyon (Tb)
ra = resistance between the canyon and atmopshere
Ucan = canyon wind speed
"""
import math
from ..scripts.LcSort import lc_sort
from ..scripts.SfcRi import sfc_ri
from ..scripts.Httc import httc
import numpy as np
def calc_ta(cs, cfM, lc_data, grid, i, met_d, z_URef, z_Hx2, Tb_rur, mod_data_ts_, mod_rslts_prev, httc_rur):
metTa0 = met_d['Ta'][i]
metWS0 = met_d['WS'][i]
H = lc_data['H'][grid]
W = lc_data['W'][grid]
LC = [lc_data['roof'][grid], lc_data['road'][grid], lc_data['watr'][grid], lc_data['conc'][grid],
lc_data['Veg'][grid], lc_data['dry'][grid], lc_data['irr'][grid]]
lc_stuff = lc_sort(cs, LC, H, W)
# define surface temperature of trees as canyon air temperature
if i == 0 or mod_rslts_prev[i - 1][grid] == -999.0:
mod_data_ts_[i][9]['Veg'] = metTa0
else:
mod_data_ts_[i][9]['Veg'] = mod_rslts_prev[i - 1][grid]
LC = lc_stuff['LC']
LC_wRoofAvg = lc_stuff['LC_wRoofAvg']
fw = lc_stuff['fw']
fg = lc_stuff['fg']
zavg = cs['zavg']
if "zavg" in cfM.keys():
zavg = float(cfM['zavg'])
Hz = max(H, zavg)
z0m_urb = 0.1 * Hz
z0h_urb = z0m_urb / 10.0
Uz = max(metWS0 * (math.log(Hz / z0m_urb) / math.log(z_URef / z0m_urb)), 0.1)
lcStuffWTree = lc_stuff['Wtree']
Ucan = Uz * math.exp(-0.386 * (Hz / lcStuffWTree))
rs_can = cs['pa'] * cs['cpair'] / (11.8 + 4.2 * Ucan)
httc_can = 1.0 / rs_can
roofIndex = 0
roadIndex = 1
wallIndex = 7
dryIndex = 5
concIndex = 3
VegIndex = 4
irrIndex = 6
watrIndex = 2
LCroof = LC[roofIndex]
LCcan = LC[roadIndex] + LC[watrIndex] + LC[concIndex] + LC[VegIndex] + LC[dryIndex] + LC[irrIndex]
# LCcan = lc_data['road'][grid] + lc_data['watr'][grid] + lc_data['conc'][grid] + lc_data['Veg'][grid] + \
# lc_data['dry'][grid] + lc_data['irr'][grid]
LChorz = LCroof + LCcan
PlanCan = LCcan / LChorz
if i != 0 and mod_rslts_prev[i - 1][grid] != -999.0:
Tacprv = mod_rslts_prev[i - 1][grid]
roofTsrfT = mod_data_ts_[i - 1][9]['roof']
else:
Tacprv = metTa0
roofTsrfT = metTa0
Tac_can_roof = (LCroof / LChorz) * roofTsrfT + (LCcan / LChorz) * Tacprv
z_Hx2 = Hz * 2
dz = z_Hx2 - H - z0m_urb
# Uz = max(metWS0 * (math.log(z_Hx2 / z0m_urb) / math.log(z_URef / z0m_urb)), 0.1)
Ri_return = sfc_ri(dz, Tb_rur, Tac_can_roof, Uz)
Ri_urb_new = Ri_return['Ri']
httcReturn = httc(Ri_urb_new, Uz, dz, z0m_urb, z0h_urb, met_d, i)
httc_urb_new = httcReturn['httc']
Tsurf_can = (mod_data_ts_[i][9]['roof'] * LC[roofIndex] +
mod_data_ts_[i][fg]['conc'] * LC[concIndex] +
mod_data_ts_[i][fg]['road'] * LC[roadIndex] +
mod_data_ts_[i][fg]['watr'] * LC[watrIndex] +
mod_data_ts_[i][fg]['dry'] * LC[dryIndex] +
mod_data_ts_[i][fg]['irr'] * LC[irrIndex] +
mod_data_ts_[i][fw]['wall'] * LC[wallIndex] +
mod_data_ts_[i][9]['Veg'] * LC[VegIndex])
LcH = LC_wRoofAvg
Tsurf_horz = (mod_data_ts_[i][9]['roof'] * LcH[roofIndex] +
mod_data_ts_[i][fg]['conc'] * LcH[concIndex] +
mod_data_ts_[i][fg]['road'] * LcH[roadIndex] +
mod_data_ts_[i][fg]['watr'] * LcH[watrIndex] +
mod_data_ts_[i][fg]['dry'] * LcH[dryIndex] +
mod_data_ts_[i][fg]['irr'] * LcH[irrIndex] +
mod_data_ts_[i][9]['Veg'] * LcH[VegIndex])
Tsurf_wall = mod_data_ts_[i][fw]['wall']
if cfM['include roofs'] == "Y":
Tac = (mod_data_ts_[i][fg]['conc'] * httc_can * LC[concIndex] +
mod_data_ts_[i][9]['roof'] / (1 / httc_can + 1 / httc_urb_new) * LC[roofIndex]
+ mod_data_ts_[i][fg]['road'] * httc_can * LC[roadIndex]
+ mod_data_ts_[i][fg]['watr'] * httc_can * LC[watrIndex]
+ mod_data_ts_[i][fg]['dry'] * httc_can * LC[dryIndex]
+ mod_data_ts_[i][fg]['irr'] * httc_can * LC[irrIndex]
+ mod_data_ts_[i][fw]['wall'] * httc_can * LC[wallIndex]
+ mod_data_ts_[i][9]['Veg'] * httc_can * LC[VegIndex]
+ (Tb_rur * httc_urb_new * PlanCan)) / (
httc_can * LC[concIndex] + LC[roofIndex] / (1 / httc_can + 1 / httc_urb_new)
+ httc_can * LC[roadIndex] + httc_can * LC[watrIndex] + httc_can * LC[dryIndex]
+ httc_can * LC[irrIndex] + httc_can * LC[wallIndex] + httc_can * LC[VegIndex]
+ httc_urb_new * PlanCan)
else:
Tac = (mod_data_ts_[i][fg]['conc'] * httc_can * LC[concIndex]
+ mod_data_ts_[i][fg]['road'] * httc_can * LC[roadIndex]
+ mod_data_ts_[i][fg]['watr'] * httc_can * LC[watrIndex]
+ mod_data_ts_[i][fg]['dry'] * httc_can * LC[dryIndex]
+ mod_data_ts_[i][fg]['irr'] * httc_can * LC[irrIndex]
+ mod_data_ts_[i][fw]['wall'] * httc_can * LC[wallIndex]
+ mod_data_ts_[i][9]['Veg'] * httc_can * LC[VegIndex]
+ Tb_rur * httc_rur * PlanCan) / (
httc_can * LC[concIndex] + httc_can * LC[roadIndex] + httc_can * LC[watrIndex]
+ httc_can * LC[dryIndex] + httc_can * LC[irrIndex] + httc_can * LC[wallIndex]
+ httc_can * LC[VegIndex] + httc_rur * PlanCan)
if LC[roofIndex] > 0.75:
Tac = -999.0
Tsurf_horz = mod_data_ts_[i][9]['roof'] * LcH[roofIndex]
return {'Ucan': Ucan, 'Ts_horz': Tsurf_horz, 'Ts_can': Tsurf_can, 'Ts_wall': Tsurf_wall, 'Tac': Tac,
'Tac_can_roof': Tac_can_roof, 'roofTsrfT': roofTsrfT, 'Tacprv': Tacprv, 'Tcorrhi': Ri_return['Tcorrhi'],
'httc_urb_new': httc_urb_new, 'Fh': httcReturn['Fh'], 'httc_can': httc_can, 'Twall': Tsurf_wall, 'fg': fg,
'fw': fw}