mattfoster (owner)

Revisions

gist: 22338 Download_button fork
public
Public Clone URL: git://gist.github.com/22338.git
Embed All Files: show embed
am_chaco_example.py #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
 
from enthought.traits.api \
    import HasTraits, Array, Range, Float, Enum, on_trait_change, Property
from enthought.traits.ui.api import View, Item
from enthought.chaco.chaco_plot_editor import ChacoPlotItem
from numpy import arange
from numpy import sin,pi
 
class Data(HasTraits):
    tt = Array
    yy = Property(Array, depends_on=['amplitude', 'carrier_frequency',
      'mod_frequency', 'mod_depth'])
    amplitude = Range(low=0,high=50.0,value=20.0)
    carrier_frequency = Range(low=.01,high=100.0,value=20)
    mod_frequency = Range(low=.01, high=10.0,value=1)
    mod_depth = Range(low=0.01, high=2, val=0.5)
 
    plot_type = Enum("line", "scatter")
 
    traits_view = View(ChacoPlotItem("tt", "yy",
                               type_trait='plot_type',
                               resizable=True,
                               x_label="time",
                               y_label="amplitude",
                               x_bounds=(0,10),
                               x_auto=False,
                               y_bounds=(-50,50),
                               y_auto=False,
                               color="blue",
                               bgcolor="white",
                               border_visible=True,
                               border_width=1,
                               title='AM Demo',
                               padding_bg_color="lightgray"),
                       Item(name='amplitude'),
                       Item(name='carrier_frequency'),
                       Item(name='mod_frequency'),
                       Item(name='mod_depth'),
                       Item(name='plot_type'),
                       resizable = True,
                       buttons = ["OK"],
                       title='AM Demo',
                       width=900, height=800)
 
 
    def _tt_default(self):
        """ Default handler for volume Trait Array. """
        return arange(0, 100, 0.01)
 
    def _get_yy(self):
        """Recalculate when one a trait the property depends on changes."""
        w_c = 2*pi*(self.carrier_frequency)
        w_m = 2*pi*(self.mod_frequency)
        
        return (self.amplitude * sin(self.tt*w_c) +
                (self.amplitude * self.mod_depth)/2 *
                                (sin(self.tt*(w_c + w_m)) +
                                sin(self.tt*(w_c + w_m))))
                             
      
if __name__ == '__main__':
    viewer = Data()
    viewer.configure_traits()