Skip to content

Commit

Permalink
Update from PR comment #263
Browse files Browse the repository at this point in the history
  • Loading branch information
CallieHsu committed Sep 20, 2023
1 parent 6b2eb40 commit 9652274
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/runcode-func.jl
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,9 @@ function affect!(
erupt_saved::EruptSaved{Float64},
)
composition = param.composition
param_saved_var.storeTemp = param_saved_var.storeTemp[param_saved_var.storeTime .< int.t]
param_saved_var.storeTime = param_saved_var.storeTime[param_saved_var.storeTime .< int.t]
IsStoreTimeLTt = param_saved_var.storeTime .< int.t
param_saved_var.storeTemp = param_saved_var.storeTemp[IsStoreTimeLTt]
param_saved_var.storeTime = param_saved_var.storeTime[IsStoreTimeLTt]

if param.dP_lit_dt_0 == 0
temp_P_lit = 0.0
Expand Down
13 changes: 8 additions & 5 deletions src/write_csv.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
function extend_with_nan(arr::Vector{T}, n::Int64)::Vector{T} where {T<:Float64}
return [arr; fill(NaN, n - length(arr))]
end

function write_csv(df::DataFrame, erupt_saved::EruptSaved{Float64}, path::String, composition::Union{Silicic,Mafic})::Nothing
number_of_data = size(df, 1)
println("number_of_data: $number_of_data")
Expand All @@ -18,15 +22,14 @@ function write_csv(df::DataFrame, erupt_saved::EruptSaved{Float64}, path::String
# add eps_x column
m_h2o = df[:, "total_mass_H2O"] ./ df[:, "total_mass"]
m_co2 = df[:, "total_mass_CO2"] ./ df[:, "total_mass"]
crystal_fraction_eps_x′(T, P, mH2O, mCO2) = crystal_fraction_eps_x(composition, T, P, mH2O, mCO2)
df[!, "eps_x"] = crystal_fraction_eps_x′.(df[:, "T"], df[:, "P+dP"], m_h2o, m_co2)
df[!, "eps_x"] = crystal_fraction_eps_x.(repeat([composition], number_of_data), df[:, "T"], df[:, "P+dP"], m_h2o, m_co2)

n = length(erupt_saved.time)
df_erupt = DataFrame(
time_of_eruption = erupt_saved.time,
duration_of_eruption = [erupt_saved.duration; fill(NaN, n - length(erupt_saved.duration))],
mass_erupted = [erupt_saved.mass; fill(NaN, n - length(erupt_saved.mass))],
volume_erupted = [erupt_saved.volume; fill(NaN, n - length(erupt_saved.volume))]
duration_of_eruption = extend_with_nan(erupt_saved.duration, n),
mass_erupted = extend_with_nan(erupt_saved.mass, n),
volume_erupted = extend_with_nan(erupt_saved.volume, n)
)
CSV.write("$path/out.csv", df)
CSV.write("$path/eruptions.csv", df_erupt)
Expand Down

0 comments on commit 9652274

Please sign in to comment.