Skip to content

Commit

Permalink
Add ClimaExplorer
Browse files Browse the repository at this point in the history
This commit adds an interactive viewer for ClimaAnalysis
  • Loading branch information
Sbozzolo committed Jul 26, 2024
1 parent c8314a7 commit ce1ce84
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ GeoMakie = "0.6.5, 0.7"
JuliaFormatter = "1"
NCDatasets = "0.13.1, 0.14"
OrderedCollections = "1.3"
Reexport = "1"
SafeTestsets = "0.1"
Statistics = "1"
Reexport = "1"
Test = "1"
julia = "1.9"

Expand Down
14 changes: 14 additions & 0 deletions climaexplorer/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name = "ClimaExplorer"
authors = ["Gabriele Bozzola <[email protected]>"]
version = "0.0.1"

[deps]
Bonito = "824d6782-a2ef-11e9-3a09-e5662e0c26f8"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
ClimaAnalysis = "29b5916a-a76c-4e73-9657-3c8fd22e65e6"
GeoMakie = "db073c08-6b98-4ee5-b6a4-5efafb3259c6"

[compat]
Bonito = "3"
ClimaAnalysis = "0.5.5"
GeoMakie = "0.6.5, 0.7"
12 changes: 12 additions & 0 deletions climaexplorer/assets/interactive.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.container {
display: flex;
}
.column {
padding: 10px;
}
.left {
flex: 0 1 20%; /* Flex-grow: 0, Flex-shrink: 1, Flex-basis: 20% */
}
.right {
flex: 1;
}
12 changes: 12 additions & 0 deletions climaexplorer/explorer.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
length(ARGS) == 1 || error("Usage: julia --project=climaexplorer explorer.jl <PATH>")

include(joinpath(@__DIR__, "libexplorer.jl"))

path = first(ARGS)

app = BonitoApp(path)

server = Server(app, "0.0.0.0", 8080)
println(server)
route!(server, "/" => app)
wait(server)
88 changes: 88 additions & 0 deletions climaexplorer/libexplorer.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import ClimaAnalysis
import Bonito: Observable, App, Slider, Dropdown, DOM, Server, route!, wait, Asset
import CairoMakie
import GeoMakie

function BonitoApp(path)
app = App() do
climastyle = Asset(joinpath(@__DIR__, "assets", "interactive.css"))
simdir = ClimaAnalysis.SimDir(path)
variables = ClimaAnalysis.available_vars(simdir) |> collect
vars_menu = Dropdown(variables)
short_name = vars_menu.value.val
# TODO: Add Dropdown menus for reduction and period

# reductions = ClimaAnalysis.available_reductions(simdir; short_name) |> collect
# reductions_menu = Dropdown(reductions)
# reduction = reductions_menu.value.val
# periods = ClimaAnalysis.available_periods(simdir; short_name, reduction) |> collect
# periods_menu = Dropdown(periods)

# Set up initial var
reduction = Observable(first(ClimaAnalysis.available_reductions(simdir; short_name)))
period = Observable(first(ClimaAnalysis.available_periods(simdir; short_name, reduction = reduction.val)))
var = get(simdir; short_name, reduction = reduction.val, period = period.val)
time_slider = Slider(ClimaAnalysis.times(var))
level_slider = Slider(ClimaAnalysis.altitudes(var))

var = map(vars_menu.value) do short_name
reduction[] = first(ClimaAnalysis.available_reductions(simdir; short_name))
period[] = first(ClimaAnalysis.available_periods(simdir; short_name, reduction = reduction.val))
var = get(simdir; short_name, reduction = reduction.val, period = period.val)
time_slider.values[] = ClimaAnalysis.times(var)
level_slider.values[] = ClimaAnalysis.altitudes(var)
setindex!(time_slider, first(ClimaAnalysis.times(var)))
setindex!(level_slider, first(ClimaAnalysis.altitudes(var)))
var
end

var = map(time_slider) do time
short_name = vars_menu.value.val
# Trigger level_slidel
setindex!(level_slider, level_slider.value.val)
ClimaAnalysis.slice(get(simdir; short_name, reduction = reduction.val, period = period.val); time, z = level_slider.value.val)
end

var = map(level_slider) do level
short_name = vars_menu.value.val
ClimaAnalysis.slice(get(simdir; short_name, reduction = reduction.val, period = period.val); time = time_slider.value.val, z = level)
end

fig = map(var) do sliced_var
fig = CairoMakie.Figure(size=(1200, 760), fontsize=30)
ClimaAnalysis.Visualize.contour2D_on_globe!(fig, sliced_var)
# ClimaAnalysis.Visualize.plot!(fig, sliced_var)
fig
end

return DOM.div(
DOM.h3("Output: ", path),
DOM.div(
DOM.div(
climastyle,
DOM.h4("Short name"),
vars_menu,
DOM.h4("Reduction: ", reduction),
DOM.h4("Period: ", period),
DOM.h4("Time: ", time_slider.value),
time_slider,
DOM.h4("Altitude: ", level_slider.value),
level_slider;
class = "column left",
),
DOM.div(fig, class = "column right"),
class = "container"
))
end
return app
end

# path = first(ARGS)
path = "../ClimaAtmos.jl/output/diagnostic_edmfx_aquaplanet/output_active/"

app = BonitoApp(path)

# server = Server(app, "0.0.0.0", 8080)
println(server)
route!(server, "/" => app)
# wait(server)

0 comments on commit ce1ce84

Please sign in to comment.