@@ -37,6 +37,14 @@ function colorrange_from_data(; data, saturation, sensitivity, allpositive)
37
37
end
38
38
end
39
39
40
+ # Makie.heatmap can fail on large grids due to an OpenGL error. A workaround is
41
+ # to wrap the data in a Makie.Resampler if any of the array dimensions is
42
+ # "large" https://github.com/MakieOrg/Makie.jl/issues/4950. The empirical cutoff
43
+ # 2000 should (hopefully) be conservative for most systems.
44
+ function maybe_resample (data)
45
+ all (< (2000 ), size (data)) ? data : Makie. Resampler (data)
46
+ end
47
+
40
48
"""
41
49
plot_intensities!(panel, res; opts...)
42
50
@@ -61,11 +69,8 @@ function Sunny.plot_intensities!(panel, res::Sunny.BandIntensities{Float64}; col
61
69
62
70
if res. qpts isa Sunny. QPath
63
71
mindisp, maxdisp = extrema (res. disp)
64
- ebounds = if isnothing (ylims)
65
- (min (0 , mindisp), 1.1 * maxdisp)
66
- else
67
- ylims .* unit_energy
68
- end
72
+ ylims = @something ylims (min (0 , mindisp), 1.1 * maxdisp) ./ unit_energy
73
+ ebounds = ylims .* unit_energy
69
74
energies = range (ebounds[1 ], ebounds[2 ], 512 )
70
75
fwhm = @something fwhm 0.02 * (ebounds[2 ]- ebounds[1 ])
71
76
σ = fwhm/ 2 √ (2 log (2 ))
@@ -77,8 +82,8 @@ function Sunny.plot_intensities!(panel, res::Sunny.BandIntensities{Float64}; col
77
82
colorrange = @something colorrange colorrange_suggest
78
83
79
84
xticklabelrotation = maximum (length .(res. qpts. xticks[2 ])) > 3 ? π/ 6 : 0.0
80
- ax = Makie. Axis (panel; xlabel= " Momentum (r.l.u.)" , ylabel, res. qpts. xticks, xticklabelrotation, axisopts... )
81
- Makie. heatmap! (ax, axes ( data, 2 ), collect (energies / unit_energy), data' ; colorrange, colormap, lowclip= :white )
85
+ ax = Makie. Axis (panel; xlabel= " Momentum (r.l.u.)" , ylabel, res. qpts. xticks, xticklabelrotation, limits = ( nothing , ylims), axisopts... )
86
+ Makie. heatmap! (ax, ( 1 , size ( data, 2 )), ylims, maybe_resample ( collect ( data' )) ; colorrange, colormap, lowclip= :white )
82
87
for i in axes (res. disp, 1 )
83
88
Makie. lines! (ax, res. disp[i,:]/ unit_energy; color= :lightskyblue3 )
84
89
end
@@ -138,18 +143,17 @@ function Sunny.plot_intensities!(panel, res::Sunny.Intensities{Float64}; colorma
138
143
if qpts isa Sunny. QPath
139
144
unit_energy, ylabel = get_unit_energy (units, into)
140
145
xticklabelrotation = maximum (length .(qpts. xticks[2 ])) > 3 ? π/ 6 : 0.0
141
- ax = Makie. Axis (panel[1 , 1 ]; xlabel= " Momentum (r.l.u.)" , ylabel, qpts. xticks, xticklabelrotation, axisopts... )
142
- isnothing (ylims) || Makie. ylims! (ax, ylims)
143
- hm = Makie. heatmap! (ax, axes (data, 2 ), collect (energies/ unit_energy), data' ; colormap, colorrange)
146
+ ax = Makie. Axis (panel[1 , 1 ]; xlabel= " Momentum (r.l.u.)" , ylabel, qpts. xticks, xticklabelrotation, limits= (nothing , ylims), axisopts... )
147
+ hm = Makie. heatmap! (ax, (1 , size (data, 2 )), extrema (energies)./ unit_energy, maybe_resample (data' ); colormap, colorrange)
144
148
Makie. Colorbar (panel[1 , 2 ], hm)
145
149
return ax
146
150
elseif qpts isa Sunny. QGrid{2 }
147
151
if isone (length (energies))
148
152
aspect = grid_aspect_ratio (crystal, qpts)
149
153
xlabel, ylabel = suggest_labels_for_grid (qpts)
150
- (xs, ys ) = map (range, qpts. coefs_lo, qpts. coefs_hi, size (qpts . qs) )
154
+ (xbounds, ybounds ) = zip ( qpts. coefs_lo, qpts. coefs_hi)
151
155
ax = Makie. Axis (panel[1 , 1 ]; xlabel, ylabel, aspect, axisopts... )
152
- hm = Makie. heatmap! (ax, xs, ys, dropdims (data; dims= 1 ); colormap, colorrange)
156
+ hm = Makie. heatmap! (ax, xbounds, ybounds, maybe_resample ( dropdims (data; dims= 1 ) ); colormap, colorrange)
153
157
Makie. Colorbar (panel[1 , 2 ], hm)
154
158
return ax
155
159
else
@@ -179,9 +183,9 @@ function Sunny.plot_intensities!(panel, res::Sunny.StaticIntensities{Float64}; c
179
183
colorrange = @something colorrange colorrange_suggest
180
184
aspect = grid_aspect_ratio (crystal, qpts)
181
185
xlabel, ylabel = suggest_labels_for_grid (qpts)
182
- (xs, ys ) = map (range, qpts. coefs_lo, qpts. coefs_hi, size (qpts . qs) )
186
+ (xbounds, ybounds ) = zip ( qpts. coefs_lo, qpts. coefs_hi)
183
187
ax = Makie. Axis (panel[1 , 1 ]; xlabel, ylabel, aspect, axisopts... )
184
- hm = Makie. heatmap! (ax, xs, ys, data; colormap, colorrange)
188
+ hm = Makie. heatmap! (ax, xbounds, ybounds, maybe_resample ( data) ; colormap, colorrange)
185
189
Makie. Colorbar (panel[1 , 2 ], hm)
186
190
return ax
187
191
else
@@ -200,9 +204,8 @@ function Sunny.plot_intensities!(panel, res::Sunny.PowderIntensities{Float64}; c
200
204
colormap = @something colormap (allpositive ? :gnuplot2 : :bwr )
201
205
colorrange = @something colorrange colorrange_suggest
202
206
203
- ax = Makie. Axis (panel[1 , 1 ]; xlabel, ylabel, axisopts... )
204
- isnothing (ylims) || Makie. ylims! (ylims)
205
- hm = Makie. heatmap! (ax, res. radii, collect (res. energies/ unit_energy), res. data' ; colormap, colorrange)
207
+ ax = Makie. Axis (panel[1 , 1 ]; xlabel, ylabel, limits= (nothing , ylims), axisopts... )
208
+ hm = Makie. heatmap! (ax, extrema (res. radii), extrema (res. energies)./ unit_energy, maybe_resample (res. data' ); colormap, colorrange)
206
209
Makie. Colorbar (panel[1 , 2 ], hm)
207
210
return ax
208
211
end
0 commit comments