Skip to content

Commit

Permalink
Add Makie extension for plotting. (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
evetion authored Dec 21, 2024
1 parent b5e796b commit adad2fd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ TableOperations = "ab02a1b2-a7df-11e8-156e-fb1833f50b87"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53"

[weakdeps]
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"

[extensions]
SpaceLiDARMakieExt = "Makie"

[compat]
AWSS3 = "0.10, 0.11"
CategoricalArrays = "^0.9, 0.10"
Expand All @@ -41,12 +47,14 @@ GeoInterface = "1"
HDF5 = "^0.15, 0.16, 0.17"
HTTP = "0.9, 1"
JSON3 = "1"
Makie = "0.21"
Proj = "1"
Statistics = "1"
TableOperations = "1.2"
Tables = "^1.4"
TimeZones = "1"
julia = "1.9"
julia = "1.10"


[extras]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Expand Down
30 changes: 30 additions & 0 deletions ext/SpaceLiDARMakieExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module SpaceLiDARMakieExt

using Makie
using SpaceLiDAR
using Tables

Makie.preferred_axis_type(plot::Makie.Plot(SpaceLiDAR.Granule)) = Makie.LScene

Makie.plottype(::SpaceLiDAR.Granule) = Makie.Scatter
Makie.used_attributes(::Type{<:Makie.Scatter}, ::SpaceLiDAR.Granule) = (:zscale, :tracks)

function Makie.convert_arguments(p::Type{<:Makie.Scatter}, geom::SpaceLiDAR.Granule; zscale = 1, tracks = nothing, kwargs...)
table = Tables.columns(points(geom))
Makie.convert_arguments(p, table.longitude .* 110_000 .* cosd.(table.latitude), table.latitude * 110_000, table.height * zscale, kwargs...)
end

function Makie.plot!(plot::Makie.Plot(SpaceLiDAR.Granule))

g = plot[1][]

get!(plot.attributes, :fxaa, true)
get!(plot.attributes, :ssao, true)

valid_attributes = Makie.shared_attributes(plot, Makie.Scatter)
valid_attributes[:zscale] = get(plot.attributes, :zscale, Makie.Observable(1))[]
Makie.scatter!(plot, valid_attributes, g)
plot
end

end

0 comments on commit adad2fd

Please # to comment.