Debian Codegraph @

envisage/examples/demo/plugins/tasks/attractors/model/rossler.py

raw
1 # (C) Copyright 2007-2025 Enthought, Inc., Austin, TX
2 # All rights reserved.
3 #
4 # This software is provided without warranty under the terms of the BSD
5 # license included in LICENSE.txt and may be redistributed only under
6 # the conditions described in the aforementioned license. The license
7 # is also available online at http://www.enthought.com/licenses/BSD.txt
8 #
9 # Thanks for using Enthought open source!
10
11 # System library imports.
12 import numpy as np
13
14 # Local imports
15 from attractors.model.i_model_3d import IModel3d, IModel3dIPlottable2dMixin
16 from attractors.model.i_plottable_2d import IPlottable2d
17 from scipy import arange, array
18 from scipy.integrate import odeint
19
20 # Enthought libary imports.
21 from traits.api import (
22 Adapter,
23 Array,
24 cached_property,
25 Float,
26 HasTraits,
27 Instance,
28 Property,
29 provides,
30 register_factory,
31 Str,
32 )
33 from traitsui.api import Item, View
34
35
36 @provides(IModel3d)
37 class Rossler(HasTraits):
38 """The model object for the Rossler attractor."""
39
40 #### 'IModel3d' interface #################################################
41
42 name = Str("Rossler Attractor")
43 points = Property(Array, observe="a, b, c, initial_point, times")
44
45 #### 'Rossler' interface ##################################################
46
47 # Equation parameters.
48 a = Float(0.2, auto_set=False, enter_set=True)
49 b = Float(0.2, auto_set=False, enter_set=True)
50 c = Float(5.7, auto_set=False, enter_set=True)
51
52 # Integration parameters.
53 initial_point = Array(dtype=np.float64, value=[0.0, 1.0, 0.0])
54 time_start = Float(0.0)
55 time_stop = Float(100.0)
56 time_step = Float(0.01)
57 times = Property(Array, observe="time_start, time_stop, time_step")
58
59 # Configuration view.
60 view = View(
61 Item("a"),
62 Item("b"),
63 Item("c"),
64 Item("initial_point"),
65 Item("time_start"),
66 Item("time_stop"),
67 Item("time_step"),
68 resizable=True,
69 )
70
71 ###########################################################################
72 # 'Rossler' interface.
73 ###########################################################################
74
75 def compute_step(self, point, time):
76 x, y, z = point
77 return array([-y - z, x + self.a * y, self.b + z * (x - self.c)])
78
79 ###########################################################################
80 # Protected interface.
81 ###########################################################################
82
83 @cached_property
84 def _get_points(self):
85 return odeint(self.compute_step, self.initial_point, self.times)
86
87 @cached_property
88 def _get_times(self):
89 return arange(self.time_start, self.time_stop, self.time_step)
90
91
92 @provides(IPlottable2d)
93 class RosslerIPlottable2dAdapter(Adapter, IModel3dIPlottable2dMixin):
94 adaptee = Instance(Rossler)
95
96 plot_type = Str("line")
97
98
99 register_factory(RosslerIPlottable2dAdapter, Rossler, IPlottable2d)