Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDanisch committed Mar 5, 2024
1 parent 937d990 commit 015c2af
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 53 deletions.
17 changes: 17 additions & 0 deletions examples/earth-sphere.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
data:
path: "./dev/NDViewer/examples/speedyweather.nc"
layers:
- figure:
size: [1000, 800]
- type: LScene
position: [1, 1]
attributes:
show_axis: false
plots:
- type: sphereplot
args: [[1, 2]]
- type: Axis
position: [1, 2]
plots:
- type: image
args: [[1, 2]]
46 changes: 9 additions & 37 deletions examples/generic.jl
Original file line number Diff line number Diff line change
@@ -1,37 +1,9 @@
using Bonito, WGLMakie, NDViewer


function create_app_from_yaml(file)
yaml_str = read(file, String)
viewer = NDViewer.load_from_yaml(yaml_str)
app = App() do
editor = CodeEditor("yaml"; initial_source=yaml_str, width=300, height=600, foldStyle="manual")
css = DOM.style("""
.ace_scrollbar-v,
.ace_scrollbar-h {
display: none !important;
}
""")
set_editor = js"""
const editor = ace.edit($(editor.element))
editor.setReadOnly(true);
"""
yaml_display = DOM.div(css, Card(editor; width="fit-content"), set_editor)
style = Styles("word-wrap" => "break-word")
app_dom = Grid(
yaml_display, viewer;
justify_content="center",
# align_items="center",
style=Styles("grid-auto-flow" => "column")
)
return Centered(app_dom; style=Styles("width" => "100%"))
end
return app, viewer
end

app1, viewer = create_app_from_yaml(joinpath(@__DIR__, "speedyweather.yaml")); app1
NDViewer.add_slice_view(viewer, 1, 1, 1, :black)
NDViewer.add_slice_view(viewer, 1, 1, 2, :blue)

app2, viewer = create_app_from_yaml(joinpath(@__DIR__, "speedyweather-tyler.yaml")); app2
app3, viewer = create_app_from_yaml(joinpath(@__DIR__, "tas-gn-64gb.yaml")); app3
using Bonito, WGLMakie, NDViewer, GeometryBasics
using NDViewer: yaml_viewer
yaml_path(name) = joinpath(@__DIR__, name)
WGLMakie.activate!()
app1 = yaml_viewer(yaml_path("speedyweather.yaml"))
app2 = yaml_viewer(yaml_path("speedy-volume.yaml"))
app3 = yaml_viewer(yaml_path("speedyweather-tyler.yaml"))
app4 = yaml_viewer(yaml_path("tas-gn-64gb.yaml"))
app5 = yaml_viewer(yaml_path("earth-sphere.yaml"))
15 changes: 15 additions & 0 deletions examples/speedy-volume.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
data:
path: "./dev/NDViewer/examples/speedyweather.nc"
layers:
- figure:
size: [1000, 800]
- type: Axis3
position: [1, 1]
plots:
- type: volume
args: [[1, 2, 3]]
- type: Axis
position: [1, 2]
plots:
- type: image
args: [[1, 2]]
2 changes: 1 addition & 1 deletion examples/speedyweather-tyler.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
data:
path: "c:\\Users\\sdani\\Programmieren\\MakieDev\\dev\\NDViewer\\examples\\speedyweather.nc"
path: ".\\dev\\NDViewer\\examples\\speedyweather.nc"
layers:
- figure:
size: [1000, 1000]
Expand Down
2 changes: 1 addition & 1 deletion examples/speedyweather.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
data:
path: "c:\\Users\\sdani\\Programmieren\\MakieDev\\dev\\NDViewer\\examples\\speedyweather.nc"
path: ".\\dev\\NDViewer\\examples\\speedyweather.nc"
layers:
- layout:
rowsize: [0.8, 0.2]
Expand Down
21 changes: 21 additions & 0 deletions examples/using Bonito.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Bonito
using DelimitedFiles
volcano = readdlm(Makie.assetpath("volcano.csv"), ',', Float64)
App() do
f = contourf(volcano, levels=10; axis=(; title="normal"))
f2 = contourf(volcano, levels=10; axis=(; title="resize_to=:parent"))
r = WGLMakie.WithConfig(f2; resize_to=:parent)
DOM.div(Grid(f, r; columns="50% 50%"); style=Styles("height" => "700px"))

end

using GeoMakie, GLMakie
fig = Figure()
ga = GeoAxis(
fig[1, 1]; # any cell of the figure's layout
dest="+proj=wintri", # the CRS in which you want to plot
)
lines!(ga, GeoMakie.coastlines()) # plot coastlines from Natural Earth as a reference
# You can plot your data the same way you would in Makie
scatter!(ga, -120:15:120, -60:7.5:60; color=-60:7.5:60, strokecolor=(:black, 0.2))
fig
4 changes: 2 additions & 2 deletions src/NDViewer.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module NDViewer

using Makie, DimensionalData, LinearAlgebra
using Makie, DimensionalData, LinearAlgebra, Bonito

include("array-interface.jl")
include("makie-converts.jl")
include("loading.jl")
include("yaml-viewer.jl")
include("widgets.jl")
include("bonito-widgets.jl")
include("makie-widgets.jl")
Expand Down
26 changes: 14 additions & 12 deletions src/layers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,15 @@ function layer_to_plot!(ax::Makie.AbstractAxis, sliced_arrays, dict, fcolor, cma
args = replace_slices(sliced_arrays, dict["args"])
attr = get(dict, "attributes", Dict())
attributes = replace_slices(sliced_arrays, attr)
if plotfunc in (heatmap, image, surface)
if (plotfunc in (heatmap, image, surface, volume)) || dict["type"] == "sphereplot"
crange = get(attributes, :colorrange, nothing)
if crange === nothing
crange = map(Makie.extrema_nan, last(args))
idx = length(cmaps)
colormaps = colormap_widget(fcolor[idx+1, 1], crange)
push!(cmaps, colormaps)
cmap_slice = last(dict["args"])
colormaps = get!(cmaps, cmap_slice) do
idx = length(cmaps)
crange = map(Makie.extrema_nan, last(args))
colormap_widget(fcolor[idx+1, 1], crange)
end
for (k, v) in pairs(colormaps)
attributes[k] = v
end
Expand All @@ -183,6 +185,8 @@ function resolve_symbol(s::String)
end
if hasproperty(Makie, name)
return getfield(Makie, name)
elseif hasproperty(NDViewer, name)
return getfield(NDViewer, name)
else
return s
end
Expand Down Expand Up @@ -251,7 +255,7 @@ function create_plot(data, layers;)
fcolor = f[3, 1]
layouts = remove_dicts!(x-> haskey(x, "layout"), layers)
sliced_arrays, widgets = create_slices(layers, data)
cmaps = []
cmaps = Dict()
axes = map(layers) do axlayer
layer_to_axis!(fplots, sliced_arrays, axlayer, fcolor, cmaps)
end
Expand All @@ -268,13 +272,14 @@ function create_plot(data, layers;)
end
end
end
for (i, colormaps) in enumerate(cmaps)
cmaps = Base.structdiff(colormaps, (; nan_color=0, alpha=0))
Colorbar(fcbar[i, 1]; vertical=false, tellheight=true, tellwidth=true, cmaps...)
for (i, colormaps) in enumerate(values(cmaps))
cmap_attr = Base.structdiff(colormaps, (; nan_color=0, alpha=0))
Colorbar(fcbar[i, 1]; vertical=false, tellheight=true, tellwidth=true, cmap_attr...)
end
return f, sliced_arrays, widgets, axes
end


struct DataViewerApp
layers
data
Expand All @@ -298,14 +303,11 @@ function wgl_create_plot(data, layers)
return DataViewerApp(layers, data, f, slices, widgets, axes)
end


function Base.display(viewer::DataViewerApp)
app = App(viewer; title="DataViewer")
display(app)
end



function add_index_slice(axis::Makie.AbstractAxis, plot, index_obs, dim, color)
dim_data = dim == 2 ? plot.y : plot.x
dim_slice = map(getindex, dim_data, index_obs)
Expand Down
12 changes: 12 additions & 0 deletions src/makie-converts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,15 @@ function Makie.convert_arguments(::Type{<:LineSegments}, u_matrix::AbstractDimAr
end
return PlotSpec(:LineSegments, convert_arguments(LineSegments, vec(points))..., cycle=[], color=radiance)
end

@recipe(SpherePlot, image) do scene
attr = Attributes()
Makie.MakieCore.colormap_attributes!(attr, :viridis)
attr
end

function Makie.plot!(p::SpherePlot)
GB = Makie.GeometryBasics
sm = GB.uv_normal_mesh(GB.Tesselation(Sphere(Point3f(0), 1.0f0), 100))
mesh!(p, sm, color=map(x -> x', p[3]); Makie.MakieCore.colormap_attributes(p)...)
end
31 changes: 31 additions & 0 deletions src/loading.jl → src/yaml-viewer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,34 @@ function load_from_yaml(yaml_str)
layers = data["layers"]
wgl_create_plot(data_cube, layers)
end


function yaml_viewer(file)
yaml_str = read(file, String)
create_app_from_yaml(yaml_str)
end

function create_app_from_yaml(yaml_str)
return App() do
viewer = NDViewer.load_from_yaml(yaml_str)
editor = CodeEditor("yaml"; initial_source=yaml_str, width=300, height=600, foldStyle="manual")
css = DOM.style("""
.ace_scrollbar-v,
.ace_scrollbar-h {
display: none !important;
}
""")
set_editor = js"""
const editor = ace.edit($(editor.element))
editor.setReadOnly(true);
"""
yaml_display = DOM.div(css, Card(editor; width="fit-content"), set_editor)
app_dom = Grid(
yaml_display, viewer;
justify_content="center",
# align_items="center",
style=Styles("grid-auto-flow" => "column")
)
return Centered(app_dom; style=Styles("width" => "100%"))
end
end

0 comments on commit 015c2af

Please sign in to comment.