Skip to content

Commit

Permalink
combined results to one plot and avoid NaN in IC_Finder Mafic
Browse files Browse the repository at this point in the history
  • Loading branch information
CallieHsu committed Sep 15, 2023
1 parent e8f7a8e commit 7fb9e41
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.8.5"
manifest_format = "2.0"
project_hash = "307cac97db0b7035e7716e25208fc63e328a2438"
project_hash = "ce9748a73286acaa3182365f1a6814016433d441"

[[deps.Adapt]]
deps = ["LinearAlgebra", "Requires"]
Expand Down
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
IterableTables = "1c8ee90f-4401-5389-894e-7a04a3dc0f4d"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Memoize = "c03570c3-d221-55d1-a50c-7939bbd78826"
Expand Down
8 changes: 5 additions & 3 deletions scripts/runcode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,12 @@ julia> chamber(composition, end_time, log_volume_km3, InitialConc_H2O, InitialCo
df = DataFrame(sol)
write_csv(df, erupt_saved, path)
if plotfig
plot_figs(df, path)
title = latexstringtitle(composition, log_volume_km3, InitialConc_H2O, InitialConc_CO2, log_vfr, depth)
plot_combined_fig(df, path, title)
plot_dual_axis(df, param_saved_var.storeTime, param_saved_var.storeEps_x, path)
end
write_ϵx_csv(param_saved_var.storeTime, param_saved_var.storeEps_x, path)
plot_ϵx(param_saved_var.storeTime, param_saved_var.storeEps_x, path)
# write_ϵx_csv(param_saved_var.storeTime, param_saved_var.storeEps_x, path)
# plot_ϵx(param_saved_var.storeTime, param_saved_var.storeEps_x, path)
return df
end
return df
Expand Down
5 changes: 5 additions & 0 deletions src/Chamber.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ using Roots
using SpecialFunctions
using Sundials
using TimerOutputs
using LaTeXStrings
using Logging
include("utils.jl")
include("./glq_points_weights.jl")
Expand Down Expand Up @@ -135,6 +136,10 @@ export @memoize,
build_rho_rc,
write_csv,
plot_figs,
plot_sol_year_unit,
latexstringtitle,
plot_combined_fig,
plot_dual_axis,
plot_ϵx,
write_ϵx_csv,
check_for_duplicates,
Expand Down
2 changes: 1 addition & 1 deletion src/ic_finder.jl
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ function IC_Finder(
end
end

if eps_g0 <= 0 || X_co20 < 0
if eps_g0 <= 0 || X_co20 < 0 || any(isnan, [X_co20, eps_g0])
X_co20 = 0.0
eps_g0 = 0.0
mco2_diss = m_co2_melt
Expand Down
100 changes: 97 additions & 3 deletions src/plot_figs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,38 @@ function plot_sol(df, x_axis_col, y_axis_col)
df[:, y_axis_col];
xaxis=x_axis_col,
yaxis=y_axis_col,
label="Chamber.jl",
linewidth=2,
marker=(:x, 3, Plots.stroke(2)),
)
end

function plot_sol_year_unit(df, xlabel, ylabel)
# Units of outputs: Time -> sec, Presure -> Pa, Volume -> m³
divisors = Dict(
"time" => 31536000,
"P+dP" => 1e6,
"V" => 1e9,
"total_mass" => 1e12,
)
labels = Dict(
"time" => "Time (yr)",
"P+dP" => "Pressure (MPa)",
"T" => "Temperature (K)",
"V" => "Volume (km³)",
"total_mass" => "Total mass (×10¹² kg)",
)
convert_unit(label) = df[:, label] / get(divisors, label, 1.0)
getaxis(label) = get(labels, label, label)

return plot(
convert_unit(xlabel), convert_unit(ylabel);
xaxis=getaxis(xlabel),
yaxis=getaxis(ylabel),
legend=false,
linewidth=2,
)
end

function plot_figs(df::DataFrame, path::String)::Nothing
ENV["GKSwstype"] = "100" # magic environmental variable for Plots
savefig′(label, path) = savefig(plot_sol(df, "time", label), path)
Expand All @@ -19,10 +45,19 @@ function plot_figs(df::DataFrame, path::String)::Nothing
return nothing
end

function plot_ϵx(storeTime::Vector{Float64}, storeEps_g::Vector{Float64}, path::String)::Nothing
function plot_combined_fig(df::DataFrame, path::String, title::LaTeXString)::Nothing
ENV["GKSwstype"] = "100" # magic environmental variable for Plots
plot_names = ["P+dP", "T", "eps_g", "V", "X_CO2", "total_mass"]
plts = [plot_sol_year_unit(df, "time", l) for l in plot_names]
combined_plot = plot(plts..., layout=(2, 3), size=(900, 500), dpi=200, margin = 3Plots.mm, plot_title=title, plot_titlefontsize=13)
savefig(combined_plot, joinpath(path, "combined_plots.png"))
return nothing
end

function plot_ϵx(storeTime::Vector{Float64}, storeEps_x::Vector{Float64}, path::String)::Nothing
ENV["GKSwstype"] = "100" # magic environmental variable for Plots
savefig(plot(
storeTime, storeEps_g;
storeTime, storeEps_x;
xaxis="time",
yaxis="eps_x",
label="Chamber.jl",
Expand All @@ -31,3 +66,62 @@ function plot_ϵx(storeTime::Vector{Float64}, storeEps_g::Vector{Float64}, path:
"$path/eps_x.png")
return nothing
end

function plot_dual_axis(df::DataFrame, storeTime::Vector{Float64}, storeEps_x::Vector{Float64}, path::String)::Nothing
color1 = RGB(20/255, 125/255, 204/255)
color2 = RGB(255/255, 100/255, 0/255)
ENV["GKSwstype"] = "100" # magic environmental variable for Plots

common_opt1 = (
xaxis="Time (yr)",
linewidth=3,
legend=:false,
guidefontsize=18,
tickfontsize=12,
linecolor=color1,
fg_color_guide=color1,
fg_color_text=color1,
)

common_opt2 = (
linewidth=3,
legend=:false,
guidefontsize=18,
tickfontsize=12,
linecolor=color2,
fg_color_guide=color2,
fg_color_text=color2,
)

plot(
df[!, 1]/31536000,
df[!, 2]/1e6;
common_opt1...,
yaxis="Pressure (MPa)",
)
p1 = plot!(
twinx(),
df[!, 1]/31536000,
df[!, 3];
common_opt2...,
yaxis="Temperature (K)",
)

plot(
df[!, 1]/31536000,
df[!, 4];
common_opt1...,
yaxis=L"𝜺_g",
)
p2 = plot!(
twinx(),
storeTime/31536000,
storeEps_x;
common_opt2...,
yaxis=L"𝜺_X",
)

savefig(p1, joinpath(path, "P_T.png"))
savefig(p2, joinpath(path, "eps_x_eps_g.png"))
return nothing
end
2 changes: 2 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -506,3 +506,5 @@ function check_for_duplicates(
)
return nothing
end

latexstringtitle(composition, log_volume_km3, InitialConc_H2O, InitialConc_CO2, log_vfr, depth) = L"\textrm{%$(string(typeof(composition)))\ \ H_2O:%$(InitialConc_H2O*100)\ \%,\ CO_2: %$(InitialConc_CO2*1000000)\ ppm,\ depth:%$(depth/1000)\ km,\ vfr: 10^{%$(log_vfr)}\ km^{3}/yr,\ V_0:10^{%$(log_volume_km3)}\ km^{3}}"

0 comments on commit 7fb9e41

Please sign in to comment.