Skip to content

Commit

Permalink
Added theta wave to ThetaSeq makie graph, but has a precision issue. …
Browse files Browse the repository at this point in the history
…Possibly what's mentioned here: MakieOrg/Makie.jl#1196 .. Attempting to get around by reducing size of time floats
  • Loading branch information
SynapticSage committed Apr 8, 2022
1 parent 4c176f4 commit 46c3b1f
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 51 deletions.
48 changes: 24 additions & 24 deletions Manifest.toml
Expand Up @@ -54,9 +54,9 @@ version = "3.8.0+0"

[[deps.ArrayInterface]]
deps = ["Compat", "IfElse", "LinearAlgebra", "Requires", "SparseArrays", "Static"]
git-tree-sha1 = "8d4a07999261b4461daae67b2d1e12ae1a097741"
git-tree-sha1 = "c933ce606f6535a7c7b98e1d86d5d1014f730596"
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
version = "5.0.6"
version = "5.0.7"

[[deps.Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
Expand Down Expand Up @@ -637,10 +637,10 @@ uuid = "d7e528f0-a631-5988-bf34-fe36492bcfd7"
version = "2.10.4+0"

[[deps.FreeTypeAbstraction]]
deps = ["ColorVectorSpace", "Colors", "FreeType", "GeometryBasics", "StaticArrays"]
git-tree-sha1 = "8e76bcd47f98ee25c8f8be4b9a1c60f48efa4f9e"
deps = ["ColorVectorSpace", "Colors", "FreeType", "GeometryBasics"]
git-tree-sha1 = "b5c7fe9cea653443736d264b85466bad8c574f4a"
uuid = "663a7486-cb36-511b-a19d-713bb74d65c9"
version = "0.9.7"
version = "0.9.9"

[[deps.FriBidi_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
Expand Down Expand Up @@ -789,9 +789,9 @@ version = "0.1.0"

[[deps.HDF5]]
deps = ["Compat", "HDF5_jll", "Libdl", "Mmap", "Random", "Requires"]
git-tree-sha1 = "1ffca8635410d35aed33facc7840fee647e18b55"
git-tree-sha1 = "cdd249512de03cbf8370365a0a08b9a24955dca9"
uuid = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
version = "0.16.5"
version = "0.16.6"

[[deps.HDF5_jll]]
deps = ["Artifacts", "JLLWrappers", "LibCURL_jll", "Libdl", "OpenSSL_jll", "Pkg", "Zlib_jll"]
Expand Down Expand Up @@ -1091,9 +1091,9 @@ version = "0.22.7"

[[deps.JuliaInterpreter]]
deps = ["CodeTracking", "InteractiveUtils", "Random", "UUIDs"]
git-tree-sha1 = "9c43a2eb47147a8776ca2ba489f15a9f6f2906f8"
git-tree-sha1 = "cd6ce9cee498f6b044357cb439f2a3fea3d450df"
uuid = "aa1ae85d-cabe-5617-a682-6adf51b2e16a"
version = "0.9.11"
version = "0.9.12"

[[deps.Juno]]
deps = ["Base64", "Logging", "Media", "Profile"]
Expand Down Expand Up @@ -1282,9 +1282,9 @@ uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"

[[deps.LoopVectorization]]
deps = ["ArrayInterface", "CPUSummary", "ChainRulesCore", "CloseOpenIntervals", "DocStringExtensions", "ForwardDiff", "HostCPUFeatures", "IfElse", "LayoutPointers", "LinearAlgebra", "OffsetArrays", "PolyesterWeave", "SIMDDualNumbers", "SLEEFPirates", "SpecialFunctions", "Static", "ThreadingUtilities", "UnPack", "VectorizationBase"]
git-tree-sha1 = "0ad02fdd8009e42eb52fcef08a4130465e055ebc"
git-tree-sha1 = "aa73a4f9379db5b4d573bce890289fb34239403d"
uuid = "bdcacae8-1622-11e9-2a5c-532679323890"
version = "0.12.104"
version = "0.12.105"

[[deps.LoweredCodeUtils]]
deps = ["JuliaInterpreter"]
Expand Down Expand Up @@ -1659,10 +1659,10 @@ uuid = "eebad327-c553-4316-9ea0-9fa01ccd7688"
version = "0.1.1"

[[deps.PlotThemes]]
deps = ["PlotUtils", "Requires", "Statistics"]
git-tree-sha1 = "a3a964ce9dc7898193536002a6dd892b1b5a6f1d"
deps = ["PlotUtils", "Statistics"]
git-tree-sha1 = "8162b2f8547bc23876edd0c5181b27702ae58dce"
uuid = "ccf2f8ad-2431-5c83-bf29-c5338b663b6a"
version = "2.0.1"
version = "3.0.0"

[[deps.PlotUtils]]
deps = ["ColorSchemes", "Colors", "Dates", "Printf", "Random", "Reexport", "Statistics"]
Expand All @@ -1684,9 +1684,9 @@ version = "0.18.8"

[[deps.Plots]]
deps = ["Base64", "Contour", "Dates", "Downloads", "FFMPEG", "FixedPointNumbers", "GR", "GeometryBasics", "JSON", "Latexify", "LinearAlgebra", "Measures", "NaNMath", "Pkg", "PlotThemes", "PlotUtils", "Printf", "REPL", "Random", "RecipesBase", "RecipesPipeline", "Reexport", "Requires", "Scratch", "Showoff", "SparseArrays", "Statistics", "StatsBase", "UUIDs", "UnicodeFun", "Unzip"]
git-tree-sha1 = "edec0846433f1c1941032385588fd57380b62b59"
git-tree-sha1 = "88ee01b02fba3c771ac4dce0dfc4ecf0cb6fb772"
uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
version = "1.27.4"
version = "1.27.5"

[[deps.Pluto]]
deps = ["Base64", "Configurations", "Dates", "Distributed", "FuzzyCompletions", "HTTP", "InteractiveUtils", "Logging", "Markdown", "MsgPack", "Pkg", "REPL", "Sockets", "TableIOInterface", "Tables", "UUIDs"]
Expand Down Expand Up @@ -1787,9 +1787,9 @@ version = "0.7.3"

[[deps.Quaternions]]
deps = ["DualNumbers", "LinearAlgebra", "Random"]
git-tree-sha1 = "522770af103809e8346aefa4b25c31fbec377ccf"
git-tree-sha1 = "3754f35199da1bb4a55211ddbfd64cb1efee2272"
uuid = "94ee1d12-ae83-5a48-8b1c-48b8ff168ae0"
version = "0.5.3"
version = "0.5.4"

[[deps.REPL]]
deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"]
Expand Down Expand Up @@ -1864,9 +1864,9 @@ version = "0.6.2"

[[deps.Roots]]
deps = ["CommonSolve", "Printf", "Setfield"]
git-tree-sha1 = "6085b8ac184add45b586ed8d74468310948dcfe8"
git-tree-sha1 = "838b60ee62bebc794864c880a47e331e00c47505"
uuid = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
version = "1.4.0"
version = "1.4.1"

[[deps.Rotations]]
deps = ["LinearAlgebra", "Quaternions", "Random", "StaticArrays", "Statistics"]
Expand Down Expand Up @@ -2159,9 +2159,9 @@ version = "0.4.1"

[[deps.UnicodePlots]]
deps = ["ColorTypes", "Contour", "Crayons", "Dates", "FileIO", "FreeTypeAbstraction", "LinearAlgebra", "MarchingCubes", "NaNMath", "SparseArrays", "StaticArrays", "StatsBase", "Unitful"]
git-tree-sha1 = "e7b68f6d25a79dff79acbd3bcf324db4385c2c6f"
git-tree-sha1 = "c3bab41f0910b8e3e70d88ee24a68ab952ec0a76"
uuid = "b8865327-cd53-5732-bb35-84acbb429228"
version = "2.10.1"
version = "2.10.3"

[[deps.Unitful]]
deps = ["ConstructionBase", "Dates", "LinearAlgebra", "Random"]
Expand All @@ -2176,9 +2176,9 @@ version = "0.1.2"

[[deps.VectorizationBase]]
deps = ["ArrayInterface", "CPUSummary", "HostCPUFeatures", "Hwloc", "IfElse", "LayoutPointers", "Libdl", "LinearAlgebra", "SIMDTypes", "Static"]
git-tree-sha1 = "a48484def839a98571683a8b5b942fc910329480"
git-tree-sha1 = "460aacceb20a12ec187eb8ca183c5944dc6c99c4"
uuid = "3d5dd08c-fd9d-11e8-17fa-ed2836048c2f"
version = "0.21.26"
version = "0.21.28"

[[deps.VersionParsing]]
git-tree-sha1 = "58d6e80b4ee071f5efd07fda82cb9fbe17200868"
Expand Down
49 changes: 30 additions & 19 deletions scripts/decode/ThetaSeqPlots.jl
@@ -1,3 +1,6 @@
#
# TODO: Add points ahead of and behind animal
# TODO: Add theta wave to scatter
using DrWatson
quickactivate(expanduser("~/Projects/goal-code"))
using Pushover, Revise, Interact, Blink, Mux, ProgressMeter
Expand All @@ -6,6 +9,7 @@ using VideoIO
using ColorSchemes, Colors
import ColorSchemeTools
import DSP
using StatsPlots
savestuff = false
if savestuff
using CairoMakie, Makie
Expand Down Expand Up @@ -50,9 +54,9 @@ thresh_var = Dict("likelihood"=>0.1,
"acausal_posterior"=>0.985,
"causal_posterior"=>0.985)
outputVideo = "animation.$(decoder_type)_$(transition_type)_$(split_type)_$(split)_$(variable)_$(basename(video))"
utils.mkifne(plotsdir("ripples","mpp_decode", "withBehVideo=$usevideo", outputVideo))
utils.mkifne(plotsdir("ripples","mpp_decode"))
utils.mkifne(plotsdir("ripples","mpp_decode","withBehVideo=$usevideo"))
utils.mkifne(plotsdir("theta","mpp_decode", "withBehVideo=$usevideo", outputVideo))
utils.mkifne(plotsdir("theta","mpp_decode"))
utils.mkifne(plotsdir("theta","mpp_decode","withBehVideo=$usevideo"))
wells = task[(task.name.=="welllocs") .& (task.epoch .== epoch), :]
utils.pushover("Finished preprocess sequenece")

Expand All @@ -73,50 +77,57 @@ end
dat = permutedims(D[variable], [2,1,3])
#mint = minimum(beh[beh.epoch.==epoch,:].time)

# Ready theta waves
beh, spikes, lfp, D = raw.normalize_time(beh, spikes, lfp, D);

tetrode = 5
load_cycles = false
load_cycles = true
lfp = raw.lfp.annotate_cycles(raw.lfp.getTet(lfp,5), method="peak-to-peak")
lfp.phase = raw.lfp.phase_to_radians(lfp.phase)
if load_cycles
cycles = raw.load_cycles(animal, day, tetrode)
else
lfp = raw.lfp.annotate_cycles(raw.lfp.getTet(lfp,5), method="peak-to-peak")
lfp.phase = raw.lfp.phase_to_radians(lfp.phase)
cycles = raw.lfp.get_cycle_table(lfp)
raw.save_cycles(cycles, animal, day, tetrode)
end
validcycles = filter(:amp_mean => amp->(amp .> 50) .& (amp .< 600), cycles)
validcycles = filter( => dur->(dur .> 0.025) .& (dur .< 0.4), validcycles)

@showprogress for (cyc, cycle) in enumerate(eachrow(validcycles))
@showprogress for (cyc, cycle) in collect(enumerate(eachrow(validcycles)))[93741:end]
start, stop = cycle.start, cycle.end
filt = (D["time"].>=start) .& (D["time"].<=stop)
if any(filt)
println(cyc)
dat_sub = dat[:,:, filt]
lfp_filt = (lfp[!,"time"].>=start) .& (lfp[!,"time"].<=stop)
break
lfp_sub = lfp[lfp_filt, :]
else
continue
end
B = beh[(beh.time.>=start) .& (beh.time.<=stop),:]
if isempty(B)
@warn "Empty behavior for cycle $cyc"
continue
end

fig=Figure()
B = beh[(beh.time.>=start) .& (beh.time.<=stop),:]
sp = copy(spikes[(spikes.time.>start) .& (spikes.time .<stop),:])
sp = groupby(sp, :unit)
sp = [sp...]
sp = sort(sp, by=x->median(x.time))
lfp_sub.raw = utils.norm_extrema(lfp_sub.raw, [0,length(sp)])
ax = Axis(fig[4,1])
α = 0.1
for (i,unit) in enumerate(sp)
print(i, " ")
cmap = get(ColorSchemes.hawaii, ((unit.time.-start)./(stop-start)))
cmap = parse.(Colorant, cmap)
jitter=* rand(Float64,size(unit.time))) .- α/2
try
cmap = get(ColorSchemes.hawaii, ((unit.time.-start)./(stop-start)))
cmap = parse.(Colorant, cmap)
jitter=* rand(Float64,size(unit.time))) .- α/2
scatter!(ax, unit.time, i*ones(size(unit.time))*4, color=cmap, strokewidth=1, markersize=3)
line!(ax, )
GLMakie.scatter!(ax, unit.time, i*ones(size(unit.time))*4, color=cmap, strokewidth=1, markersize=3)
catch
@warn "$i failed"
end
end
lines!(ax, lfp_sub.time, lfp_sub.raw)

# -----------------
# READY HEATMAP VARS
Expand All @@ -138,7 +149,7 @@ validcycles = filter(:δ => dur->(dur .> 0.025) .& (dur .< 0.4), validcycles)
area = "CA1"
color = decode.scatter.marker_color([area])
sc_glow_color = decode.scatter.glow_color([area])
sc_glow_width = cycle.amp_mean/10
sc_glow_width = cycle.amp_mean/20

# ----------------------------
# SETUP FIGURE, AXIS, ARTISTIS
Expand Down Expand Up @@ -172,10 +183,10 @@ validcycles = filter(:δ => dur->(dur .> 0.025) .& (dur .< 0.4), validcycles)
label = "Time", flipaxis = false, vertical=false)

if savestuff
for e in ["pdf","svg"]
for e in ["pdf","png"]
savefile = plotsdir("theta","mpp_decode", "withBehVideo=$usevideo",
outputVideo,
"cycle=$cyc.$area.$tetrode.amp=$(round(ripple.amp,digits=2))" *
"cycle=$cyc.$area.$tetrode.amp=$(round(cycle.amp_mean,digits=2))" *
".$e")
save(savefile, fig, pt_per_unit = 1)
end
Expand Down
12 changes: 6 additions & 6 deletions src/field.jl
Expand Up @@ -579,7 +579,7 @@ module field
else; kwargs = ()
end
l = func(x..., F; kwargs..., kws...)
annotate_field(key=key, keyappend=keyappend, keyprepend=keyprepend,
annotate_field(l; key=key, keyappend=keyappend, keyprepend=keyprepend,
grid=grid, textcolor=textcolor,
justification=justification,
location=location,nplots=nplots,
Expand Down Expand Up @@ -607,7 +607,7 @@ module field
c=cgrad(:acton,rev=false), showaxis=:no, kws...)
#old cms = :linear_kryw_5_100_c67_n256
#:lajolla
annotate_field(key=key, keyappend=keyappend, keyprepend=keyprepend,
annotate_field(hm; key=key, keyappend=keyappend, keyprepend=keyprepend,
grid=grid, textcolor=textcolor,
justification=justification,
location=location,nplots=nplots,
Expand All @@ -625,8 +625,8 @@ module field
return Plots.plot()
end
if seriestype isa Symbol
Plots.plot3d(F; seriestype=seriestype, kws...)
annotate_field(key=key, keyappend=keyappend, keyprepend=keyprepend,
p = Plots.plot3d(F; seriestype=seriestype, kws...)
annotate_field(p, key=key, keyappend=keyappend, keyprepend=keyprepend,
grid=grid, textcolor=textcolor,
justification=justification,
location=location, nplots=nplots,
Expand All @@ -639,11 +639,11 @@ module field
fontsize=fontsize, location=location,
nplots=nplots,
nplots_factor=nplots_factor,
quant=quant)
quant=quant),
F, dims=slice_dim)
end
end
function annotate_field(;
function annotate_field(hm;
key::Union{String,NamedTuple,Nothing}=NamedTuple(),
keyappend::Union{String,NamedTuple,Nothing}=nothing,
keyprepend::Union{String,NamedTuple,Nothing}=nothing,
Expand Down
22 changes: 20 additions & 2 deletions src/raw.jl
Expand Up @@ -576,8 +576,8 @@ module raw
end
function load(pos...; kws...)
videopath = get_path(pos...; kws...)
stream = VideoIO.open(videopath)
vid = VideoIO.openvideo(stream)
stream = VideoIO.open(videopath)
vid = VideoIO.openvideo(stream)
end
end
export video
Expand Down Expand Up @@ -624,4 +624,22 @@ module raw
end
export dlc

function normalize_time(data::Union{DataFrame, Dict}...)
if data[1] isa DataFrame
println("a")
tₘ = minimum(data[1].time)
else
println("b")
tₘ = minimum(data[1]["time"])
end
for source 1:length(data)
if data[source] isa DataFrame && ("time" names(data[source]))
data[source].time = data[source].time .- tₘ
elseif "time" keys(data[source])
data[source]["time"] = data[source]["time"] .- tₘ
end
end
return data
end

end
7 changes: 7 additions & 0 deletions src/utils.jl
Expand Up @@ -38,6 +38,13 @@ function pnf(X::T) where T <: Dict
println(Dict(key=>mean(isnan.(x)) for (key,x) in X))
end

function norm_extrema(x::Vector{T1}, minmax::Union{Vector{T2},Tuple{T2}}) where
T1 <: Real where T2 <: Real
@assert (minmax[2]-minmax[1]) .> 0
x = (x .- minimum(x))./(maximum(x) - minimum(x))
x = x .* diff(minmax) .+ minmax[1]
end

function squeeze(A::AbstractArray)
s = size(A)
A = dropdims(A, dims = tuple(findall(size(A) .== 1)...))
Expand Down

0 comments on commit 46c3b1f

Please sign in to comment.