| 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_plottable_2d import IPlottable2d |
| 16 |
from scipy import array, zeros |
| 17 |
|
| 18 |
# Enthought library imports. |
| 19 |
from traits.api import ( |
| 20 |
Array, |
| 21 |
cached_property, |
| 22 |
Float, |
| 23 |
HasTraits, |
| 24 |
Int, |
| 25 |
Property, |
| 26 |
provides, |
| 27 |
Str, |
| 28 |
) |
| 29 |
from traitsui.api import Item, View |
| 30 |
|
| 31 |
|
| 32 |
@provides(IPlottable2d) |
| 33 |
class Henon(HasTraits): |
| 34 |
"""The model object for the Henon map.""" |
| 35 |
|
| 36 |
#### 'Henon' interface #################################################### |
| 37 |
|
| 38 |
# Equation parameters. |
| 39 |
a = Float(1.4, auto_set=False, enter_set=True) |
| 40 |
b = Float(0.3, auto_set=False, enter_set=True) |
| 41 |
|
| 42 |
# Iteration parameters. |
| 43 |
initial_point = Array(dtype=np.float64, value=[0.1, 0.1]) |
| 44 |
steps = Int(10000) |
| 45 |
|
| 46 |
# Iteration results. |
| 47 |
points = Property(Array, observe="a, b, initial_point, steps") |
| 48 |
|
| 49 |
# Configuration view. |
| 50 |
view = View( |
| 51 |
Item("a"), |
| 52 |
Item("b"), |
| 53 |
Item("initial_point"), |
| 54 |
Item("steps"), |
| 55 |
resizable=True, |
| 56 |
) |
| 57 |
|
| 58 |
#### 'IPlottable2D' interface ############################################# |
| 59 |
|
| 60 |
name = Str("Henon Map") |
| 61 |
plot_type = Str("scatter") |
| 62 |
x_data = Property(Array, observe="points") |
| 63 |
y_data = Property(Array, observe="points") |
| 64 |
x_label = Str("x") |
| 65 |
y_label = Str("y") |
| 66 |
|
| 67 |
########################################################################### |
| 68 |
# Protected interface. |
| 69 |
########################################################################### |
| 70 |
|
| 71 |
@cached_property |
| 72 |
def _get_points(self): |
| 73 |
point = self.initial_point |
| 74 |
points = zeros((self.steps, 2)) |
| 75 |
for i in range(self.steps): |
| 76 |
x, y = points[i] = point |
| 77 |
point = array([y + 1 - self.a * x**2, self.b * x]) |
| 78 |
return points |
| 79 |
|
| 80 |
@cached_property |
| 81 |
def _get_x_data(self): |
| 82 |
return self.points[:, 0] |
| 83 |
|
| 84 |
@cached_property |
| 85 |
def _get_y_data(self): |
| 86 |
return self.points[:, 1] |