-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ODESolution (and SciMLEnsembleSolution) to DataFrame support (con…
…ditional on 1.9)
- Loading branch information
1 parent
605824a
commit 40abe8d
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module SciMLBaseDataFramesExt | ||
using SciMLBase, DataFrames | ||
|
||
function DataFrames.DataFrame(sol::EnsembleSolution, idxs::AbstractVector) | ||
@assert allequal(getproperty.(sol.u, :t)) "solutions must have shared timesteps" | ||
data = sol[:, idxs] | ||
i_max, j_max, _ = size(data) | ||
v = ["t"=>sol[1].t] | ||
for (i, s) in enumerate(sol.u) | ||
for idx in idxs | ||
push!(v, string("sol ", i, ": ", idx)=>s[idx]) | ||
end | ||
end | ||
DataFrame(v) | ||
end | ||
|
||
function DataFrames.DataFrame(sol::ODESolution, idxs::AbstractVector) | ||
@assert allequal(getproperty.(sol.u, :t)) "solutions must have shared timesteps" | ||
data = sol[:, idxs] | ||
i_max, j_max, _ = size(data) | ||
v = ["t"=>sol[1].t] | ||
for idx in idxs | ||
push!(v, string("sol ", i, ": ", idx)=>s[idx]) | ||
end | ||
DataFrame(v) | ||
end | ||
|
||
end |