Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ version = "0.1.0"

[deps]
ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
DimensionalData = "0703355e-b756-11e9-17c0-8b28908087d0"
DiskArrayEngine = "2d4b2e14-ccd6-4284-b8b0-2378ace7c126"
DiskArrayTools = "fcd2136c-9f69-4db6-97e5-f31981721d63"
Expand All @@ -14,8 +13,6 @@ Extents = "411431e0-e8b7-467b-b5e0-f676ba4f2910"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
MakieCore = "20f20a25-4f0e-4fdf-b5d1-57303727442b"
Observables = "510215fc-4207-5dde-b226-833fc4488ee2"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
Proj = "c94c279d-25a6-4763-9509-64d165bea63e"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand All @@ -25,9 +22,11 @@ Zarr = "0a941bbe-ad1d-11e8-39d9-ab76183a1d99"

[weakdeps]
ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"

[extensions]
PyramidSchemeArchGDALExt = "ArchGDAL"
PyramidSchemeMakieExt = "Makie"

[compat]
Aqua = "0.8"
Expand All @@ -42,8 +41,6 @@ Extents = "0.1.3"
FillArrays = "1.11"
GeoInterface = "1.3.4"
Makie = "0.21.2"
MakieCore = "0.8.2"
Observables = "0.5.5"
OffsetArrays = "1.14"
Proj = "1.7.1"
Statistics = "1.10"
Expand Down
63 changes: 63 additions & 0 deletions ext/PyramidSchemeMakieExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
module PyramidSchemeMakieExt
using Makie: Axis, Colorbar, DataAspect, Figure, FigureAxisPlot, Observable, Relative
using Makie: on, heatmap!, image!
import Makie: plot, plot!
using PyramidScheme: Pyramid, switchkeys, levels, selectlevel, xkey, ykey
using DimensionalData: DimensionalData as DD
using DimensionalData.Dimensions: XDim, YDim
using Extents: Extent, extent, intersects
"""
plot(pyramids)
Plot a Pyramid.
This will plot the coarsest resolution level at the beginning and will plot higher resolutions after zooming into the plot.
This is expected to be used with interactive Makie backends.
"""
function plot(pyramid::Pyramid;colorbar=true, kwargs...)
#This should be converted into a proper recipe for Makie but this would depend on a pyramid type.
fig = Figure()
lon, lat = DD.dims(DD.parent(pyramid))
ax = Axis(fig[1,1], limits=(extrema(lon), extrema(lat)), aspect=DataAspect())
hmap = plot!(ax, pyramid;kwargs...)
if colorbar
Colorbar(fig[1,2], hmap, height = Relative(3.5 / 4))
end
ax.autolimitaspect = 1
FigureAxisPlot(fig, ax, hmap)
end

function plot!(ax, pyramid::Pyramid;interp=false, kwargs...)#; rastercrs=crs(parent(pyramid)),plotcrs=EPSG(3857), kwargs...)
tip = levels(pyramid)[end-2][:,:]
#@show typeof(tip)
data = Observable{DD.AbstractDimMatrix}(tip)
xval = only(values(extent(pyramid, XDim)))
yval = only(values(extent(pyramid, YDim)))
rasdataext = Extent(X=xval, Y=yval)
rasext = extent(pyramid)
xk = xkey(rasext)
yk = ykey(rasext)
on(ax.scene.viewport) do viewport
limext = extent(ax.finallimits[])

datalimit = switchkeys(limext, rasext)

data.val = selectlevel(pyramid, datalimit, target_imsize=viewport.widths)
notify(data)
end
on(ax.finallimits) do limits
limext = extent(limits)
# Compute limit in raster projection
#trans = Proj.Transformation(plotcrs, rastercrs, always_xy=true)
#datalimit = trans_bounds(trans, limext)
datalimit = switchkeys(limext, rasext)
if intersects(rasdataext, limext)
rasdata = selectlevel(pyramid, datalimit, target_imsize=ax.scene.viewport[].widths)
# Project selected data to plotcrs
#data.val = Rasters.resample(rasdata, crs=plotcrs, method=:bilinear )
data.val = rasdata
end
notify(data)
end
#@show typeof(data)
hmap = heatmap!(ax, data; interpolate=interp, kwargs...)
end
end
69 changes: 5 additions & 64 deletions src/PyramidScheme.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,17 @@ using DiskArrayEngine: DiskArrayEngine, GMDWop, InputArray, LocalRunner, MovingW
using DiskArrayEngine: create_outwindows, engine
using DiskArrays: DiskArrays
#using YAXArrays: savecube
using Zarr
using YAXArrayBase
const YAB = YAXArrayBase
using YAXArrayBase: YAXArrayBase as YAB
using YAXArrays: Cube, YAXArray, to_dataset, savedataset, setchunks, open_dataset
using Zarr: zcreate, writeattrs
using Zarr: Zarr, zcreate, zopen, writeattrs
using DimensionalData: DimensionalData as DD
using DimensionalData.Dimensions: XDim, YDim
using Extents
using Extents: Extent, extent
using FillArrays: Zeros
using Proj
using Makie: Axis, Colorbar, DataAspect, Figure, FigureAxisPlot, Observable, Relative
using Makie: on, heatmap!, image!
import MakieCore: plot, plot!
using OffsetArrays

using Statistics
using Statistics: mean

export Pyramid, buildpyramids

Expand Down Expand Up @@ -411,24 +406,7 @@ function selectlevel(pyramid, ext;target_imsize=(1024, 512))
end


"""
plot(pyramids)
Plot a Pyramid.
This will plot the coarsest resolution level at the beginning and will plot higher resolutions after zooming into the plot.
This is expected to be used with interactive Makie backends.
"""
function plot(pyramid::Pyramid;colorbar=true, kwargs...)
#This should be converted into a proper recipe for Makie but this would depend on a pyramid type.
fig = Figure()
lon, lat = DD.dims(parent(pyramid))
ax = Axis(fig[1,1], limits=(extrema(lon), extrema(lat)), aspect=DataAspect())
hmap = plot!(ax, pyramid;kwargs...)
if colorbar
Colorbar(fig[1,2], hmap, height = Relative(3.5 / 4))
end
ax.autolimitaspect = 1
FigureAxisPlot(fig, ax, hmap)
end


xkey(keyext) = DD.dim2key(DD.dims(keyext, XDim))
ykey(keyext) = DD.dim2key(DD.dims(keyext, YDim))
Expand All @@ -449,42 +427,6 @@ function switchkeys(dataext, keyext)
Extent(nt)
end

function plot!(ax, pyramid::Pyramid;interp=false, kwargs...)#; rastercrs=crs(parent(pyramid)),plotcrs=EPSG(3857), kwargs...)
tip = levels(pyramid)[end-2][:,:]
#@show typeof(tip)
data = Observable{DD.AbstractDimMatrix}(tip)
xval = only(values(Extents.extent(pyramid, XDim)))
yval = only(values(Extents.extent(pyramid, YDim)))
rasdataext = Extent(X=xval, Y=yval)
rasext = extent(pyramid)
xk = xkey(rasext)
yk = ykey(rasext)
on(ax.scene.viewport) do viewport
limext = Extents.extent(ax.finallimits[])

datalimit = switchkeys(limext, rasext)

data.val = selectlevel(pyramid, datalimit, target_imsize=viewport.widths)
notify(data)
end
on(ax.finallimits) do limits
limext = Extents.extent(limits)
# Compute limit in raster projection
#trans = Proj.Transformation(plotcrs, rastercrs, always_xy=true)
#datalimit = trans_bounds(trans, limext)
datalimit = switchkeys(limext, rasext)
if Extents.intersects(rasdataext, limext)
rasdata = selectlevel(pyramid, datalimit, target_imsize=ax.scene.viewport[].widths)
# Project selected data to plotcrs
#data.val = Rasters.resample(rasdata, crs=plotcrs, method=:bilinear )
data.val = rasdata
end
notify(data)
end
#@show typeof(data)
hmap = heatmap!(ax, data; interpolate=interp, kwargs...)
end

"""
trans_bounds(trans::Proj.Transformation, bbox::Extent, densify_pts::Integer)
Compute the projection of `bbox` with the transformation `trans`.
Expand All @@ -504,7 +446,6 @@ function write(path, pyramid::Pyramid; kwargs...)

for (i,l) in enumerate(reverse(pyramid.levels))
outpath = joinpath(path, string(i-1))
@show outpath
savecube(l,outpath)
end
end
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ end

@testitem "Pyramid building RGB eltype" begin
using PyramidScheme: PyramidScheme as PS
using DimensionalData
using Colors
data = rand(RGB, 2000,2000)
dd = DimArray(data, (X(1:2000), Y(1:2000)))
Expand Down
Loading