diff --git a/src/models.jl b/src/models.jl index 065687ff37d728c25623c86c124e89c4c00c0b1e..1351c3deff41cec84ae9848c86b84738e304ee64 100644 --- a/src/models.jl +++ b/src/models.jl @@ -270,3 +270,13 @@ function medianlarvasize(larvae::Vector{LarvaModel}; n::Int=100) end return median(sizes) end + +function simultaneouslarvae(larvae) + laststep = maximum([larva.alignedsteps[end] for larva in values(larvae)]) + n = 0 + for step in 1:20:laststep + n = max(n, count(larva -> larva.alignedsteps[1] <= step <= larva.alignedsteps[end], + values(larvae))) + end + return n +end diff --git a/src/viewer.jl b/src/viewer.jl index ae7d191625a0c8b0b468632e30da3dc5ca3b8903..325cb7d76fa8c0951a2bd70eba555d50070c0abc 100644 --- a/src/viewer.jl +++ b/src/viewer.jl @@ -67,7 +67,14 @@ function larvaviewer(controller; controller[:player] = player = timecontroller(times) controller[:larva] = larva = LarvaController(controller, model, tag_lut, player) - delayed_controller = slave(larva, PeriodicObservation(1.0)) + + n_simultaneous_larvae = simultaneouslarvae(model) + if 40 < n_simultaneous_larvae + @info "Refresh rate throttled to 1Hz" n_simultaneous_larvae + delayed_controller = slave(larva, PeriodicObservation(1.0)) + else + delayed_controller = larva + end on(getactivelarva(controller)) do id @info isnothing(id) ? "No active larva" : "Activating larva #$(id)" diff --git a/src/wgl.jl b/src/wgl.jl index 991194ef64789464a6ef95fe889ae16db493d125..264b3e1b04a57c8f8a88b5b2bfc44b975576742a 100644 --- a/src/wgl.jl +++ b/src/wgl.jl @@ -129,10 +129,15 @@ function AssayPlot(ctrl, larvae::DecoratedLarvae; size=(1000, 750)) AssayPlot(ctrl, fig, ax, larvae, button) end -function AssayPlot(ctrl, larvae::Vector{LarvaModel}; kwargs...) - sample = downsampler() +function AssayPlot(ctrl, larvae::Vector{LarvaModel}; downsampling_threshold=1e5, kwargs...) + npoints = sum([length(larva.path) for larva in larvae]) + if downsampling_threshold <= npoints + @info "Trajectory down-sampling active" npoints + sample = downsampler() + larvae = sample.(larvae) + end plot = AssayPlot(ctrl, - DecoratedLarvae(sample.(larvae), + DecoratedLarvae(larvae, gettags(ctrl), gettimestep(ctrl)); kwargs...)