Skip to content

Commit

Permalink
add Tyler, bugfixes, perf improvements and more complex TOML config
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDanisch committed Feb 20, 2024
1 parent b1ea1a6 commit 27c8681
Show file tree
Hide file tree
Showing 10 changed files with 383 additions and 118 deletions.
9 changes: 9 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@ version = "1.0.0-DEV"
[deps]
Bonito = "824d6782-a2ef-11e9-3a09-e5662e0c26f8"
DimensionalData = "0703355e-b756-11e9-17c0-8b28908087d0"
DiskArrays = "3c3547ce-8d99-4f5e-a174-61eb10b00ae3"
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
MapTiles = "fea52e5a-b371-463b-85f5-81770daa2737"
NetCDF = "30363a11-5582-574a-97bb-aa9a979735b9"
Observables = "510215fc-4207-5dde-b226-833fc4488ee2"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
Tyler = "e170d443-b9d6-418a-9ee8-061e966341ef"
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
YAXArrays = "c21b50f5-aa40-41ea-b809-c0f5e47bfa5c"
Zarr = "0a941bbe-ad1d-11e8-39d9-ab76183a1d99"

[compat]
Bonito = "3"
Expand Down
79 changes: 31 additions & 48 deletions examples/generic.jl
Original file line number Diff line number Diff line change
@@ -1,54 +1,37 @@
using Bonito, WGLMakie, NDViewer
using NetCDF, YAXArrays
using DimensionalData
using Random

data_cube = Cube(joinpath(@__DIR__, "speedyweather.nc"))
layers = [
Dict(
"type" => heatmap,
# "attributes" => Dict("colorrange" => colorrange),
"args" => [[1, 2]],
),
Dict(
"type" => lines,
"args" => [[1]],
"attributes" => Dict("color" => "black")
)
]


dd = data_cube = DimensionalData.modify(data_cube) do arr
return convert(Array{Float32}, arr)
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

NDViewer.wgl_create_plot(dd, layers)


layers = [
Dict(
"type" => linesegments,
"args" => [[1, 2, 5 => 5], [1, 2, 5 => 3]],
"attributes" => Dict("color" => "black")
)
]

linesegments(data_cube[:, :, 5, 10, 5], data_cube[:, :, 5, 10, 3])
NDViewer.wgl_create_plot(data_cube, layers)

using Zarr, DiskArrays
path = "gs://cmip6/CMIP6/ScenarioMIP/DKRZ/MPI-ESM1-2-HR/ssp585/r1i1p1f1/3hr/tas/gn/v20190710"
g = open_dataset(zopen(path; consolidated=true))

data_cube = DimensionalData.modify(g.tas) do arr
return DiskArrays.CachedDiskArray(arr)
end
data = (data=data_cube,
names=map(x -> name(x.dim), collect(axes(data_cube))));

layers = [Dict("type" => heatmap,
"data" => [1, 2])]

# vec(view(data_cube, :, :, 1)) # fails on Makie#master because of this!
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)

NDViewer.wgl_create_plot(data, layers)
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
25 changes: 25 additions & 0 deletions examples/speedyweather-tyler.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
data:
path: "c:\\Users\\sdani\\Programmieren\\MakieDev\\dev\\NDViewer\\examples\\speedyweather.nc"
layers:
- figure:
size: [1000, 1000]
- type: Axis
position: [1, 1]
attributes:
aspect: DataAspect
plots:
- type: image
attributes:
colormap: viridis
args: [[1, 2]]
- type: Tyler
position: [2, 1]
attributes:
provider: OpenTopoMap
plots:
- type: linesegments
args: [[1, 2, {5: 5}], [1, 2, {5: 3}]]
attributes:
colormap: autumn1
alpha: 0.5
linewidth: 1
31 changes: 31 additions & 0 deletions examples/speedyweather.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
data:
path: "c:\\Users\\sdani\\Programmieren\\MakieDev\\dev\\NDViewer\\examples\\speedyweather.nc"
layers:
- layout:
rowsize: [0.8, 0.2]
- figure:
size: [1000, 800]
- layout:
rowsize: [0.8, 0.2]
- type: Axis
position: [1, 1]
attributes:
aspect: DataAspect
plots:
- type: image
attributes:
colormap: viridis
args: [[1, 2]]
- type: Axis
position: [2, 1]
plots:
- type: lines
args: [[1]]
attributes:
color: black
linewidth: 2
- type: lines
args: [[2]]
attributes:
color: blue
linewidth: 2
10 changes: 10 additions & 0 deletions examples/tas-gn-64gb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
data:
path: "gs://cmip6/CMIP6/ScenarioMIP/DKRZ/MPI-ESM1-2-HR/ssp585/r1i1p1f1/3hr/tas/gn/v20190710"
layers:
- figure:
size: [1000, 800]
- type: Axis
position: [1, 1]
plots:
- type: image
args: [[1, 2]]
1 change: 1 addition & 0 deletions src/NDViewer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using Makie, DimensionalData, LinearAlgebra

include("array-interface.jl")
include("makie-converts.jl")
include("loading.jl")
include("widgets.jl")
include("bonito-widgets.jl")
include("makie-widgets.jl")
Expand Down
12 changes: 3 additions & 9 deletions src/bonito-widgets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ function PlayButton(slider, range, session)
button = Bonito.Button(""; style=Styles("min-width" => "1rem", "height" => "2rem", "margin" => "0px"))
not_yet_open = true
playing = Threads.Atomic{Bool}(false)
time_per_frame = Threads.Atomic{Float64}(1 / 24)
last_elapsed = Float64[]
time_per_frame = Threads.Atomic{Float64}(1 / 30)
task = @async let i = first(range)
while true
yield()
Expand All @@ -19,15 +18,10 @@ function PlayButton(slider, range, session)
if playing[]
i = mod1(i + 1, last(range))
slider[] = i
# leave time for actuall rendering etc, before sleeping
yield()
end
elapsed = time() - t
if length(last_elapsed) == 100
circshift!(last_elapsed, -1)
last_elapsed[end] = elapsed
else
push!(last_elapsed, elapsed)
end
time_per_frame[] = maximum(last_elapsed)
sleep(max(0.001, time_per_frame[] - elapsed))
end
println("done: ", not_yet_open, ", ", isopen(session))
Expand Down
Loading

0 comments on commit 27c8681

Please sign in to comment.