Skip to content

Commit

Permalink
Something works
Browse files Browse the repository at this point in the history
  • Loading branch information
trontrytel committed Mar 2, 2024
1 parent 79a0b14 commit 96e862d
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 274 deletions.
3 changes: 2 additions & 1 deletion ext/EmulatorModelsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import CloudMicrophysics.Parameters as CMP
function AA.N_activated_per_mode(
machine::MLJ.Machine,
ap::CMP.AerosolActivationParameters,
ad::CMP.AerosolDistributionType,
aip::CMP.AirProperties,
tps::TDP.ThermodynamicsParameters,
T::FT,
p::FT,
w::FT,
q::TD.PhasePartition{FT},
) where {FT <: Real}
hygro = mean_hygroscopicity_parameter(ap, ad)
hygro = AA.mean_hygroscopicity_parameter(ap, ad)
return ntuple(Val(AM.n_modes(ad))) do i
# Model predicts activation of the first mode. So, swap each mode
# with the first mode repeatedly to predict all activations.
Expand Down
77 changes: 77 additions & 0 deletions ml_test/Common.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import CSV
import DataFrames as DF
using DataFramesMeta

function get_num_modes(df::DataFrame)
i = 1
while true
if !("mode_$(i)_N" in names(df))
return i - 1
end
i += 1
end
end

function get_num_modes(data_row::NamedTuple)
i = 1
while true
if !(Symbol("mode_$(i)_N") in keys(data_row))
return i - 1
end
i += 1
end
end

function read_aerosol_dataset(
dataset_filename::String,
Y_name = :mode_1_act_frac_S_interp
)
initial_data = DF.DataFrame(CSV.File(dataset_filename))
df = filter(row -> row.S_max > 0 && row.S_max < 0.2, initial_data)
selected_columns_X = []
num_modes = get_num_modes(df)
@info(num_modes)
for i in 1:num_modes
append!(
selected_columns_X,
Symbol.([
"mode_$(i)_N",
"mode_$(i)_mean",
"mode_$(i)_stdev",
"mode_$(i)_kappa",
]),
)
end
append!(
selected_columns_X,
[:velocity, :initial_temperature, :initial_pressure],
)
X = df[:, selected_columns_X]
Y = df[:, Y_name]
return (X, Y, initial_data)
end

function preprocess_aerosol_data(X::DataFrame)
num_modes = get_num_modes(X)
for i in 1:num_modes
X = DF.transform(
X,
Symbol("mode_$(i)_N") => ByRow(log) => Symbol("mode_$(i)_N"),
)
X = DF.transform(
X,
Symbol("mode_$(i)_mean") =>
ByRow(log) => Symbol("mode_$(i)_mean"),
)
end
X = DF.transform(X, :velocity => ByRow(log) => :velocity)
return X
end

function target_transform(act_frac)
return @. atanh(2.0 * 0.99 * (act_frac - 0.5))
end

function inverse_target_transform(transformed_act_frac)
return @. (1.0 / (2.0 * 0.99)) * tanh(transformed_act_frac) + 0.5
end
207 changes: 0 additions & 207 deletions ml_test/PreprocessAerosolData.jl

This file was deleted.

5 changes: 2 additions & 3 deletions ml_test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
[deps]
CLIMAParameters = "6eacf6c3-8458-43b9-ae03-caf5306d3d53"
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
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"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
MLJ = "add582a8-e3ab-11e8-2d5e-e98b27df1bc7"
MLJFlux = "094fc8d1-fd35-5302-93ea-dabda2abf845"
MLJModels = "d491faf4-2d78-11e9-2867-c94bc002c0b7"
Expand Down
63 changes: 0 additions & 63 deletions ml_test/testing.jl

This file was deleted.

Loading

0 comments on commit 96e862d

Please sign in to comment.