Greenland ice loss example: animated & interactive
julia
using Tyler
using Tyler.TileProviders
using Tyler.Extents
using Dates
using HTTP
using Arrow
using DataFrames
using GLMakie
using GLMakie.Colors
GLMakie.activate!()
INFO
Ice loss from the Greenland Ice Sheet: 1972-2022.
- Contact person: Alex Gardner & Chad Greene
Load ice loss data [courtesy of Chad Greene @ JPL]
julia
url = "https://github.com/JuliaGeo/JuliaGeoData/blob/365a09596bfca59e0977c20c2c2f566c0b29dbaa/assets/data/iceloss_subset.arrow?raw=true";
resp = HTTP.get(url);
df = DataFrame(Arrow.Table(resp.body));
first(df, 5)
select map provider
julia
provider = TileProviders.Esri(:WorldImagery);
Greenland extent
julia
extent = Extent(X = (-54., -48.), Y = (68.8, 72.5));
Extent(X = (-54.0, -48.0), Y = (68.8, 72.5))
extract data
julia
cnt = [length(foo) for foo in df.X];
X = reduce(vcat,df.X);
Y = reduce(vcat,df.Y);
Z = [repeat([i],c) for (i, c) = enumerate(cnt)];
Z = reduce(vcat,Z);
make a colormap
julia
nc = length(Makie.to_colormap(:thermal));
n = nrow(df);
alpha = zeros(nc);
alpha[1:maximum([1,round(Int64,1*nc/n)])] = alpha[1:maximum([1,round(Int64,1*nc/n)])] .* (1.05^-1.5);
alpha[maximum([1,round(Int64,1*nc/n)])] = 1;
cmap = Colors.alphacolor.(Makie.to_colormap(:thermal), alpha);
cmap = Observable(cmap);
show map
julia
fig = Figure(; size = (1200,600))
ax = Axis(fig[1,1])
m = Tyler.Map(extent; provider, figure=fig, axis=ax);
wait(m)
create initial scatter plot
julia
scatter!(ax, X, Y; color = Z, colormap = cmap, colorrange = [0, n], markersize = 10);
add colorbar
julia
a,b = extrema(df.Date);
a = year(a);
b = year(b);
Colorbar(fig[1,2]; colormap = cmap, colorrange = [a,b],
height=Relative(0.5), width = 15)
# hide ticks, grid and lables
hidedecorations!(ax);
# hide frames
hidespines!(ax);
# wait for tiles to fully load
wait(m)
loop to create animation
julia
for k = 1:15
# reset apha
alpha[:] = zeros(nc);
cmap[] = Colors.alphacolor.(cmap[], alpha)
for i in 2:1:n
# modify alpha
alpha[1:maximum([1,round(Int64,i*nc/n)])] = alpha[1:maximum([1,round(Int64,i*nc/n)])] .* (1.05^-1.5);
alpha[maximum([1,round(Int64,i*nc/n)])] = 1;
cmap[] = Colors.alphacolor.(cmap[], alpha);
sleep(0.001);
end
end