Skip to content

Commit

Permalink
doc(sdt): vsup draft
Browse files Browse the repository at this point in the history
  • Loading branch information
tpoisot committed Nov 26, 2024
1 parent 55bd39d commit 533a3ac
Showing 1 changed file with 42 additions and 26 deletions.
68 changes: 42 additions & 26 deletions docs/src/tutorials/bivariate-vsup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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

0 comments on commit 533a3ac

Please sign in to comment.