Skip to content

Commit

Permalink
Update interactive_poincaresos method to v3 (#250)
Browse files Browse the repository at this point in the history
* Update `interactive_poincaresos` to V3.0

* Update Project.toml

---------

Co-authored-by: George Datseris <[email protected]>
  • Loading branch information
GabrielMajeri and Datseris authored Dec 9, 2024
1 parent 0972a4b commit 6822617
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DynamicalSystems"
uuid = "61744808-ddfa-5f27-97ff-6e42cc95d634"
repo = "https://github.com/JuliaDynamics/DynamicalSystems.jl.git"
version = "3.4.0"
version = "3.4.1"

[deps]
Attractors = "f3fd9213-ca85-4dba-9dfd-7fc91308fec7"
Expand Down
35 changes: 15 additions & 20 deletions ext/src/poincareclick.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,45 @@ function DynamicalSystems.interactive_poincaresos(ds, plane, idxs, complete;
# Makie kwargs:
color = randomcolor,
scatterkwargs = (),
labels = ("u₁" , "u₂"),
# DiffEq kwargs:
diffeq = NamedTuple()
labels = ("u₁", "u₂")
)

error("this function has not yet been updated to DynamicalSystems.jl v3.0. PR welcomed!")
# TODO: What is needed here is to make this use `PoincareMap`.
# and that's it!

# Basic sanity checks on the method arguments
@assert typeof(plane) <: Tuple
@assert length(idxs) == 2
@assert eltype(idxs) == Int
@assert plane[1] idxs
u0 = DynamicalSystems.get_state(ds)

# This is the low-level call of poincaresos:
DynamicalSystems.DynamicalSystemsBase.check_hyperplane_match(plane, DynamicalSystems.dimension(ds))
integ = DynamicalSystems.integrator(ds, u0; diffeq)
planecrossing = ChaosTools.PlaneCrossing(plane, direction > 0)
i = DynamicalSystems.SVector{2, Int}(idxs)

figure = Figure(resolution = (1000, 800), backgroundcolor = DEFAULT_BG)
figure = Figure(size = (1000, 800), backgroundcolor = :white)

T_slider, m_slider = _add_psos_controls!(figure, tfinal)
ax = figure[0, :] = Axis(figure)

# Initial Section
f = (t) -> planecrossing(integ(t))
data = ChaosTools._poincaresos(integ, f, planecrossing, T_slider[], i, rootkw)
# Construct a new `PoincareMap` structure with the given parameters
pmap = DynamicalSystems.DynamicalSystemsBase.PoincareMap(ds, plane;
direction, u0, rootkw, Tmax = tfinal[2])

# Compute the initial section
psos, = trajectory(pmap, T_slider[]; t0 = 0)
data = psos[:, i]
length(data) == 0 && error(ChaosTools.PSOS_ERROR)

positions_node = Observable(data)
colors = (c = color(u0); [c for i in 1:length(data)])
colors_node = Observable(colors)
scatter!(
ax, positions_node, color = colors_node,
markersize = lift(o -> o*px, m_slider), marker = MARKER, scatterkwargs...
markersize = lift(o -> o*px, m_slider), marker = :circle, scatterkwargs...
)

ax.xlabel, ax.ylabel = labels
laststate = Observable(u0)

# Interactive clicking on the psos:
MakieLayout.deactivate_interaction!(ax, :rectanglezoom)
Makie.deactivate_interaction!(ax, :rectanglezoom)
spoint = select_point(ax.scene)
on(spoint) do pos
x, y = pos; z = plane[2] # third variable comes from plane
Expand All @@ -62,13 +57,13 @@ function DynamicalSystems.interactive_poincaresos(ds, plane, idxs, complete;
return
end

DynamicalSystems.reinit!(integ, newstate)
data = ChaosTools._poincaresos(integ, f, planecrossing, T_slider[], i, rootkw)
psos, = trajectory(pmap, T_slider[], newstate; t0 = 0)
data = psos[:, i]
positions = positions_node[]; colors = colors_node[]
append!(positions, data)
c = color(newstate)
append!(colors, fill(c, length(data)))
# update all the observables with Array as value:
# Update all the observables with Array as value:
positions_node[], colors_node[], laststate[] = positions, colors, newstate
end
display(figure)
Expand Down

0 comments on commit 6822617

Please sign in to comment.