Created
October 18, 2023 01:32
-
-
Save russelljjarvis/33dae78306b65e72715bd57d8c2173ab to your computer and use it in GitHub Desktop.
Reading Long term stability of cortical ensembles
This file contains hidden or 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
using Plots | |
using MAT | |
using StatsBase | |
using JLD2 | |
using OnlineStats | |
using SparseArrays | |
using DelimitedFiles | |
using DataFrames | |
using Revise | |
function get_all_exempler_days() | |
FPS = matread("../JPMatlabFiles/M4 analyzed2DaysV.mat")["dataIntersected"][1]["Movie"]["FPS"] | |
frame_width = 1.0/FPS #0.08099986230023408 #second, sample_rate = 12.3457#Hz | |
length_of_spike_mat0 = length(matread("../JPMatlabFiles/M4 analyzed2DaysV.mat")["dataIntersected"]) | |
length_of_spike_mat1 = 1:6 | |
current_max_t = 0.0 | |
tt = Vector{Float32}([]) | |
nn = Vector{UInt32}([]) | |
init_mat = Vector{Any}([]) | |
@inbounds for i in 1:length_of_spike_mat0 | |
#if "Transients" in keys(matread("../JesusMatlabFiles/M1 analyzed2DaysV.mat")["dataIntersected"][i]) | |
# init_mat = matread("../JesusMatlabFiles/M1 analyzed2DaysV.mat")["dataIntersected"][i]["Transients"]["Raster"] | |
# end | |
@inbounds for j in 1:6 | |
if "Transients" in keys(matread("../JPMatlabFiles/M$j analyzed2DaysV.mat")["dataIntersected"][i]) | |
temp = matread("../JPMatlabFiles/M$j analyzed2DaysV.mat")["dataIntersected"][1]["Transients"]["Raster"] | |
if j==1 | |
init_mat = copy(matread("../JPMatlabFiles/M$j analyzed2DaysV.mat")["dataIntersected"][i]["Transients"]["Raster"]) | |
else | |
init_mat = vcat(init_mat,copy(temp)) | |
end | |
end | |
end | |
#@show(init_mat) | |
(nodes,times,whole_duration) = convert_bool_matrice_to_raster(init_mat,frame_width) | |
Plots.scatter(times,nodes) | |
savefig("plot_scatter.png") | |
times = [t+current_max_t for t in times ] | |
current_max_t = maximum(times) | |
append!(tt,times) | |
append!(nn,nodes) | |
end | |
Plots.scatter(tt,nn,legend = false, markersize = 0.5,markerstrokewidth=0,alpha=0.8, bgcolor=:snow2, fontcolor=:blue,xlabel="Time (ms)", ylabel="Neuron ID") | |
savefig("long.png") | |
(nn::Vector{UInt32},tt::Vector{Float32},current_max_t::Real) | |
end | |
function load_datasets_calcium_v1() | |
(nodes,times,whole_duration) = get_all_exempler_of_days() | |
spikes_ragged,numb_neurons = create_spikes_ragged(nodes,times) | |
(times::Vector{Float32},nodes::Vector{UInt32},whole_duration::Real,spikes_ragged::Vector{Any},numb_neurons::Int) | |
end | |
""" | |
A method to re-represent dense boolean vectors as a two dense vectors of spikes, and times. | |
spikes is a matrix with regularly sampled windows, populated by spikes, with calcium spikes. | |
""" | |
function convert_bool_matrice_to_raster(read_spike_dense::Matrix{Bool}, frame_width::Real) | |
nodes = UInt32[] | |
times = Float32[] | |
@inbounds for (indy,row) in enumerate(eachrow(read_spike_dense)) | |
for (indx,x) in enumerate(row) | |
if x | |
push!(nodes,indy) | |
push!(times,indx*frame_width) | |
end | |
end | |
end | |
whole_duration = length(read_spike_dense[1,:])*frame_width | |
(nodes::Vector{UInt32},times::Vector{Float32},whole_duration::Real) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment