-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualization.jl
More file actions
213 lines (170 loc) · 7.78 KB
/
visualization.jl
File metadata and controls
213 lines (170 loc) · 7.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
function plot2DSM(grid, smFT, MX, MY, rec; ref=nothing, showaxis=false, anisotropyAxis=nothing)
freqidx = Int[]
for (iy,my) in enumerate(MY)
for (ix,mx) in enumerate(MX)
ax = CairoMakie.Axis(grid[ix, iy], ylabel="",
xticklabelsvisible=false, xticksvisible=false)
idx = (mx-1)*16+(my-1)*17+1
push!(freqidx, idx)
c = smFT[:, :, idx, rec]
if ref == nothing
ref = copy(smFT)
end
if (mx == 1 && my == 1) || (mx == 2 && my == 1) || (mx == 1 && my == 2)
c .= maximum(abs.(ref[:, :, :, rec]))
end
amax = maximum(abs.(ref[:, :, idx, rec]))
A = collect(transpose(ImageUtils.complexColoring(collect((c)); amax))) #
CairoMakie.heatmap!(ax, A)
hidedecorations!(ax, grid=false, label=false)
tightlimits!(ax)
if showaxis && (ix == 1) && (iy == 1)
as_ = 7.6
fs_ = 14
Q1_ = size(A,1)
Q2_ = size(A,2)
arrows!(ax, [Q1_*0.1,Q1_*0.1], [Q2_*0.95,Q2_*0.95],
[Q1_*0.1,0], [0,-Q2_*0.1], color=:white,
arrowsize=as_, lengthscale=3.0, linewidth = 1.5 )
text!(ax, [Q1_*0.05,Q1_*(0.45)],[Q2_*(0.95-0.6),Q2_*(0.82)], text=[rich("x", font=:bold_italic),rich("y", font=:bold_italic)],
color=:white, fontsize=fs_ )
end
if anisotropyAxis != nothing && (ix == 1) && (iy == 1)
Q1_ = size(A,1)
Q2_ = size(A,2)
F = 2
lines!(ax, [1+F,Q1_-F],[Q2_-F,1+F], color=:yellow, linewidth = 1.5)
end
end
end
rowgap!(grid, 5)
colgap!(grid, 5)
return freqidx
end
function plotSMs(SMeas, SCorr, bSF, rec = 2, filenamePrefix = "SM", anisotropyAxis = nothing)
MX = 2:2:9
MY = 2:2:9
fig = Figure( size = (1300, 1200), figure_padding = 1 )#, fontsize = 16)
gr1 = GridLayout()
fig[1,1] = gr1
gr2 = GridLayout()
fig[2,1] = gr2
gr3 = GridLayout()
fig[2,2] = gr3
gr4 = GridLayout()
fig[2,3] = gr4
gr5 = GridLayout()
fig[2,4] = gr5
gr6 = GridLayout()
fig[3,1] = gr6
gr7 = GridLayout()
fig[3,2] = gr7
gr8 = GridLayout()
fig[3,3] = gr8
gr9 = GridLayout()
fig[3,4] = gr9
smEq = SCorr[:Eq_TFEst]
smEqAnis = SCorr[:EqAnis_TFEst]
smEqAnisRed = SCorr[:EqAnisRed_TFEst]
smFP = SCorr[:FP_TFEst]
# change to measured TFs
#smEq = SCorr[:Eq_TFMeas]
#smEqAnis = SCorr[:EqAnis_TFMeas]
#smEqAnisRed = SCorr[:EqAnisRed_TFMeas]
#smFP = SCorr[:FP_TFMeas]
smModels = [smFP, smEqAnis, smEqAnisRed, smEq]
freqidx = plot2DSM(gr1, SMeas, MX, MY, rec; showaxis=true, anisotropyAxis)
plot2DSM(gr2, smFP, MX, MY, rec )
plot2DSM(gr3, smEqAnis, MX, MY, rec )
plot2DSM(gr4, smEqAnisRed, MX, MY, rec )
plot2DSM(gr5, smEq, MX, MY, rec )
plot2DSM(gr6, smFP - SMeas, MX, MY, rec; ref=SMeas*0.5 )
plot2DSM(gr7, smEqAnis - SMeas, MX, MY, rec; ref=SMeas*0.5 )
plot2DSM(gr8, smEqAnisRed - SMeas, MX, MY, rec; ref=SMeas*0.5 )
plot2DSM(gr9, smEq - SMeas, MX, MY, rec; ref=SMeas*0.5 )
for r in [(1,1),(2,1),(2,2),(2,3),(2,4),(3,1),(3,2),(3,3),(3,4)]
ax_ = CairoMakie.Axis(fig[r[1],r[2]], xlabel=rich("κ", subscript("y"), font=:italic),
ylabel = rich("κ", subscript("x"), font=:italic), yreversed = true,
ylabelpadding = 2, xlabelpadding = 2, xticks = MX.-1, yticks = MY.-1,
limits=(0.1,maximum(MX)-1+0.9,0.1,maximum(MY)-1+0.9))
end
Label(fig[1, 1, Top()], "Measured", valign = :bottom, font = :bold, #fontsize = 24,
padding = (0, 0, 5, 0))
strDataset = ["FP", "EQANIS", "red. EQANIS", "EQ"]
for l=1:length(strDataset)
Label(fig[2, l, Top()], strDataset[l], valign = :bottom, font = :bold, #fontsize = 24,
padding = (0, 0, 5, 0))
end
Label(fig[3, 1, Top()], "Diff: FP - Measured", valign = :bottom, font = :bold, #fontsize = 24,
padding = (0, 0, 5, 0))
Label(fig[3, 2, Top()], "Diff: EQANIS - Measured", valign = :bottom, font = :bold, #fontsize = 24,
padding = (0, 0, 5, 0))
Label(fig[3, 3, Top()], "Diff: red. EQANIS - Measured", valign = :bottom, font = :bold, #fontsize = 24,
padding = (0, 0, 5, 0))
Label(fig[3, 4, Top()], "Diff: EQ - Measured", valign = :bottom, font = :bold, #fontsize = 24,
padding = (0, 0, 5, 0))
C = collect(range(0,1,length=100)) *
transpose(exp.(2*π*im*collect(range(0,1,length=100))))
axleg, pleg = CairoMakie.heatmap(fig[2,5],
(complexColoring(C)),
axis=(ylabel="Phase", xlabel="Amplitude", #title="colorbar", titlefont = :bold,
#titlesize = 24,
yaxisposition = :right,
xticks=([1,100],["0","1"]),
yticks=([0.5,50,100.5],["0", "π", "2π"])))
axleg, pleg = CairoMakie.heatmap(fig[3,5],
(complexColoring(C)),
axis=(ylabel="Phase", xlabel="Amplitude", #title="colorbar", titlefont = :bold,
#titlesize = 24,
yaxisposition = :right,
xticks=([1,100],["0","0.5"]),
yticks=([0.5,50,100.5],["0", "π", "2π"])))
colsize!(fig.layout, 5, Aspect(1, 0.1))
energyMeas = maximum(reshape(abs.(SMeas),size(SMeas,1)*size(SMeas,2),size(SMeas,3),size(SMeas,4)),dims=1)
energyFP = maximum(reshape(abs.(smFP),size(SMeas,1)*size(SMeas,2),size(SMeas,3),size(SMeas,4)),dims=1)
energyEq = maximum(reshape(abs.(smEq),size(SMeas,1)*size(SMeas,2),size(SMeas,3),size(SMeas,4)),dims=1)
energyEqAnis = maximum(reshape(abs.(smEqAnis),size(SMeas,1)*size(SMeas,2),size(SMeas,3),size(SMeas,4)),dims=1)
energyEqAnisRed = maximum(reshape(abs.(smEqAnisRed),size(SMeas,1)*size(SMeas,2),size(SMeas,3),size(SMeas,4)),dims=1)
ax = CairoMakie.Axis(fig[1, 2:5], yscale = log10, alignmode = Outside(10,0,-40,0),
xlabel = rich(rich("f", font=:italic), " / kHz"),
ylabel = "Row Energy")
freq = rxFrequencies(bSF) ./ 1000
fidx = 1:(div(length(rxFrequencies(bSF)),3))
ls = [:solid, :solid, :dashdot, :dashdotdot, :dot]
lw = 3
CairoMakie.lines!(ax, freq[fidx], energyMeas[1,fidx,rec], color = RGBf(colors[1]...),
label = "Measured", linewidth=lw, linestyle = ls[1] )
CairoMakie.lines!(ax, freq[fidx], energyFP[1, fidx,rec], color = RGBf(colors[2]...),
label = "FP", linewidth=lw, linestyle = ls[2] )
CairoMakie.lines!(ax, freq[fidx], energyEqAnis[1,fidx,rec], color = RGBf(colors[3]...),
label = "EQANIS", linewidth=lw, linestyle = ls[3] )
CairoMakie.lines!(ax, freq[fidx], energyEqAnisRed[1,fidx,rec], color = RGBf(colors[4]...),
label = "red. EQANIS", linewidth=lw, linestyle = ls[4] )
CairoMakie.lines!(ax, freq[fidx], energyEq[1,fidx,rec], color = RGBf(colors[5]...),
label = "EQ", linewidth=lw, linestyle = ls[5] )
CairoMakie.scatter!(ax, freq[freqidx], energyMeas[1,freqidx,rec], color = RGBf(colors[1]...),
markersize = 14, marker = :xcross )
tightlimits!(ax)
axislegend(ax)
# Error Plots
crange = (0.05,0.36)
maxMixingError = max(9, MX[end])
for l=1:length(smModels)
err = relErrorMixingOrder(smModels[l], SMeas, 1:maxMixingError )[:,:,rec]
@info "Extrema of Error for $(strDataset[l]): $(extrema(err))"
@info "Mean of Error for $(strDataset[l]): $(mean(err))"
ax = CairoMakie.Axis(fig[4, l], xlabel = rich("κ", subscript("y"), font=:italic),
ylabel = (l==1) ? rich("κ", subscript("x"), font=:italic) : "",
title = "Error: $(strDataset[l])", xlabelpadding = 2, ylabelpadding = 2,
yreversed = true, xticks = 1:2:maxMixingError, yticks = 1:2:maxMixingError,
yticklabelsvisible=(l==1), yticksvisible=(l==1))
@info maximum(err)
CairoMakie.heatmap!(ax, transpose(err), colorrange = crange )
tightlimits!(ax)
end
fig[4,5] = Colorbar(fig[4, 4], limits = crange, label = "Error")
rowgap!(fig.layout, 10)
colgap!(fig.layout, 10)
save("img/$(filenamePrefix)$(rec).png", fig, px_per_unit = 2, pt_per_unit = 0.25)
save("img/$(filenamePrefix)$(rec).pdf", fig, px_per_unit = 2, pt_per_unit = 0.25)
end