-
Notifications
You must be signed in to change notification settings - Fork 0
/
pm_retention.py
199 lines (171 loc) · 6.5 KB
/
pm_retention.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
"""
Code specific for the air regulation model
"""
import pcraster as pcr
from ... import checked_call2, validate
from .. import project
from ..io import IO
@checked_call2
def wrapper(project_file_pathname):
"""
Calculate air regulation by vegetation
:param str project_file_pathname: Name of project file
"""
configuration = project.configuration(project_file_pathname)
io = IO(configuration)
# Inputs
land_cover_pathname = configuration.input_raster_pathname(
"pm_retention", "land_cover"
)
pm_10_pathname = configuration.input_raster_pathname("pm_retention", "pm_10")
pm_25_pathname = configuration.input_raster_pathname("pm_retention", "pm_25")
trees_pathname = configuration.input_raster_pathname("pm_retention", "trees")
shrubs_pathname = configuration.input_raster_pathname("pm_retention", "shrubs")
grass_pathname = configuration.input_raster_pathname("pm_retention", "grass")
resuspension_fractionpm10 = configuration.float_value(
"pm_retention", "resuspension_fractionpm10"
)
resuspension_fractionpm25 = configuration.float_value(
"pm_retention", "resuspension_fractionpm25"
)
deposition_lut_pathname = configuration.input_table_pathname(
"pm_retention", "deposition_lut"
)
deposition_tree_lut_pathname = configuration.input_table_pathname(
"pm_retention", "deposition_tree_lut"
)
resuspension_fractionpm10_lut_pathname = configuration.input_table_pathname(
"pm_retention", "resuspension_fractionpm10_lut"
)
resuspension_fractionpm25_lut_pathname = configuration.input_table_pathname(
"pm_retention", "resuspension_fractionpm25_lut"
)
# Outputs
capture_pm10_pathname = configuration.output_raster_pathname(
"pm_retention", "capture_pm10"
)
capture_pm25_pathname = configuration.output_raster_pathname(
"pm_retention", "capture_pm25"
)
map_total_pm10_pathname = configuration.output_raster_pathname(
"pm_retention", "map_total_pm10"
)
map_total_pm25_pathname = configuration.output_raster_pathname(
"pm_retention", "map_total_pm25"
)
land_cover = io.read_raster(land_cover_pathname)
pm_10 = io.read_raster(pm_10_pathname)
pm_25 = io.read_raster(pm_25_pathname)
# Fill no-data cells with zero
trees = io.read_raster(trees_pathname)
trees = pcr.ifthenelse(pcr.defined(trees), trees, 0.0)
shrubs = io.read_raster(shrubs_pathname)
shrubs = pcr.ifthenelse(pcr.defined(shrubs), shrubs, 0.0)
grass = io.read_raster(grass_pathname)
grass = pcr.ifthenelse(pcr.defined(grass), grass, 0.0)
deposition_velocity = pcr.lookupscalar(deposition_lut_pathname, land_cover)
deposition_velocity_trees = pcr.lookupscalar(
deposition_tree_lut_pathname, land_cover
)
resuspension_fractionpm10 = pcr.lookupscalar(
resuspension_fractionpm10_lut_pathname, land_cover
)
resuspension_fractionpm25 = pcr.lookupscalar(
resuspension_fractionpm25_lut_pathname, land_cover
)
(
capture_pm10,
capture_pm25,
map_total_pm10,
map_total_pm25,
) = function(
land_cover,
pm_10,
pm_25,
trees,
shrubs,
grass,
resuspension_fractionpm10,
resuspension_fractionpm25,
deposition_velocity,
deposition_velocity_trees,
)
io.write_raster(capture_pm10, capture_pm10_pathname)
io.write_raster(capture_pm25, capture_pm25_pathname)
io.write_raster(map_total_pm10, map_total_pm10_pathname)
io.write_raster(map_total_pm25, map_total_pm25_pathname)
def function(
land_cover, # pylint: disable=unused-argument
pm_10_concentration,
pm_25_concentration,
trees,
shrubs,
grass,
resuspension_fractionpm10,
resuspension_fractionpm25,
deposition_velocity,
deposition_velocity_trees,
):
"""
Calculate health effects of green space
:param nominal_raster land_cover: Land cover
:param scalar_raster pm_10_concentration: Concentration of PM10
:param scalar_raster trees: Percentage coverage by vegetation > 2.5m
:param scalar_raster shrubs: Percentage coverage by vegetation 1-2.5m
:param scalar_raster grass: Percentage coverage by vegetation < 1m
:param float resuspension_fraction: Fraction resuspension
:param scalar_raster deposition_velocity: Deposition velocities for
non-trees (m/s)
:param scalar_raster deposition_velocity_trees: Deposition velocities
for trees (m/s)
:return: Tuple of
- Amount of PM10 captured by vegetation (kg/ha/yr)
- Amount of PM2.5 captured by vegetation (kg/ha/yr)
:rtype: tuple of scalar rasters
"""
validate.in_range([trees, shrubs, grass], 0, 1)
validate.in_range([resuspension_fractionpm10], 0, 1)
validate.in_range([resuspension_fractionpm25], 0, 1)
validate.greater_equal_than([deposition_velocity, deposition_velocity_trees], 0)
cell_size = pcr.cellvalue(pcr.celllength(), 0)[0]
vegetated = trees + shrubs + grass
vegetated = pcr.ifthenelse(vegetated > 1, 1, vegetated)
non_vegetated = 1.0 - vegetated
deposition_velocity = (
trees * deposition_velocity_trees
+ shrubs * 0.3
+ grass * 0.2
+ non_vegetated * deposition_velocity
)
pm_10_concentration = pcr.windowaverage(pm_10_concentration, 2 * 100 + cell_size)
pm_25_concentration = pcr.windowaverage(pm_25_concentration, 2 * 100 + cell_size)
validate.greater_equal_than(pm_10_concentration, -1e-5)
pm_10_concentration = pcr.ifthenelse(
pm_10_concentration < 0, 0, pm_10_concentration
)
pm_25_concentration = pcr.ifthenelse(
pm_25_concentration < 0, 0, pm_25_concentration
)
# Conversion factor from cm/s * μg/m³ → kg/dam2/yr
unit_conversion = 0.031536
capture_pm10 = (
deposition_velocity
* pm_10_concentration
* (1 - resuspension_fractionpm10)
* unit_conversion
)
capture_pm25 = (
deposition_velocity
* 0.2
* pm_25_concentration
* (1 - resuspension_fractionpm25)
* unit_conversion
)
map_total_pm10 = pcr.maptotal(capture_pm10)
map_total_pm25 = pcr.maptotal(capture_pm25)
return (
capture_pm10,
capture_pm25,
map_total_pm10,
map_total_pm25,
)