From 533a3ac24ac4b919fb6c6fb38a54f6f1393b9f6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Poisot?= Date: Tue, 26 Nov 2024 13:54:57 -0500 Subject: [PATCH] doc(sdt): vsup draft --- docs/src/tutorials/bivariate-vsup.jl | 68 +++++++++++++++++----------- 1 file changed, 42 insertions(+), 26 deletions(-) diff --git a/docs/src/tutorials/bivariate-vsup.jl b/docs/src/tutorials/bivariate-vsup.jl index 7db741ae4..aeb83fe6e 100644 --- a/docs/src/tutorials/bivariate-vsup.jl +++ b/docs/src/tutorials/bivariate-vsup.jl @@ -9,39 +9,53 @@ CairoMakie.activate!(; type = "png", px_per_unit = 2) #hide # get some data POL = SpeciesDistributionToolkit.gadm("BEL"); -spatialextent = SpeciesDistributionToolkit.boundingbox(POL; padding=1.0) +spatialextent = SpeciesDistributionToolkit.boundingbox(POL; padding = 0.1) # some layers provider = RasterData(CHELSA2, BioClim) -val = SDMLayer( +layers = [mask!(SDMLayer( provider; - layer = 1, - spatialextent... - ) -val = convert(SDMLayer{Float16}, val) -val = trim(mask!(val, POL)) + layer = i, + spatialextent..., + ), POL) for i in [1, 3]] + +layers = [convert(SDMLayer{Float16}, l) for l in layers] + +# unpack + +val, unc = layers + +# temperature layer # fig-hm -heatmap(val; axis=(aspect=DataAspect(), )) +heatmap(val; axis = (aspect = DataAspect(),)) +lines!(POL[1].geometry, color=:black) current_figure() #hide -# fake uncertainty with randomness -# TODO: add randomness - -unc = (val - rand(values(val))).^2.0 +# now see the seasonality layer # fig-hm-unc -heatmap(unc; axis=(aspect=DataAspect(), )) +heatmap(unc; axis = (aspect = DataAspect(),)) +lines!(POL[1].geometry, color=:black) current_figure() #hide +# ## Value-suppressing uncertainty palette + # function for VSUP -function _vsup_grid(vbins, ubins, vpal, upal=colorant"#e3e3e3", shrinkage=0.5, exponent=1.0) +function _vsup_grid( + vbins, + ubins, + vpal; + upal = colorant"#f3f3f344", + s = 0.5, + k = 1.0, +) pal = fill(upal, (vbins, ubins)) for i in 1:ubins - shrkfac = ((i - 1) / (ubins - 1))^exponent - subst = 0.5 - shrkfac * shrinkage / 2 + shrkfac = ((i - 1) / (ubins - 1))^k + subst = 0.5 - shrkfac * s / 2 pal[:, i] .= CairoMakie.cgrad(vpal)[LinRange(0.5 - subst, 0.5 + subst, vbins)] # Apply the mix to the uncertain color for j in 1:vbins @@ -62,21 +76,23 @@ end # VSUP test - what are the parameters -ubins = 50 -vbins = 50 -vbin = quantize(val, vbins) -ubin = quantize(unc, ubins) +ubins = 31 +vbins = 31 +vbin = discretize(quantize(val, vbins), vbins) +ubin = discretize(quantize(unc, ubins), ubins) -pal = _vsup_grid(ubins, vbins, :isoluminant_cgo_70_c39_n256) +pal = _vsup_grid(vbins, ubins, :diverging_isoluminant_cjm_75_c23_n256) # fig-vsup-colorpalette -f = Figure(; size=(800,400)) +f = Figure(; size = (800, 400)) ax = Axis(f[1, 1]; aspect = DataAspect()) heatmap!(ax, vbin + (ubin - 1) * maximum(vbin); colormap = vcat(pal...)) hidespines!(ax) hidedecorations!(ax) +lines!(POL[1].geometry, color=:black) current_figure() #hide +# fig-vsup-legend p = PolarAxis( f[1, 2]; theta_0 = -pi / 2.5, @@ -86,14 +102,14 @@ p = PolarAxis( ) surface!( p, - 0 .. π/5, + 0 .. π / 5, 0 .. 1, zeros(size(pal)); color = reverse(pal), shading = NoShading, ) -thetalims!(p, 0, pi/5) +thetalims!(p, 0, pi / 5) colsize!(f.layout, 1, Relative(0.7)) -current_figure() +current_figure() #hide -# Bivariate palette test +# ## Bivariate palette