Skip to content

Commit

Permalink
fix voltage_timeseries for single neurons
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrevaya committed Oct 4, 2024
1 parent 0f1fb20 commit a0afb02
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions src/blox/blox_utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,18 @@ function mean_firing_rate(spikes::SparseMatrixCSC, sol; trim_transient = 0,
return t, rₘ
end

function state_timeseries(blox, sol::SciMLBase.AbstractSolution, state::String; ts=nothing)

namespaced_name = namespaced_nameof(blox)
state_name = Symbol(namespaced_name, "$(state)")

if isnothing(ts)
return sol[state_name]
else
return Array(sol(ts, idxs = state_name))
end
end

function state_timeseries(cb::Union{CompositeBlox, AbstractVector{<:AbstractNeuronBlox}},
sol::SciMLBase.AbstractSolution, state::String; ts=nothing)

Expand All @@ -502,36 +514,43 @@ function state_timeseries(cb::Union{CompositeBlox, AbstractVector{<:AbstractNeur
return s
end

function meanfield_timeseries(cb::Union{CompositeBlox, AbstractVector{<:AbstractNeuronBlox}}, sol::SciMLBase.AbstractSolution,
state::String; ts=nothing)
function meanfield_timeseries(cb::Union{CompositeBlox, AbstractVector{<:AbstractNeuronBlox}},
sol::SciMLBase.AbstractSolution, state::String; ts=nothing)

s = state_timeseries(cb, sol, state; ts)

return vec(mapslices(nanmean, s; dims = 2))
end

function voltage_timeseries(cb::Union{CompositeBlox, AbstractVector{<:AbstractBlox}}, sol::SciMLBase.AbstractSolution; ts=nothing)
voltage_timeseries(blox, sol::SciMLBase.AbstractSolution; ts=nothing) =
state_timeseries(blox, sol, "V"; ts)

function voltage_timeseries(cb::Union{CompositeBlox, AbstractVector{<:AbstractBlox}},
sol::SciMLBase.AbstractSolution; ts=nothing)
return state_timeseries(cb, sol, "V"; ts)
end

function meanfield_timeseries(cb::Union{CompositeBlox, AbstractVector{<:AbstractNeuronBlox}}, sol::SciMLBase.AbstractSolution; ts=nothing)
function meanfield_timeseries(cb::Union{CompositeBlox, AbstractVector{<:AbstractNeuronBlox}},
sol::SciMLBase.AbstractSolution; ts=nothing)
V = voltage_timeseries(cb, sol; ts)
replace_refractory!(V, cb, sol)

return vec(mapslices(nanmean, V; dims = 2))
end

function powerspectrum(cb::Union{CompositeBlox, AbstractVector{<:AbstractNeuronBlox}}, sol::SciMLBase.AbstractSolution, state::String;
sampling_rate=nothing, method=periodogram, window=nothing)
function powerspectrum(cb::Union{CompositeBlox, AbstractVector{<:AbstractNeuronBlox}},
sol::SciMLBase.AbstractSolution, state::String; sampling_rate=nothing,
method=periodogram, window=nothing)

t_sampled, sampling_freq = get_sampling_info(sol; sampling_rate=sampling_rate)
s = meanfield_timeseries(cb, sol, state; ts = t_sampled)

return method(s, fs=sampling_freq, window=window)
end

function powerspectrum(cb::Union{CompositeBlox, AbstractVector{<:AbstractNeuronBlox}}, sol::SciMLBase.AbstractSolution;
sampling_rate=nothing, method=periodogram, window=nothing)
function powerspectrum(cb::Union{CompositeBlox, AbstractVector{<:AbstractNeuronBlox}},
sol::SciMLBase.AbstractSolution; sampling_rate=nothing,
method=periodogram, window=nothing)

t_sampled, sampling_freq = get_sampling_info(sol; sampling_rate=sampling_rate)
V = voltage_timeseries(cb, sol; ts = t_sampled)
Expand Down

0 comments on commit a0afb02

Please sign in to comment.