Closed behinger closed 1 year ago
function save(file,uf::T;compress=false) where T<:UnfoldModel
jldopen(file, "w"; compress = compress) do f
f["uf"] = T(uf.design,Unfold.DesignMatrix(designmatrix(uf).formulas,missing,designmatrix(uf).events),uf.modelfit)
end
end
function load(file,::Type{<:UnfoldModel})
f = jldopen(file, "r")
uf = f["uf"]
form = designmatrix(uf).formulas
events = designmatrix(uf).events
X = Unfold.modelcols(form.rhs, events)
# reintegrate the designmatrix
return typeof(uf)(uf.design,Unfold.DesignMatrix(form,X,events),uf.modelfit)
end
@jschepers can you try this out with an realistic UnfoldFile?
These tools might be helpful:
pretty_filesize(x) = Base.format_bytes(filesize(x))
pretty_summarysize(x) = Base.format_bytes(Base.summarysize(x))
@time save(joinpath(tempdir(),"test3.jld2"),m;compress=true)
@time save(joinpath(tempdir(),"test4.jld2"),m;compress=false)
begin
sizex = x->pretty_filesize(joinpath(tempdir(),"test$x.jld2"))
@show pretty_summarysize(m)
for k = 1:4
@show sizex(k)
end
end
@time m2 = load(joinpath(tempdir(),"test4.jld2"),UnfoldModel)
m.designmatrix.Xs == m2.designmatrix.Xs
Saved files can be quite large - play around with @save filename.JLD2 {compress} ??
Check why files of a single subject with 128 channels can be 2gb large - seems too big