Skip to content

Commit 004c293

Browse files
committed
add GLMakie heatmap and heatmap! multiple dispatch for surfaces
1 parent ed2b3c5 commit 004c293

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

ext/GLMakie_Visualisation.jl

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module GLMakie_Visualisation
33

44
using Statistics
55
using GeophysicalModelGenerator: lonlatdepth_grid, GeoData, CartData, km, AbstractGeneralGrid
6-
import GeophysicalModelGenerator: visualise
6+
import GeophysicalModelGenerator: visualise, ustrip
77

88
# We do not check `isdefined(Base, :get_extension)` as recommended since
99
# Julia v1.9.0 does not load package extensions when their dependency is
@@ -14,7 +14,9 @@ else
1414
using ..GLMakie
1515
end
1616

17-
export visualise
17+
import GLMakie: heatmap!, heatmap
18+
19+
export visualise, heatmap, heatmap!
1820

1921
println("Loading GLMakie extensions for GMG")
2022

@@ -271,5 +273,47 @@ function visualise(Data::AbstractGeneralGrid; Topography=nothing, Topo_range=not
271273
return nothing
272274
end
273275

276+
"""
277+
heatmap(x::GeoData, args...; field=:Topography, kwargs...)
278+
heatmap for a 2D GeoData object (surface)
279+
"""
280+
function heatmap(x::GeoData, args...; field=:Topography, kwargs...)
281+
@assert size(x.depth.val,3)==1
282+
283+
heatmap(x.lon.val[:,1], x.lat.val[1,:], ustrip.(x.fields[field][:,:,1]), args...; kwargs...)
284+
285+
end
286+
287+
"""
288+
heatmap(x::CartData, args...; field=:Topography, kwargs...)
289+
heatmap for a 2D CartData object (surface)
290+
"""
291+
function heatmap(x::CartData, args...; field=:Topography, kwargs...)
292+
@assert size(x.z.val,3)==1
293+
294+
heatmap(x.x.val[:,1], x.y.val[1,:], ustrip.(x.fields[field][:,:,1]), args...; kwargs...)
295+
296+
end
297+
298+
"""
299+
heatmap!(x::GeoData, args...; field=:Topography, kwargs...)
300+
in-place heatmap for a 2D GeoData object (surface),
301+
"""
302+
function heatmap!(x::GeoData, args...; field=:Topography, kwargs...)
303+
@assert size(x.z.val,3)==1
304+
305+
heatmap!(x.lon.val[:,1], x.lat.val[1,:], ustrip.(x.fields[field][:,:,1]), args...; kwargs...)
306+
307+
end
308+
309+
"""
310+
heatmap!(x::CartData, args...; field=:Topography, kwargs...)
311+
in-place heatmap for a 2D CartData object (surface)
312+
"""
313+
function heatmap!(x::CartData, args...; field=:Topography, kwargs...)
314+
@assert size(x.z.val,3)==1
315+
heatmap!(x.x.val[:,1], x.y.val[1,:], ustrip.(x.fields[field][:,:,1]), args...; kwargs...)
316+
end
317+
274318

275319
end

0 commit comments

Comments
 (0)