SpeedyWeather / SpeedyWeather.jl

Play atmospheric modelling like it's LEGO.
https://speedyweather.github.io/SpeedyWeather.jl/dev
MIT License
400 stars 24 forks source link

Add Makie extension #511

Closed milankl closed 2 months ago

milankl commented 2 months ago

@simondanisch you're probably happy to see this! @navidcy getting there #482

julia> vor
18688-element, 128-ring OctahedralGaussianGrid{Float32}:
  3.0710835f-5
  3.1388656f-5
  ⋮
 -8.172375f-6
 -7.466016f-6

julia> heatmap(vor, title="Surface vorticity [1/s]")

yields

image

navidcy commented 2 months ago

Yes, yes, yes!

navidcy commented 2 months ago

I can help out!

milankl commented 2 months ago

I can help out!

Yeah, I don't think I've set up the extension correctly. I thought

If I see this right, they are doing basically the same (bit more complicated though because they need GraphMakie)

https://github.com/bsc-quantic/Tenet.jl/blob/master/ext/TenetGraphMakieExt.jl

milankl commented 2 months ago

@navidcy Okay, I got it to work

julia> using SpeedyWeather

julia> heatmap
ERROR: UndefVarError: `heatmap` not defined

julia> using CairoMakie
Precompiling SpeedyWeatherMakieExt
  1 dependency successfully precompiled in 12 seconds. 360 already precompiled.

julia> methods(heatmap)
# 4 methods for generic function "heatmap" from MakieCore:
 [1] heatmap()
     @ ~/.julia/packages/MakieCore/UAwps/src/recipes.jl:172
 [2] heatmap(grid::SpeedyWeather.RingGrids.AbstractFullGrid; title)
     @ SpeedyWeatherMakieExt ~/.julia/packages/SpeedyWeather/kXPNB/ext/SpeedyWeatherMakieExt.jl:14
 [3] heatmap(grid::SpeedyWeather.RingGrids.AbstractGrid; title)
     @ SpeedyWeatherMakieExt ~/.julia/packages/SpeedyWeather/kXPNB/ext/SpeedyWeatherMakieExt.jl:6
 [4] heatmap(args...; kw...)
     @ ~/.julia/packages/MakieCore/UAwps/src/recipes.jl:175

julia> heatmap(rand(FullGaussianGrid,4))

pops up a CairoMakie window

image

Lessons learned

@SimonDanisch I've struggled with this ☝🏼 as I haven't found any info. The pkg docs only describe extensions from the perspective if Makie would want to define some of its plotting functions for external types, not the probably more common use case (?) that a package owns a type and wants to define some plotting function (owned by Makie) for it. If you want me to write this up as a quick guide in the makie docs let me know where and I'm happy to add it.

SimonDanisch commented 2 months ago

@milankl would be amazing to have this in the docs. I think @jkrumbiegel thought about having a section in the docs for this, maybe he has some thoughts. Otherwise I'd say make a new page for package extensions in how-to: https://docs.makie.org/stable/how-to/ https://github.com/MakieOrg/Makie.jl/tree/master/docs/how-to