Guest User

Untitled

a guest
Feb 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. from enthought.traits.api \
  4. import HasTraits, Array, Range, Float, Enum, on_trait_change, Property
  5. from enthought.traits.ui.api import View, Item
  6. from enthought.chaco.chaco_plot_editor import ChacoPlotItem
  7. from numpy import arange
  8. from numpy import sin,pi
  9.  
  10. class Data(HasTraits):
  11. tt = Array
  12. yy = Property(Array, depends_on=['amplitude', 'carrier_frequency',
  13. 'mod_frequency', 'mod_depth'])
  14. amplitude = Range(low=0,high=50.0,value=20.0)
  15. carrier_frequency = Range(low=.01,high=100.0,value=20)
  16. mod_frequency = Range(low=.01, high=10.0,value=1)
  17. mod_depth = Range(low=0.01, high=2, val=0.5)
  18.  
  19. plot_type = Enum("line", "scatter")
  20.  
  21. traits_view = View(ChacoPlotItem("tt", "yy",
  22. type_trait='plot_type',
  23. resizable=True,
  24. x_label="time",
  25. y_label="amplitude",
  26. x_bounds=(0,10),
  27. x_auto=False,
  28. y_bounds=(-50,50),
  29. y_auto=False,
  30. color="blue",
  31. bgcolor="white",
  32. border_visible=True,
  33. border_width=1,
  34. title='AM Demo',
  35. padding_bg_color="lightgray"),
  36. Item(name='amplitude'),
  37. Item(name='carrier_frequency'),
  38. Item(name='mod_frequency'),
  39. Item(name='mod_depth'),
  40. Item(name='plot_type'),
  41. resizable = True,
  42. buttons = ["OK"],
  43. title='AM Demo',
  44. width=900, height=800)
  45.  
  46.  
  47. def _tt_default(self):
  48. """ Default handler for volume Trait Array. """
  49. return arange(0, 100, 0.01)
  50.  
  51. def _get_yy(self):
  52. """Recalculate when one a trait the property depends on changes."""
  53. w_c = 2*pi*(self.carrier_frequency)
  54. w_m = 2*pi*(self.mod_frequency)
  55.  
  56. return (self.amplitude * sin(self.tt*w_c) +
  57. (self.amplitude * self.mod_depth)/2 *
  58. (sin(self.tt*(w_c + w_m)) +
  59. sin(self.tt*(w_c + w_m))))
  60.  
  61.  
  62. if __name__ == '__main__':
  63. viewer = Data()
  64. viewer.configure_traits()
Add Comment
Please, Sign In to add comment