Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aerosol activation emulators: GP, ET, and ARG-informed #349

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions ext/Common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import DataFrames as DF
using DataFramesMeta

import CloudMicrophysics.AerosolModel as AM
import CloudMicrophysics.AerosolActivation as AA

function get_num_modes(df::DataFrame)
i = 1
while true
Expand Down Expand Up @@ -68,6 +71,67 @@
return X
end

function get_ARG_act_frac(data_row::NamedTuple)

FT = Float32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to pass in the FT and the parameter structs as arguments, instead of defining them here?

aip = CMP.AirProperties(FT)
tps = TD.Parameters.ThermodynamicsParameters(FT)
ap = CMP.AerosolActivationParameters(FT)

num_modes = get_num_modes(data_row)
@assert num_modes > 0
mode_Ns = []
mode_means = []
mode_stdevs = []
mode_kappas = []
w = data_row.velocity
T = data_row.initial_temperature
p = data_row.initial_pressure
for i in 1:num_modes
push!(mode_Ns, data_row[Symbol("mode_$(i)_N")])
push!(mode_means, data_row[Symbol("mode_$(i)_mean")])
push!(mode_stdevs, data_row[Symbol("mode_$(i)_stdev")])
push!(mode_kappas, data_row[Symbol("mode_$(i)_kappa")])
end
ad = AM.AerosolDistribution(
Tuple(
AM.Mode_κ(
mode_means[i],
mode_stdevs[i],
mode_Ns[i],
FT(1),
FT(1),
FT(0),
FT(mode_kappas[i]),
1,
) for i in 1:num_modes
),
)
pv0 = TD.saturation_vapor_pressure(tps, FT(T), TD.Liquid())
vapor_mix_ratio = pv0 / TD.Parameters.molmass_ratio(tps) / (p - pv0)
q_vap = vapor_mix_ratio / (vapor_mix_ratio + 1)
q = TD.PhasePartition(FT(q_vap), FT(0), FT(0))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure there is never any cloud condensate in this data?


return collect(
AA.N_activated_per_mode(ap, ad, aip, tps, FT(T), FT(p), FT(w), q),
) ./ mode_Ns
end

function get_ARG_act_frac(X::DataFrame)
return transpose(hcat(get_ARG_act_frac.(NamedTuple.(eachrow(X)))...))

Check warning on line 121 in ext/Common.jl

View check run for this annotation

Codecov / codecov/patch

ext/Common.jl#L120-L121

Added lines #L120 - L121 were not covered by tests
end

function preprocess_aerosol_data_with_ARG_act_frac(X::DataFrame)
num_modes = get_num_modes(X)
X = DF.transform(
X,
AsTable(All()) =>
ByRow(x -> get_ARG_act_frac(x)) =>
[Symbol("mode_$(i)_ARG_act_frac") for i in 1:num_modes],
)
return preprocess_aerosol_data(X)
end

function target_transform(act_frac)
return @. atanh(2.0 * 0.99 * (act_frac - 0.5))
end
Expand Down
3 changes: 3 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ ClimaParams = "5c42b081-d73a-476f-9059-fd94b934656c"
CloudMicrophysics = "6a9e3e04-43cd-43ba-94b9-e8782df3c71b"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DataFramesMeta = "1313f7d8-7da2-5740-9ea0-a2ca25f37964"
EvoTrees = "f6006082-12f8-11e9-0c9c-0d5d367ab1e5"
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
GaussianProcesses = "891a1506-143c-57d2-908e-e1f8e92e6de9"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
MLJ = "add582a8-e3ab-11e8-2d5e-e98b27df1bc7"
MLJFlux = "094fc8d1-fd35-5302-93ea-dabda2abf845"
MLJModels = "d491faf4-2d78-11e9-2867-c94bc002c0b7"
RootSolvers = "7181ea78-2dcb-4de3-ab41-2b8ab5a31e74"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Thermodynamics = "b60c26fb-14c3-4610-9d3e-2d17fe7ff00c"

Expand Down
Loading
Loading