Skip to content

Commit

Permalink
volume calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
dfabianus committed Nov 14, 2023
1 parent cdfadfa commit 14f8ab1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/standard_library.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ function diff_kalman(experiment::Experiment, names::Symbol...; xₖ = [0 0]', P
return ts_diff
end

function smooth_kalman(experiment::Experiment, names::Symbol...; xₖ = [0 0]', Pₖ = [10 0; 0 10], Q = [0 0; 0 0.01], R = 0.04)
ts_vec = [Experiments.timeseries(experiment, name) for name in names]
t_vec = timestamp2hours.(ts_vec)
z_vec = vec.(values.(ts_vec))
d_vec = [kalman_state_derivative(t, z, xₖ, Pₖ; Q = Q, R = R)[1] for (t,z) in zip(t_vec, z_vec)]
ts_smooth = [Experiments.timeseries(Symbol(name, :_smooth_kalman), t, d) for (name,t,d) in zip(names,timestamp.(ts_vec),d_vec)]
return ts_smooth
end

function volume_flow(experiment::Experiment, massflow::Symbol ; density::Real=1000, name::Symbol=:volume_flow)
ts_massflow = Experiments.timeseries(experiment, massflow)
ts_volume_flow = -ts_massflow ./ density
Expand Down Expand Up @@ -241,4 +250,10 @@ function calc_K2S1(experiment::Experiment, Q_S::Symbol, Q_CO2::Symbol, Q_O2::Sym
ts_CO2 = Experiments.timeseries(:K2S1_mCO2, Experiments.starttime(Q_S_ts) .+ Experiments.hours2duration.(df.timestamp), df.value3)
ts_O2 = Experiments.timeseries(:K2S1_mO2, Experiments.starttime(Q_S_ts) .+ Experiments.hours2duration.(df.timestamp), df.value4)
return [ts_X, ts_S, ts_CO2, ts_O2]
end

function volume(experiment::Experiment, mass::Symbol; initial_vol, density::Real=1000, name::Symbol=:volume)
ts_mass = Experiments.timeseries(experiment, mass)
ts_volume = ts_mass ./ density .+ initial_vol
return [Experiments.timeseries(ts_volume, name)]
end
10 changes: 9 additions & 1 deletion test/usecases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,12 @@ Experiments.calc!(exp, Experiments.calc_K2S1, :Q_S, :Q_CO2, :Q_O2, :V_L; x0 = [0
plot(Experiments.timeseries(exp, :K2S1_mX))
plot!(Experiments.timeseries(exp, :K2S1_mS))
scatter!(Experiments.timeseries(exp, :c_S) .* Experiments.timeseries(exp, :V_L))
scatter!(Experiments.timeseries(exp, :DCW) .* Experiments.timeseries(exp, :V_L))
scatter!(Experiments.timeseries(exp, :DCW) .* Experiments.timeseries(exp, :V_L))

Experiments.calc!(exp, Experiments.volume, :m_L; initial_vol = 1.5, name = :V_L_new)
plot(Experiments.timeseries(exp, :V_L_new))
plot!(Experiments.timeseries(exp, :V_L))

Experiments.calc!(exp, Experiments.smooth_kalman, :m_L)
plot(Experiments.timeseries(exp, :m_L_smooth_kalman))
plot!(Experiments.timeseries(exp, :m_L))

0 comments on commit 14f8ab1

Please sign in to comment.