Skip to content

Commit

Permalink
Migrate examples for PyPlot to CairoMakie
Browse files Browse the repository at this point in the history
  • Loading branch information
nHackel committed Sep 27, 2024
1 parent f90a7a8 commit c46c2e8
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 116 deletions.
15 changes: 7 additions & 8 deletions src/examples/julia/batch.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using RedPitayaDAQServer
using PyPlot
using CairoMakie

include("config.jl")

Expand Down Expand Up @@ -58,11 +58,10 @@ uLastPeriod = readFrames(rp, currentFrame(rp), 2)
masterTrigger!(rp, false)
serverMode!(rp, CONFIGURATION)

figure(1)
clf()
# Frame dimensions are [samples, chan, periods, frames]
plot(vec(uFirstPeriod[:,1,:,:]))
plot(vec(uCurrentPeriod[:,1,:,:]))
plot(vec(uLastPeriod[:,1,:,:]))
legend(("first period", "current period", "last period"))
savefig("images/batch.png")
plot = lines(vec(uFirstPeriod[:,1,:,:]), label = "first period")
lines!(plot.axis, vec(uCurrentPeriod[:,1,:,:]), label = "current period")
lines!(plot.axis, vec(uLastPeriod[:,1,:,:]), label = "last period")
axislegend(plot.axis)
save(joinpath(@__DIR__(), "images", "batch.png"), plot)
plot
22 changes: 10 additions & 12 deletions src/examples/julia/cluster.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using RedPitayaDAQServer
using PyPlot
using CairoMakie

# obtain the URL of the RedPitaya
include("config.jl")
Expand Down Expand Up @@ -44,14 +44,12 @@ uCurrentPeriod = readFrames(rpc, currentFrame(rpc), 1)
masterTrigger!(rpc, false)
serverMode!(rpc, CONFIGURATION)

figure(1)
clf()
subplot(2, 1, 1)
plot(vec(uFirstPeriod[:,1,:,:]))
plot(vec(uFirstPeriod[:,3,:,:]))
legend(("Channel 1", "Channel 3"))
subplot(2, 1, 2)
plot(vec(uCurrentPeriod[:,1,:,:]))
plot(vec(uCurrentPeriod[:,3,:,:]))
legend(("Channel 1", "Channel 3"))
savefig("images/cluster.png")
fig = Figure()
plot = lines(fig[1,1], vec(uFirstPeriod[:,1,:,:]), label = "Channel 1")
lines!(plot.axis, vec(uFirstPeriod[:,3,:,:]), label = "Channel 3")
axislegend(plot.axis)
plot = lines(fig[1, 2], vec(uCurrentPeriod[:,1,:,:]), label = "Channel 1")
lines!(plot.axis, vec(uCurrentPeriod[:,3,:,:]), label = "Channel 3")
axislegend(plot.axis)
save(joinpath(@__DIR__(), "images", "cluster.png"), fig)
fig
13 changes: 4 additions & 9 deletions src/examples/julia/clusterView.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using RedPitayaDAQServer
using PyPlot
using CairoMakie

include("config.jl")

Expand Down Expand Up @@ -46,12 +46,7 @@ sleep(1.0)
# ClusterView only reads from selected RedPitayas
uCurrentPeriod = readData(rpcv, currentFrame(rpc), 1)

fig = figure(1)
clf()
subplot(1,2,1)
plot(vec(uCurrentPeriod[:,1,:,:]))
fig = Figure()
# Channels from result can be mapped to channels in the cluster
PyPlot.title("Cluster channel $(viewToClusterChannel(rpcv,1))")
subplot(1,2,2)
plot(vec(uCurrentPeriod[:,3,:,:]))
PyPlot.title("Cluster channel $(viewToClusterChannel(rpcv,3))")
lines(fig[1, 1], vec(uCurrentPeriod[:,1,:,:]), axis = (title = "Cluster channel $(viewToClusterChannel(rpcv,1))",))
lines(fig[1, 2], vec(uCurrentPeriod[:,3,:,:]), axis = (title = "Cluster channel $(viewToClusterChannel(rpcv,3))",))
2 changes: 1 addition & 1 deletion src/examples/julia/config.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# URLs= ["rp-f08ccb.local", "rp-f08caa.local"]
URLs= ["192.168.2.22"]#, "192.168.2.17"]
URLs= ["192.168.1.100"]#, "192.168.2.17"]
mkpath("images")
17 changes: 7 additions & 10 deletions src/examples/julia/counterTrigger.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using RedPitayaDAQServer
using PyPlot
using CairoMakie
using Statistics
using Base.Threads

Expand Down Expand Up @@ -108,15 +108,12 @@ counterTrigger_enabled!(rp, false)

close(t)

figure(1)
clf()
# Frame dimensions are [samples, chan, periods, frames]
plot(vec(uFirstPeriod[:,1,:,:]))
plot(vec(uCurrentPeriod[:,1,:,:]))
plot(vec(uLastPeriod[:,1,:,:]))
legend(("first period", "current period", "last period"))
savefig("images/counterTrigger.png")

plot = lines(vec(uFirstPeriod[:,1,:,:]), label = "first period")
lines!(plot.axis, vec(uCurrentPeriod[:,1,:,:]), label = "current period")
lines!(plot.axis, vec(uLastPeriod[:,1,:,:]), label = "last period")
axislegend(plot.axis)
save(joinpath(@__DIR__(), "images", "counterTrigger.png"), plot)
plot
#==
0: enable
1: trigger_arm
Expand Down
15 changes: 7 additions & 8 deletions src/examples/julia/counterTriggerCluster.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using RedPitayaDAQServer
using PyPlot
using CairoMakie
using Statistics
using Base.Threads

Expand Down Expand Up @@ -108,15 +108,14 @@ counterTrigger_enabled!(rpc, false)

close(t)

figure(1)
clf()
chan = 3
# Frame dimensions are [samples, chan, periods, frames]
plot(vec(uFirstPeriod[:,chan,:,:]))
plot(vec(uCurrentPeriod[:,chan,:,:]))
plot(vec(uLastPeriod[:,chan,:,:]))
legend(("first period", "current period", "last period"))
savefig("images/counterTrigger.png")
plot = lines(vec(uFirstPeriod[:,chan,:,:]), label = "first period")
lines!(plot.axis, vec(uCurrentPeriod[:,chan,:,:]), label = "current period")
lines!(plot.axis, vec(uLastPeriod[:,chan,:,:]), label = "last period")
axislegend(plot.axis)
save(joinpath(@__DIR__(), "images", "counterTriggerCluster.png"), plot)
plot

#==
0: enable
Expand Down
13 changes: 6 additions & 7 deletions src/examples/julia/delay.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using RedPitayaDAQServer
using PyPlot
using CairoMakie

# obtain the URL of the RedPitaya
include("config.jl")
Expand Down Expand Up @@ -44,10 +44,9 @@ uUncorrected = readSamples(rp, 0, 45, correct_filter_delay = false)
masterTrigger!(rp, false)
serverMode!(rp, CONFIGURATION)

figure(1)
clf()
# Sample dimensions are [chan, samples]
plot(vec(uCorrected[1, :]))
plot(vec(uUncorrected[1, :]))
legend(("first period", "Corrected", "Uncorrected"))
savefig("images/delay.png")
plot = lines(vec(uCorrected[1, :]), label = "Corrected")
lines!(plot.axis, vec(uUncorrected[1, :]), label = "Uncorrected")
axislegend(plot.axis)
save(joinpath(@__DIR__(), "images", "delay.png"), plot)
plot
8 changes: 3 additions & 5 deletions src/examples/julia/producerConsumer.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using RedPitayaDAQServer
using ThreadPools
using PyPlot
using CairoMakie

include("config.jl")

Expand Down Expand Up @@ -141,9 +141,7 @@ else
# Wait for the consumer since otherwise Julia just terminates in non-interactive mode.
wait(consumer)

figure(1)
clf()
# Frame dimensions are [samples, chan, periods, frames]
plot(vec(buffer[:, 1, :, :]))
savefig("images/producerConsumer.png")
plot = lines(vec(buffer[:, 1, :, :]))
save(joinpath(@__DIR__(), "images", "producerConsumer.png"), plot)
end
20 changes: 9 additions & 11 deletions src/examples/julia/ramping.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using RedPitayaDAQServer
using PyPlot
using CairoMakie

# obtain the URL of the RedPitaya
include("config.jl")
Expand Down Expand Up @@ -37,9 +37,8 @@ masterTrigger!(rp, true)

uFirstPeriod = readFrames(rp, 0, 6)


fr = currentFrame(rp)
uCurrentPeriod = readFrames(rp, fr, 6)
sleep(0.5)
uCurrentPeriod = readFrames(rp, currentFrame(rp), 6)

# Start ramp down asynchronously
# Note that we might not see the actual ramping in this example, see seqRamping.jl for that
Expand All @@ -52,11 +51,10 @@ masterTrigger!(rp, false)
serverMode!(rp, CONFIGURATION)
enableRamping!(rp, 1, false)

figure(1)
clf()
# Frame dimensions are [samples, chan, periods, frames]
plot(vec(uCurrentPeriod[:,1,:,:]))
plot(vec(uFirstPeriod[:,1,:,:]))
plot(vec(uLastPeriod[:,1,:,:]))
legend(("regular", "start", "end"))
savefig("images/asyncRamping.png")
plot = lines(vec(uCurrentPeriod[:,1,:,:]), label = "regular")
lines!(plot.axis, vec(uFirstPeriod[:,1,:,:]), label = "start")
lines!(plot.axis, vec(uLastPeriod[:,1,:,:]), label = "end")
axislegend(plot.axis)
save(joinpath(@__DIR__(), "images", "asyncRamping.png"), plot)
plot
11 changes: 5 additions & 6 deletions src/examples/julia/seqRamping.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using RedPitayaDAQServer
using PyPlot
using CairoMakie

# obtain the URL of the RedPitaya
include("config.jl")
Expand Down Expand Up @@ -46,13 +46,12 @@ masterTrigger!(rp, true)
samples_per_step = (samples_per_period * periods_per_frame)/steps_per_frame
uCurrentFrame = readFrames(rp, 0, 4)

fig = figure(1)
clf()
plot(vec(uCurrentFrame[:,1,:,1:4]))

masterTrigger!(rp, false)
serverMode!(rp, CONFIGURATION)
enableRamping!(rp, 1, false)
clearSequence!(rp)

savefig("images/seqRamping.png")
plot = lines(vec(uCurrentFrame[:,1,:,1:4]))

save(joinpath(@__DIR__(), "images", "seqRamping.png"), plot)
plot
14 changes: 6 additions & 8 deletions src/examples/julia/sequence.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using RedPitayaDAQServer
using PyPlot
using CairoMakie

# obtain the URL of the RedPitaya
include("config.jl")
Expand Down Expand Up @@ -42,13 +42,11 @@ samples_per_step = (samples_per_period * periods_per_frame)/steps_per_frame
timing = seqTiming(seq)
uCurrentFrame = readFrames(rp, div(timing.start*samples_per_step, samples_per_period * periods_per_frame), 2)

fig = figure(1)
clf()
plot(vec(uCurrentFrame[:,1,:,:]))
plot(vec(uCurrentFrame[:,2,:,:]))
legend(("Rx1", "Rx2"))

masterTrigger!(rp, false)
serverMode!(rp, CONFIGURATION)

savefig("images/sequence.png")
plot = lines(vec(uCurrentFrame[:,1,:,:]), label = "Rx1")
lines!(plot.axis, vec(uCurrentFrame[:,2,:,:]), label = "Rx2")
axislegend(plot.axis)
save(joinpath(@__DIR__(), "images", "sequence.png"), plot)
plot
19 changes: 8 additions & 11 deletions src/examples/julia/sequenceMultiChannelWithOffsetAndEnable.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using RedPitayaDAQServer
using PyPlot
using CairoMakie

# obtain the URL of the RedPitaya
include("config.jl")
Expand Down Expand Up @@ -29,7 +29,7 @@ phaseDAC!(rp, 1, 1, 0.0)
amplitudeDAC!(rp, 1, 1, 0.1)

# No waveform on second channel
amplitudeDAC!(rp, 2, 1, 0.0)
amplitudeDAC!(rp, 2, 1, 0.2 )

clearSequence!(rp)

Expand All @@ -42,8 +42,7 @@ lut = collect(cat(lutA,lutB*0.1,dims=2)')
# Alternate in disabling the DAC output of the channels from step to step
lutEnableDACA = ones(Bool, steps_per_frame)
lutEnableDACA[1:2:end] .= false
lutEnableDACB = ones(Bool, steps_per_frame)
lutEnableDACB[2:2:end] .= false
lutEnableDACB = map(!, lutEnableDACA)
enableLUT = collect( cat(lutEnableDACA,lutEnableDACB,dims=2)' )

seq = SimpleSequence(lut, 1, enableLUT)
Expand All @@ -57,11 +56,9 @@ uCurrentPeriod = readFrames(rp, 0, 1)
masterTrigger!(rp, false)
serverMode!(rp, CONFIGURATION)

fig = figure(1)
clf()
plot(vec(uCurrentPeriod[:,1,:,:]))
plot(vec(uCurrentPeriod[:,2,:,:]))
legend(("Rx1", "Rx2"))
plot = lines(vec(uCurrentPeriod[:,1,:,:]), label = "Rx1")
lines!(plot.axis, vec(uCurrentPeriod[:,2,:,:]), label = "Rx2")
axislegend(plot.axis)
save(joinpath(@__DIR__(), "images", "sequenceMultiChannelWithOffsetAndEnable.png"), plot)
plot


savefig("images/sequenceMultiChannelWithOffsetAndEnable.png")
15 changes: 7 additions & 8 deletions src/examples/julia/simple.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using RedPitayaDAQServer
using PyPlot
using CairoMakie

# obtain the URL of the RedPitaya
include("config.jl")
Expand Down Expand Up @@ -52,11 +52,10 @@ uLastPeriod = readFrames(rp, currentFrame(rp), 1)
masterTrigger!(rp, false)
serverMode!(rp, CONFIGURATION)

figure(1)
clf()
# Frame dimensions are [samples, chan, periods, frames]
plot(vec(uFirstPeriod[:,1,:,:]))
plot(vec(uCurrentPeriod[:,1,:,:]))
plot(vec(uLastPeriod[:,1,:,:]))
legend(("first period", "current period", "last period"))
savefig("images/simple.png")
plot = lines(vec(uFirstPeriod[:,1,:,:]), label = "first period")
lines!(plot.axis, vec(uCurrentPeriod[:,1,:,:]), label = "current period")
lines!(plot.axis, vec(uLastPeriod[:,1,:,:]), label = "last period")
axislegend(plot.axis)
save(joinpath(@__DIR__(), "images", "simple.png"), plot)
plot
Loading

0 comments on commit c46c2e8

Please sign in to comment.