Skip to content

Commit 95df386

Browse files
authored
Merge pull request #552 from CliMA/al/p3
Adding P3 to compare w AIDA calibs
2 parents a41c345 + 5c61a02 commit 95df386

File tree

6 files changed

+183
-66
lines changed

6 files changed

+183
-66
lines changed

papers/ice_nucleation_2024/AIDA_calibrations.jl

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ data_file_names = [
3232
["ACI04_22", "EXP19"],
3333
]
3434
batch_names = ["HOM", "IN0701", "IN0719", "ACI04_22", "EXP19", "EXP45", "DEP", "IMM"]
35-
end_sim = 25 # Loss func looks at last end_sim timesteps only
3635
start_time_list = [ # freezing onset
3736
[Int32(150), Int32(180), Int32(0)],
3837
[Int32(50)],
@@ -75,12 +74,13 @@ global EKI_calibrated_coeff_dict = Dict()
7574
global UKI_calibrated_coeff_dict = Dict()
7675
mutable struct all_calibration_data
7776
UKI_calibrated_parcel::Vector{ODE.ODESolution}
77+
P3_parcel::Vector{ODE.ODESolution}
7878
Nₜ_list::Vector{Any}
7979
t_profile_list::Vector{Any}
8080
frozen_frac_moving_mean_list::Vector{Any}
8181
frozen_frac_list::Vector{Any}
8282
end
83-
global overview_data = all_calibration_data(Vector{ODE.ODESolution}(), [], [], [], [])
83+
global overview_data = all_calibration_data(Vector{ODE.ODESolution}(), Vector{ODE.ODESolution}(), [], [], [], [])
8484

8585
for (batch_index, batch_name) in enumerate(batch_names)
8686
@info(batch_name)
@@ -94,23 +94,28 @@ for (batch_index, batch_name) in enumerate(batch_names)
9494

9595
if batch_name == "HOM"
9696
nuc_mode = "ABHOM"
97+
P3_nuc_mode = "P3_hom"
9798
elseif batch_name in ["IN0701", "IN0719", "EXP45", "DEP"]
9899
nuc_mode = "ABDINM"
100+
P3_nuc_mode = "P3_dep"
99101
elseif batch_name in ["ACI04_22", "EXP19", "IMM"]
100102
nuc_mode = "ABIFM"
103+
P3_nuc_mode = "P3_het"
101104
end
102105

103106
### Check for and grab data in AIDA_data folder.
104107
calib_variables = data_to_calib_inputs(
105108
FT, batch_name, data_file_name_list, nuc_mode,
106109
start_time, end_time,
107-
w, t_max, end_sim,
110+
w, t_max,
111+
P3_nuc_mode,
108112
)
109113
(;
110114
t_profile, T_profile, P_profile, ICNC_profile, e_profile, S_l_profile,
111115
params_list, IC_list,
112116
frozen_frac, frozen_frac_moving_mean, ICNC_moving_avg,
113117
Nₜ, y_truth,
118+
P3_params_list,
114119
) = calib_variables
115120

116121
if batch_name in ["HOM", "DEP", "IMM"]
@@ -123,7 +128,7 @@ for (batch_index, batch_name) in enumerate(batch_names)
123128
Γ = (0.1 / 3)^2 * LinearAlgebra.I # 0.1 is the uncertainty in observed ICNC
124129

125130
### Calibration.
126-
UKI_output = calibrate_J_parameters_UKI(FT, nuc_mode, params_list, IC_list, y_truth, end_sim, Γ)
131+
UKI_output = calibrate_J_parameters_UKI(FT, nuc_mode, params_list, IC_list, y_truth, Γ)
127132

128133
UKI_calibrated_parameters = UKI_output[1] # MEAN of parameters from ensembles in FINAL iteration
129134
UKI_all_params = UKI_output[2] # parameters from EACH ensemble in EACH iteration
@@ -151,11 +156,14 @@ for (batch_index, batch_name) in enumerate(batch_names)
151156
end
152157

153158
## Calibrated parcel.
154-
UKI_parcel = run_model([params_list[exp_index]], nuc_mode, UKI_calibrated_parameters, FT, [IC_list[exp_index]], end_sim)
159+
UKI_parcel = run_model([params_list[exp_index]], nuc_mode, UKI_calibrated_parameters, FT, [IC_list[exp_index]])
160+
@info(exp_names[exp_index])
161+
P3_parcel = run_model([P3_params_list[exp_index]], P3_nuc_mode, [0, 0], FT, [IC_list[exp_index]], P3 = true)
155162
if batch_name in ["HOM", "DEP", "IMM"]
156163
# the order it appends is "in05_17_aida.edf", "in05_18_aida.edf", "TROPIC04",
157164
# "in07_01_aida.edf", "in07_19_aida.edf", "EXP45", "ACI04_22", "EXP19".
158165
push!(overview_data.UKI_calibrated_parcel, UKI_parcel)
166+
push!(overview_data.P3_parcel, P3_parcel)
159167
end
160168

161169
## Plots.
@@ -192,12 +200,12 @@ for (batch_index, batch_name) in enumerate(batch_names)
192200
t_profile[exp_index], frozen_frac_moving_mean[exp_index], frozen_frac[exp_index],
193201
)
194202

195-
## Looking at spread in UKI calibrated parameters
196-
UKI_parcel_1 = run_model([params_list[exp_index]], nuc_mode, [UKI_final_iter_spread[1,1], UKI_final_iter_spread[2,1]], FT, [IC_list[exp_index]], end_sim)
197-
UKI_parcel_2 = run_model([params_list[exp_index]], nuc_mode, [UKI_final_iter_spread[1,2], UKI_final_iter_spread[2,2]], FT, [IC_list[exp_index]], end_sim)
198-
UKI_parcel_3 = run_model([params_list[exp_index]], nuc_mode, [UKI_final_iter_spread[1,3], UKI_final_iter_spread[2,3]], FT, [IC_list[exp_index]], end_sim)
199-
UKI_parcel_4 = run_model([params_list[exp_index]], nuc_mode, [UKI_final_iter_spread[1,4], UKI_final_iter_spread[2,4]], FT, [IC_list[exp_index]], end_sim)
200-
UKI_parcel_5 = run_model([params_list[exp_index]], nuc_mode, [UKI_final_iter_spread[1,5], UKI_final_iter_spread[2,5]], FT, [IC_list[exp_index]], end_sim)
203+
# Looking at spread in UKI calibrated parameters
204+
UKI_parcel_1 = run_model([params_list[exp_index]], nuc_mode, [UKI_final_iter_spread[1,1], UKI_final_iter_spread[2,1]], FT, [IC_list[exp_index]])
205+
UKI_parcel_2 = run_model([params_list[exp_index]], nuc_mode, [UKI_final_iter_spread[1,2], UKI_final_iter_spread[2,2]], FT, [IC_list[exp_index]])
206+
UKI_parcel_3 = run_model([params_list[exp_index]], nuc_mode, [UKI_final_iter_spread[1,3], UKI_final_iter_spread[2,3]], FT, [IC_list[exp_index]])
207+
UKI_parcel_4 = run_model([params_list[exp_index]], nuc_mode, [UKI_final_iter_spread[1,4], UKI_final_iter_spread[2,4]], FT, [IC_list[exp_index]])
208+
UKI_parcel_5 = run_model([params_list[exp_index]], nuc_mode, [UKI_final_iter_spread[1,5], UKI_final_iter_spread[2,5]], FT, [IC_list[exp_index]])
201209

202210
UKI_spread_fig = plot_UKI_spread(
203211
exp_names[exp_index],

papers/ice_nucleation_2024/calibration.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import StatsBase as SB
1616
include(joinpath(pkgdir(CM), "parcel", "Parcel.jl"))
1717

1818
# Define model which wraps around parcel and overwrites calibrated parameters
19-
function run_model(p_list, IN_mode, coefficients, FT, IC_list, end_sim::Int64; calibration = false)
19+
function run_model(p_list, IN_mode, coefficients, FT, IC_list; calibration = false, P3 = false)
2020
# grabbing calibrated m and c
2121
m_calibrated, c_calibrated = coefficients
2222

@@ -33,7 +33,9 @@ function run_model(p_list, IN_mode, coefficients, FT, IC_list, end_sim::Int64; c
3333
IC = IC_list[exp_index]
3434

3535
# overwriting
36-
if aerosol == CMP.Kaolinite(FT)
36+
if P3 == true
37+
nothing
38+
elseif aerosol == CMP.Kaolinite(FT)
3739
if IN_mode == "ABDINM"
3840
override_file = Dict(
3941
"China2017_J_deposition_m_Kaolinite" =>
@@ -194,7 +196,6 @@ function run_model(p_list, IN_mode, coefficients, FT, IC_list, end_sim::Int64; c
194196
local sol = run_parcel(IC, FT(0), t_max, params)
195197

196198
if calibration == true
197-
# loss_func_i = sol[9, (end - end_sim):end] ./ (IC[7] + IC[8] + IC[9])
198199
loss_func_i = sol[9, end] / (IC[7] + IC[8] + IC[9])
199200
append!(loss_func, loss_func_i)
200201
elseif calibration == false
@@ -292,7 +293,7 @@ function create_prior(FT, IN_mode, ; perfect_model = false, aerosol_type = nothi
292293
return prior
293294
end
294295

295-
function calibrate_J_parameters_EKI(FT, IN_mode, params, IC, y_truth, end_sim, Γ,; perfect_model = false)
296+
function calibrate_J_parameters_EKI(FT, IN_mode, params, IC, y_truth, Γ,; perfect_model = false)
296297
@info("Starting EKI calibration")
297298
# Random number generator
298299
rng_seed = 24
@@ -326,7 +327,7 @@ function calibrate_J_parameters_EKI(FT, IN_mode, params, IC, y_truth, end_sim,
326327
ϕ_n = EKP.get_ϕ_final(prior, EKI_obj)
327328
G_ens = hcat(
328329
[
329-
run_model(params, IN_mode, ϕ_n[:, i], FT, IC, end_sim, calibration = true) for
330+
run_model(params, IN_mode, ϕ_n[:, i], FT, IC, calibration = true) for
330331
i in 1:N_ensemble
331332
]...,
332333
)
@@ -362,7 +363,7 @@ function calibrate_J_parameters_EKI(FT, IN_mode, params, IC, y_truth, end_sim,
362363
return [calibrated_coeffs, ϕ_n_values, mean_each_iter, error]
363364
end
364365

365-
function calibrate_J_parameters_UKI(FT, IN_mode, params, IC, y_truth, end_sim, Γ,; perfect_model = false)
366+
function calibrate_J_parameters_UKI(FT, IN_mode, params, IC, y_truth, Γ,; perfect_model = false)
366367
@info("Starting UKI calibration")
367368
(; aerosol) = params[1]
368369

@@ -393,7 +394,7 @@ function calibrate_J_parameters_UKI(FT, IN_mode, params, IC, y_truth, end_sim,
393394
ϕ_n = EKP.get_ϕ_final(prior, UKI_obj)
394395
# Evaluate forward map
395396
G_n = [
396-
run_model(params, IN_mode, ϕ_n[:, i], FT, IC, end_sim, calibration = true) for
397+
run_model(params, IN_mode, ϕ_n[:, i], FT, IC, calibration = true) for
397398
i in 1:size(ϕ_n)[2] #i in 1:N_ensemble
398399
]
399400
# Reformat into `d x N_ens` matrix

papers/ice_nucleation_2024/calibration_setup.jl

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function perf_model_IC(FT, IN_mode)
138138
return [Sₗ, p₀, T₀, qᵥ, qₗ, qᵢ, Nₐ, Nₗ, Nᵢ, FT(0)]
139139
end
140140

141-
function perf_model_pseudo_data(FT, IN_mode, params, IC, end_sim)
141+
function perf_model_pseudo_data(FT, IN_mode, params, IC)
142142
n_samples = 10
143143

144144
if IN_mode == "ABDINM"
@@ -149,7 +149,7 @@ function perf_model_pseudo_data(FT, IN_mode, params, IC, end_sim)
149149
coeff_true = [FT(255.927125), FT(-68.553283)]
150150
end
151151

152-
G_truth = run_model(params, IN_mode, coeff_true, FT, IC, end_sim, calibration = true)
152+
G_truth = run_model(params, IN_mode, coeff_true, FT, IC, calibration = true)
153153
dim_output = length(G_truth)
154154

155155
Γ = (0.1 / 3)^2 * LinearAlgebra.I
@@ -160,15 +160,15 @@ function perf_model_pseudo_data(FT, IN_mode, params, IC, end_sim)
160160
return [y_truth, Γ, coeff_true]
161161
end
162162

163-
function AIDA_IN05_params(FT, w, t_max, t_profile, T_profile, P_profile)
163+
function AIDA_IN05_params(FT, w, t_max, t_profile, T_profile, P_profile; P3 = false)
164164
IN_mode = "ABHOM"
165165
const_dt = FT(1)
166166
prescribed_thermodynamics = true
167167
aerosol_act = "AeroAct"
168168
aerosol = CMP.Sulfate(FT)
169-
dep_nucleation = "ABDINM"
170-
heterogeneous = "ABIFM"
171-
homogeneous = "ABHOM"
169+
dep_nucleation = P3 ? "P3_dep" : "ABDINM"
170+
heterogeneous = P3 ? "P3_het" : "ABIFM"
171+
homogeneous = P3 ? "P3_hom" : "ABHOM"
172172
condensation_growth = "Condensation"
173173
deposition_growth = "Deposition"
174174
liq_size_distribution = "Gamma"
@@ -177,8 +177,9 @@ function AIDA_IN05_params(FT, w, t_max, t_profile, T_profile, P_profile)
177177
r_nuc = FT(1e-7) #FT(3.057e-6)
178178
A_aer = FT(4 * π * r_nuc^2)
179179
ips = CMP.IceNucleationParameters(FT)
180+
aap = CMP.AerosolActivationParameters(FT)
180181

181-
params = (; const_dt, w, t_max, ips,
182+
params = (; const_dt, w, t_max, ips, aap,
182183
prescribed_thermodynamics, t_profile, T_profile, P_profile,
183184
aerosol_act, aerosol, r_nuc, aero_σ_g, A_aer, # aerosol activation
184185
condensation_growth, deposition_growth, # growth
@@ -236,7 +237,7 @@ function AIDA_IN05_IC(FT, data_file)
236237
return [Sₗ, p₀, T₀, qᵥ, qₗ, qᵢ, Nₐ, Nₗ, Nᵢ, FT(0)]
237238
end
238239

239-
function AIDA_IN07_params(FT, w, t_max, t_profile, T_profile, P_profile, batch_name)
240+
function AIDA_IN07_params(FT, w, t_max, t_profile, T_profile, P_profile, batch_name; P3 = false)
240241
IN_mode = "ABDINM"
241242
const_dt = FT(1)
242243
prescribed_thermodynamics = true
@@ -248,9 +249,9 @@ function AIDA_IN07_params(FT, w, t_max, t_profile, T_profile, P_profile, batch_n
248249
elseif batch_name == "DEP"
249250
aerosol = CMP.Dust(FT)
250251
end
251-
dep_nucleation = "ABDINM"
252-
heterogeneous = "ABIFM"
253-
homogeneous = "ABHOM"
252+
dep_nucleation = P3 ? "P3_dep" : "ABDINM"
253+
heterogeneous = P3 ? "P3_het" : "ABIFM"
254+
homogeneous = P3 ? "P3_hom" : "ABHOM"
254255
condensation_growth = "Condensation"
255256
deposition_growth = "Deposition"
256257
liq_size_distribution = "Gamma"
@@ -260,8 +261,9 @@ function AIDA_IN07_params(FT, w, t_max, t_profile, T_profile, P_profile, batch_n
260261
A_aer = FT(4 * π * r_nuc^2)
261262
# r_nuc = r₀ in IC
262263
ips = CMP.IceNucleationParameters(FT)
264+
aap = CMP.AerosolActivationParameters(FT)
263265

264-
params = (; const_dt, w, t_max, ips,
266+
params = (; const_dt, w, t_max, ips, aap,
265267
prescribed_thermodynamics, t_profile, T_profile, P_profile,
266268
aerosol_act, aerosol, r_nuc, aero_σ_g, A_aer, # aerosol activation
267269
condensation_growth, deposition_growth, # growth
@@ -320,15 +322,15 @@ function AIDA_IN07_IC(FT, data_file)
320322
return [Sₗ, p₀, T₀, qᵥ, qₗ, qᵢ, Nₐ, Nₗ, Nᵢ, FT(0)]
321323
end
322324

323-
function TROPIC04_params(FT, w, t_max, t_profile, T_profile, P_profile)
325+
function TROPIC04_params(FT, w, t_max, t_profile, T_profile, P_profile; P3 = false)
324326
IN_mode = "ABHOM"
325327
const_dt = FT(1)
326328
prescribed_thermodynamics = true
327329
aerosol_act = "AeroAct"
328330
aerosol = CMP.Sulfate(FT)
329-
dep_nucleation = "ABDINM"
330-
heterogeneous = "ABIFM"
331-
homogeneous = "ABHOM"
331+
dep_nucleation = "None"
332+
heterogeneous = "None"
333+
homogeneous = P3 ? "P3_hom" : "ABHOM"
332334
condensation_growth = "Condensation"
333335
deposition_growth = "Deposition"
334336
liq_size_distribution = "Gamma"
@@ -337,8 +339,9 @@ function TROPIC04_params(FT, w, t_max, t_profile, T_profile, P_profile)
337339
r_nuc = FT(1.15 / 2 * 1e-6)
338340
A_aer = FT(4 * π * r_nuc^2)
339341
ips = CMP.IceNucleationParameters(FT)
342+
aap = CMP.AerosolActivationParameters(FT)
340343

341-
params = (; const_dt, w, t_max, ips,
344+
params = (; const_dt, w, t_max, ips, aap,
342345
prescribed_thermodynamics, t_profile, T_profile, P_profile,
343346
aerosol_act, aerosol, r_nuc, aero_σ_g, A_aer, # aerosol activation
344347
condensation_growth, deposition_growth, # growth
@@ -376,16 +379,16 @@ function TROPIC04_IC(FT)
376379
return [Sₗ, p₀, T₀, qᵥ, qₗ, qᵢ, Nₐ, Nₗ, Nᵢ, FT(0)]
377380
end
378381

379-
function ACI04_22_params(FT, w, t_max, t_profile, T_profile, P_profile, batch_name)
382+
function ACI04_22_params(FT, w, t_max, t_profile, T_profile, P_profile, batch_name; P3 = false)
380383
# Niemand et al (2012)
381384
IN_mode = "ABIFM"
382385
const_dt = FT(1)
383386
prescribed_thermodynamics = true
384387
aerosol_act = "None"
385388
aerosol = batch_name == "ACI04_22" ? CMP.MiddleEasternDust(FT) : CMP.Dust(FT)
386-
dep_nucleation = "ABDINM"
387-
heterogeneous = "ABIFM"
388-
homogeneous = "ABHOM"
389+
dep_nucleation = P3 ? "P3_dep" : "ABDINM"
390+
heterogeneous = P3 ? "P3_het" : "ABIFM"
391+
homogeneous = P3 ? "P3_hom" : "ABHOM"
389392
condensation_growth = "Condensation"
390393
deposition_growth = "Deposition"
391394
liq_size_distribution = "Gamma"
@@ -394,8 +397,9 @@ function ACI04_22_params(FT, w, t_max, t_profile, T_profile, P_profile, batch_na
394397
r_nuc = FT(0.645 / 2 * 1e-6) # avg of 2 modes
395398
A_aer = FT(4 * π * r_nuc^2)
396399
ips = CMP.IceNucleationParameters(FT)
400+
aap = CMP.AerosolActivationParameters(FT)
397401

398-
params = (; const_dt, w, t_max, ips,
402+
params = (; const_dt, w, t_max, ips, aap,
399403
prescribed_thermodynamics, t_profile, T_profile, P_profile,
400404
aerosol_act, aerosol, r_nuc, aero_σ_g, A_aer, # aerosol activation
401405
condensation_growth, deposition_growth, # growth
@@ -433,16 +437,16 @@ function ACI04_22_IC(FT)
433437
return [Sₗ, p₀, T₀, qᵥ, qₗ, qᵢ, Nₐ, Nₗ, Nᵢ, FT(0)]
434438
end
435439

436-
function EXP19_params(FT, w, t_max, t_profile, T_profile, P_profile, batch_name)
440+
function EXP19_params(FT, w, t_max, t_profile, T_profile, P_profile, batch_name; P3 = false)
437441
# Cotten et al (2007)
438442
IN_mode = "ABIFM"
439443
const_dt = FT(1)
440444
prescribed_thermodynamics = true
441445
aerosol_act = "None"
442446
aerosol = batch_name == "EXP19" ? CMP.AsianDust(FT) : CMP.Dust(FT)
443-
dep_nucleation = "ABDINM"
444-
heterogeneous = "ABIFM"
445-
homogeneous = "ABHOM"
447+
dep_nucleation = P3 ? "P3_dep" : "ABDINM"
448+
heterogeneous = P3 ? "P3_het" : "ABIFM"
449+
homogeneous = P3 ? "P3_hom" : "ABHOM"
446450
condensation_growth = "Condensation"
447451
deposition_growth = "Deposition"
448452
liq_size_distribution = "Gamma"
@@ -451,8 +455,9 @@ function EXP19_params(FT, w, t_max, t_profile, T_profile, P_profile, batch_name)
451455
r_nuc = FT(0.4 / 2 * 1e-6) # value is mode radius, not mean
452456
A_aer = FT(4 * π * r_nuc^2)
453457
ips = CMP.IceNucleationParameters(FT)
458+
aap = CMP.AerosolActivationParameters(FT)
454459

455-
params = (; const_dt, w, t_max, ips,
460+
params = (; const_dt, w, t_max, ips, aap,
456461
prescribed_thermodynamics, t_profile, T_profile, P_profile,
457462
aerosol_act, aerosol, r_nuc, aero_σ_g, A_aer, # aerosol activation
458463
condensation_growth, deposition_growth, # growth
@@ -490,16 +495,16 @@ function EXP19_IC(FT)
490495
return [Sₗ, p₀, T₀, qᵥ, qₗ, qᵢ, Nₐ, Nₗ, Nᵢ, FT(0)]
491496
end
492497

493-
function EXP45_params(FT, w, t_max, t_profile, T_profile, P_profile, batch_name)
498+
function EXP45_params(FT, w, t_max, t_profile, T_profile, P_profile, batch_name; P3 = false)
494499
# Cotten et al (2007)
495500
IN_mode = "ABDINM"
496501
const_dt = FT(1)
497502
prescribed_thermodynamics = true
498503
aerosol_act = "None"
499504
aerosol = batch_name == "EXP45" ? CMP.SaharanDust(FT) : CMP.Dust(FT)
500-
dep_nucleation = "ABDINM"
501-
heterogeneous = "ABIFM"
502-
homogeneous = "ABHOM"
505+
dep_nucleation = P3 ? "P3_dep" : "ABDINM"
506+
heterogeneous = P3 ? "P3_het" : "ABIFM"
507+
homogeneous = P3 ? "P3_hom" : "ABHOM"
503508
condensation_growth = "Condensation"
504509
deposition_growth = "Deposition"
505510
liq_size_distribution = "Gamma"
@@ -508,8 +513,9 @@ function EXP45_params(FT, w, t_max, t_profile, T_profile, P_profile, batch_name)
508513
r_nuc = FT(0.4 / 2 * 1e-6) # value is mode radius, not mean
509514
A_aer = FT(4 * π * r_nuc^2)
510515
ips = CMP.IceNucleationParameters(FT)
516+
aap = CMP.AerosolActivationParameters(FT)
511517

512-
params = (; const_dt, w, t_max, ips,
518+
params = (; const_dt, w, t_max, ips, aap,
513519
prescribed_thermodynamics, t_profile, T_profile, P_profile,
514520
aerosol_act, aerosol, r_nuc, aero_σ_g, A_aer, # aerosol activation
515521
condensation_growth, deposition_growth, # growth

0 commit comments

Comments
 (0)