An option: CMDimData.jl & HDF5
My CMDimData.jl/MDDatasets.jl libraries provide multi-dimensional data structures and functions that can easily be written to/read from HDF5 files. An example of how you can transfer “Ensemble” results to these data structures is shown below.
Create ydataMD
(of type: MDDatasets.DataRS
) from “Ensemble” ydata
array (and x
values):
#Encapsulate multi-dimensional data using MDDatasets.jl structures:
n_trajectories = length(ydata)
ydataMD = fill(DataRS{DataF1}, PSweep("Trajectory", collect(1:n_trajectories))) do trajectory
sol_i = DataF1(x, ydata[trajectory]) #encapsulates (x,y) data in a single structure
return sol_i
end
If you are interested, but have trouble understanding how it works, I can provide further details.
Once ydataMD
is created, you can easily post-process the data over all parameter sweeps without having to explicitly loop through each one. There is example code in the CMDimData.jl README file:
→ GitHub - ma-laforge/CMDimData.jl: Parametric analysis/visualization +continuous-f(x) interpolation
A more complete example
I recently made a few changes to CMDimData.jl, so the following code will only work once v0.4.0 is merged in Julia’s GeneralRegistry:
using MDDatasets #Data containers & post-processing operation
#Higher level plotting routines, supporting MDDataset objects:
using CMDimData, CMDimData.EasyPlot, CMDimData.EasyData
#Build some data like with your own "Ensemble" results:
x = collect(1:100)
ydata = []
for trajectory in 1:50
push!(ydata, rand(length(x)))
end
#Encapsulate multi-dimensional data using MDDatasets.jl structures:
n_trajectories = length(ydata)
ydataMD = fill(DataRS{DataF1}, PSweep("Trajectory", collect(1:n_trajectories))) do trajectory
sol_i = DataF1(x, ydata[trajectory]) #encapsulates (x,y) data in a single structure
return sol_i
end
#Read/write data to HDF5 file:
filepath = "results.hdf5"
datasetid = "EnsembleDataset" #Some string
@info("Writing $filepath...")
EasyData.openwriter(filepath) do w
write(w, ydataMD, datasetid)
end
@info("Reading back $filepath...")
r = EasyData.openreader(filepath)
ydataMD_fromfile = EasyData.readdata(r, datasetid)
close(r)
@show ydataMD_fromfile
As you can see, all data is written out with the write()
and EasyData.readdata()
commands (without having to manually loop through trajectories).
Plot the results
#Show plot (more control required than Plot.jl)
#------------------------------------------------------------------------------
plot = cons(:plot, title = "multi-dimensional data",
xyaxes = set(xscale=:lin, yscale=:lin),
labels = set(xaxis="X-Axis Label", yaxis="Y-Axis Label")
)
#Add all of ydataMD to the plot with a single statement:
push!(plot,
cons(:wfrm, ydataMD, label="ydataMD"),
)
#Display plot itself:
CMDimData.@includepkg EasyPlotInspect #Use InspectDR backend to plot (needs to run only once)
EasyPlot.displaygui(:InspectDR, plot) #Can use other backends