Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
*don't conflict with `time` in Base
*fix accessing the wrong columns for the voltage average
  • Loading branch information
agchesebro committed Aug 13, 2024
1 parent e095eb5 commit 5b865f4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions test/extract_saved_voltages.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using FileIO
using DataFrames

# Loading single file - will loop to load all eventually
data = load("/Users/achesebro/Downloads/sim0003.jld2")
df = data["df"]
all_voltages = select(df, r"₊V")
time = select(df, :timestamp)[:, 1]
time_vec = select(df, :timestamp)[:, 1]

# Get all region names

Expand All @@ -21,8 +22,8 @@ unique_names = unique(unique_names)

# Get unique time indices (not originally unique because of the callbacks)
time_indices = Vector{Int}()
for i in eachindex(time)
if i == 1 || time[i] != time[i-1]
for i in eachindex(time_vec)
if i == 1 || time_vec[i] != time_vec[i-1]
push!(time_indices, i)
end
end
Expand All @@ -32,10 +33,11 @@ regions = zeros(length(time_indices), length(unique_names))

for i in eachindex(unique_names)
name = unique_names[i]
region = select(df, Regex(name))
region = select(all_voltages, Regex(name))
temp = reduce(+, eachcol(region)) ./ ncol(region)
println(size(region))
regions[:, i] = temp[time_indices]
end

using Plots
plot(time[time_indices], regions, xlabel="Time", ylabel="Voltage", title="Average Voltage in Each Region")
plot(time_vec[time_indices], regions, xlabel="Time", ylabel="Voltage", title="Average Voltage in Each Region")

0 comments on commit 5b865f4

Please sign in to comment.