Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ClimaExplorer, intearctive visualizer #51

Open
9 of 19 tasks
Sbozzolo opened this issue Aug 3, 2024 · 3 comments
Open
9 of 19 tasks

Add ClimaExplorer, intearctive visualizer #51

Sbozzolo opened this issue Aug 3, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@Sbozzolo
Copy link
Member

Sbozzolo commented Aug 3, 2024

Description to be written

Tasks

@AlexisRenchon
Copy link
Member

AlexisRenchon commented Aug 5, 2024

I made a little minimal working example, not sure if it is helpful, but here it is:

using Bonito
using WGLMakie 

function MWE()
    fig = Figure() # defined only once
    ax = Axis(fig[1,1]) # defined only once
    slider = Bonito.Slider(0:0.1:1)
    
    data = Observable(Vec2f.(1.0, slider.value[]))
    scatter!(ax, data) # plot an observable

    on(slider.value) do val
        data[] = Vec2f.(1.0, val) # update the value of the observable
    end

    app = App() do session::Session
        return DOM.div(
                   DOM.div(slider, slider.value),
                   fig
                  )
    end
    return app
end

MWE()

@Sbozzolo Sbozzolo changed the title Add ClimaExplorer, intearctive visualizer Add ClimaExplorer, intearctive visualizer Aug 5, 2024
@Sbozzolo
Copy link
Member Author

Sbozzolo commented Aug 5, 2024

I made a little minimal working example, not sure if it is helpful, but here it is:

using Bonito
using WGLMakie 

function MWE()
    fig = Figure() # defined only once
    ax = Axis(fig[1,1]) # defined only once
    slider = Bonito.Slider(0:0.1:1)
    
    data = Observable(Vec2f.(1.0, slider.value[]))
    scatter!(ax, data) # plot an observable

    on(slider.value) do val
        data[] = Vec2f.(1.0, val) # update the value of the observable
    end

    app = App() do session::Session
        return DOM.div(
                   DOM.div(slider, slider.value),
                   fig
                  )
    end
    return app
end

MWE()

We have to find a way to balance this with how ClimaAnalysis is used elsewhere. I think I add to create new Axis to make sure it would work out of the box. But I am sure that there are ways to fix this.

@AlexisRenchon
Copy link
Member

AlexisRenchon commented Aug 5, 2024

I can work on it after I am done with ClimaDiagnostics (or outside of work hours) - or we can do a hackathon together!

I think the ClimaAnalysis code just need some refactor, same functionality, and it won't be too many big changes, just isolate things a bit more.

Anything can be an Observable, and anything can take Observable arguments via the @lift macro, to become in turn a new Observable function of another one e.g.,

x = Observable(1.0)
coordinates = @lift(Vec2f.(1.0, $x)) # any function would work here

Eventually, a Makie plot function (scatter, heatmap, ...) needs to take one or more observables in its arguments, e.g. scatter(coordinates), figures and axis can be created before and not updated.

So in ClimaAnalysis, we need to be able to retrieve arguments of plotting from a function

There are other ways, but useful to know are:

julia> x = Observable(1.0)
Observable(1.0)
julia> x[] = 2
2
julia> x_value = x[]
2.0
julia> typeof(x)
Observable{Float64}
julia> typeof(x_value)
Float64

I find useful:

julia> y = @lift(Vec2f.(2.0, $x)) # the @lift macro 
Observable(Float32[2.0, 2.0])

on(slider.value) do val  # on any widget update
    f(val)
end

map(menu2.value) do val # this works too
    f(val)
end

@Sbozzolo Sbozzolo added the enhancement New feature or request label Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants