-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathozark_pmodel.jl
More file actions
309 lines (284 loc) · 7.39 KB
/
ozark_pmodel.jl
File metadata and controls
309 lines (284 loc) · 7.39 KB
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
import SciMLBase
import ClimaComms
ClimaComms.@import_required_backends
using ClimaCore
import ClimaParams as CP
using Dates
using ClimaDiagnostics
using ClimaUtilities
using ClimaLand
using ClimaLand.Domains: Column
using ClimaLand.Snow
using ClimaLand.Soil
using ClimaLand.Soil.Biogeochemistry
using ClimaLand.Canopy
using ClimaLand.Canopy.PlantHydraulics
import ClimaLand
import ClimaLand.Parameters as LP
using ClimaLand.Simulations: LandSimulation, solve!
import ClimaLand.FluxnetSimulations as FluxnetSimulations
using CairoMakie, ClimaAnalysis, GeoMakie, Printf, StatsBase
import ClimaLand.LandSimVis as LandSimVis
const FT = Float64
toml_dict = LP.create_toml_dict(FT)
climaland_dir = pkgdir(ClimaLand)
prognostic_land_components = (:canopy, :snow, :soil, :soilco2)
site_ID = "US-MOz"
site_ID_val = FluxnetSimulations.replace_hyphen(site_ID)
# Get the default values for this site's domain, location, and parameters
(; dz_tuple, nelements, zmin, zmax) =
FluxnetSimulations.get_domain_info(FT, Val(site_ID_val))
(; time_offset, lat, long) =
FluxnetSimulations.get_location(FT, Val(site_ID_val))
(; atmos_h) = FluxnetSimulations.get_fluxtower_height(FT, Val(site_ID_val))
(;
soil_ν,
soil_K_sat,
soil_S_s,
soil_vg_n,
soil_vg_α,
θ_r,
ν_ss_quartz,
ν_ss_om,
ν_ss_gravel,
z_0m_soil,
z_0b_soil,
soil_ϵ,
soil_α_PAR,
soil_α_NIR,
Ω,
χl,
α_PAR_leaf,
λ_γ_PAR,
τ_PAR_leaf,
α_NIR_leaf,
τ_NIR_leaf,
ϵ_canopy,
ac_canopy,
g1,
Drel,
g0,
Vcmax25,
SAI,
f_root_to_shoot,
K_sat_plant,
ψ63,
Weibull_param,
a,
conductivity_model,
retention_model,
plant_ν,
plant_S_s,
rooting_depth,
n_stem,
n_leaf,
h_leaf,
h_stem,
h_canopy,
) = FluxnetSimulations.get_parameters(FT, Val(site_ID_val))
# Construct the ClimaLand domain to run the simulation on
land_domain = Column(;
zlim = (zmin, zmax),
nelements = nelements,
dz_tuple = dz_tuple,
longlat = (long, lat),
)
surface_domain = ClimaLand.Domains.obtain_surface_domain(land_domain)
# Set up the timestepping information for the simulation
dt = Float64(450) # 7.5 minutes
# This reads in the data from the flux tower site and creates
# the atmospheric and radiative driver structs for the model
(data_start, data_stop) = FluxnetSimulations.get_data_dates(site_ID, time_offset)
# Constrain to 2000-2020 (MODIS LAI availability) and skip first day
# so TimeVaryingInputs have data before t=0 even if initial rows are missing
start_date = max(data_start + Day(1), DateTime(2000, 1, 1))
stop_date = min(data_stop, DateTime(2020, 12, 31, 23, 59, 59))
# This reads in the data from the flux tower site and creates
# the atmospheric and radiative driver structs for the model
(; atmos, radiation) = FluxnetSimulations.prescribed_forcing_fluxnet(
site_ID,
lat,
long,
time_offset,
atmos_h,
start_date,
toml_dict,
FT,
)
# Now we set up the model. For the soil model, we pick
# a model type and package up parameters.
soil_domain = land_domain
soil_albedo = Soil.ConstantTwoBandSoilAlbedo{FT}(;
PAR_albedo = soil_α_PAR,
NIR_albedo = soil_α_NIR,
)
forcing = (; atmos, radiation)
retention_parameters = (;
ν = soil_ν,
θ_r,
K_sat = soil_K_sat,
hydrology_cm = vanGenuchten{FT}(; α = soil_vg_α, n = soil_vg_n),
)
composition_parameters = (; ν_ss_om, ν_ss_quartz, ν_ss_gravel)
soil = Soil.EnergyHydrology{FT}(
soil_domain,
forcing,
toml_dict;
prognostic_land_components,
additional_sources = (ClimaLand.RootExtraction{FT}(),),
albedo = soil_albedo,
runoff = ClimaLand.Soil.Runoff.SurfaceRunoff(),
retention_parameters,
composition_parameters,
S_s = soil_S_s,
z_0m = z_0m_soil,
z_0b = z_0b_soil,
emissivity = soil_ϵ,
)
# Soil microbes model
co2_prognostic_soil = Soil.Biogeochemistry.PrognosticMet(soil.parameters)
drivers = Soil.Biogeochemistry.SoilDrivers(co2_prognostic_soil, atmos)
soilco2 = Soil.Biogeochemistry.SoilCO2Model{FT}(soil_domain, drivers, toml_dict)
# Now we set up the canopy model, one component at a time.
# Set up radiative transfer
radiation_parameters = (;
Ω,
G_Function = CLMGFunction(χl),
α_PAR_leaf,
τ_PAR_leaf,
α_NIR_leaf,
τ_NIR_leaf,
)
radiative_transfer = Canopy.TwoStreamModel{FT}(
surface_domain,
toml_dict;
radiation_parameters,
ϵ_canopy,
)
# Set up conductance
conductance = PModelConductance{FT}(toml_dict)
# Set up photosynthesis
is_c3 = FT(1)
photosynthesis = PModel{FT}(surface_domain, toml_dict; is_c3)
# Set up soil moisture stress using soil retention parameters
soil_moisture_stress = PiecewiseMoistureStressModel{FT}(
land_domain,
toml_dict;
soil_params = retention_parameters,
)
# Set up plant hydraulics
# Read in LAI from MODIS data
surface_space = land_domain.space.surface;
LAI =
ClimaLand.Canopy.prescribed_lai_modis(surface_space, start_date, stop_date)
# Get the maximum LAI at this site over the first year of the simulation
maxLAI = FluxnetSimulations.get_maxLAI_at_site(start_date, lat, long);
RAI = maxLAI * f_root_to_shoot
hydraulics = Canopy.PlantHydraulicsModel{FT}(
surface_domain,
toml_dict;
n_stem,
n_leaf,
h_stem,
h_leaf,
ν = plant_ν,
S_s = plant_S_s,
conductivity_model,
retention_model,
)
height = h_stem + h_leaf
biomass =
Canopy.PrescribedBiomassModel{FT}(; LAI, SAI, RAI, rooting_depth, height)
# Set up the energy model
energy = Canopy.BigLeafEnergyModel{FT}(toml_dict; ac_canopy)
ground = ClimaLand.PrognosticGroundConditions{FT}()
canopy_forcing = (; atmos, radiation, ground)
# Combine the components into a CanopyModel
canopy = Canopy.CanopyModel{FT}(
surface_domain,
canopy_forcing,
LAI,
toml_dict;
prognostic_land_components,
radiative_transfer,
photosynthesis,
conductance,
soil_moisture_stress,
hydraulics,
energy,
biomass,
)
# Snow model
snow = Snow.SnowModel(
FT,
surface_domain,
forcing,
toml_dict,
dt;
prognostic_land_components,
)
# Integrated plant hydraulics, soil, and snow model
land = LandModel{FT}(canopy, snow, soil, soilco2);
set_ic! = FluxnetSimulations.make_set_fluxnet_initial_conditions(
site_ID,
start_date,
time_offset,
land,
)
# Callbacks
output_vars = [
"gpp",
"shf",
"lhf",
"swu",
"lwu",
"swc",
"swe",
"tsoil",
"sco2",
"so2",
"soc",
"scms",
]
diags = ClimaLand.default_diagnostics(
land,
start_date;
output_writer = ClimaDiagnostics.Writers.DictWriter(),
output_vars,
reduction_period = :halfhourly,
);
simulation = LandSimulation(
start_date,
stop_date,
dt,
land;
user_callbacks = (),
set_ic!,
updateat = Second(dt), # How often we want to update the drivers
diagnostics = diags,
)
@time solve!(simulation)
comparison_data = FluxnetSimulations.get_comparison_data(site_ID, time_offset)
savedir = joinpath(
pkgdir(ClimaLand),
"experiments/integrated/fluxnet/US-MOz/pmodel/out",
)
mkpath(savedir)
LandSimVis.make_diurnal_timeseries(
land_domain,
diags,
start_date;
savedir,
short_names = ["gpp", "shf", "lhf", "swu", "lwu"],
spinup_date = start_date + Day(20),
comparison_data,
)
LandSimVis.make_timeseries(
land_domain,
diags,
start_date;
savedir,
short_names = ["swc", "tsoil", "swe"],
spinup_date = start_date + Day(20),
comparison_data,
)