gstlal  0.8.1
 All Classes Namespaces Files Functions Variables Pages
lal_fakeligosrc.py
1 # Copyright (C) 2010 Leo Singer
2 # Copyright (C) 2009 Drew Keppel
3 #
4 # This program is free software; you can redistribute it and/or modify it
5 # under the terms of the GNU General Public License as published by the
6 # Free Software Foundation; either version 2 of the License, or (at your
7 # option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
12 # Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with this program; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 """Generate simulated initial LIGO h(t)"""
18 __author__ = "Drew Keppel <drew.keppel@ligo.org>"
19 
20 #
21 # The filter design in this code is by Drew Keppel originally commited to
22 # the lloid_gui program in Jul 2009 (git hash d7e01fa5be6) and subsequently
23 # migrated into pipeparts.py. It was converted into a stand-alone Python
24 # element by Leo Singer in 2010 (git hash c79657d297)
25 #
26 
27 
28 from gstlal import pipeutil
29 from gstlal.pipeutil import gobject, gst
30 
31 
32 class lal_fakeligosrc(gst.Bin):
33 
34  __gstdetails__ = (
35  'Fake LIGO Source',
36  'Source',
37  __doc__,
38  __author__
39  )
40 
41  __gproperties__ = {
42  'blocksize': (
43  gobject.TYPE_UINT64,
44  'blocksize',
45  'Number of samples in each outgoing buffer',
46  0, gobject.G_MAXULONG, 16384 * 8 * 1, # min, max, default
47  gobject.PARAM_WRITABLE
48  ),
49  'instrument': (
50  gobject.TYPE_STRING,
51  'instrument',
52  'Instrument name (e.g., "H1")',
53  None,
54  gobject.PARAM_WRITABLE
55  ),
56  'channel-name': (
57  gobject.TYPE_STRING,
58  'channel-name',
59  'Channel name (e.g., "LSC-STRAIN")',
60  None,
61  gobject.PARAM_WRITABLE
62  )
63  }
64 
65  __gsttemplates__ = (
66  gst.PadTemplate("src",
67  gst.PAD_SRC, gst.PAD_ALWAYS,
68  gst.caps_from_string("""
69  audio/x-raw-float,
70  channels = (int) 1,
71  endianness = (int) BYTE_ORDER,
72  width = (int) 64,
73  rate = (int) 16384
74  """)
75  ),
76  )
77 
78  def do_set_property(self, prop, val):
79  if prop.name == 'blocksize':
80  # Set property on all sources
81  for elem in self.iterate_sources():
82  elem.set_property('blocksize', val)
83  elif prop.name in ('instrument', 'channel-name'):
84  self.__tags[prop.name] = val
85  tagstring = ','.join('%s="%s"' % kv for kv in self.__tags.iteritems())
86  self.__taginject.set_property('tags', tagstring)
87 
88 
89  def do_send_event(self, event):
90  """
91  Send SEEK and EOS events to the source elements, all others
92  to the by default bins send all events to the sink
93  elements.
94  """
95  # FIXME: seeks should go to sink elements as well
96  success = True
97  if event.type in (gst.EVENT_SEEK, gst.EVENT_EOS):
98  for elem in self.iterate_sources():
99  success &= elem.send_event(event)
100  else:
101  for elem in self.iterate_sinks():
102  success &= elem.send_event(event)
103  return success
104 
105 
106  def __init__(self):
107  super(lal_fakeligosrc, self).__init__()
108 
109  self.__tags = {'units':'strain'}
110 
111  # Build first filter chain
112  chains = (
113  pipeutil.mkelems_in_bin(self,
114  ('audiotestsrc', {'wave':'gaussian-noise', 'volume': 5.03407936516e-17, 'samplesperbuffer': 16384}),
115  *((('audioiirfilter', {'a': (1.87140685e-05, 3.74281370e-05, 1.87140685e-05), 'b': (1., 1.98861643, -0.98869215)}),) * 14)
116  ),
117  pipeutil.mkelems_in_bin(self,
118  ('audiotestsrc', {'wave': 'gaussian-noise', 'volume': 1.39238913312e-20, 'samplesperbuffer': 16384}),
119  ('audioiirfilter', {'a': (9.17933667e-07, 1.83586733e-06, 9.17933667e-07), 'b': (1., 1.99728828, -0.99729195)})
120  ),
121  pipeutil.mkelems_in_bin(self,
122  ('audiotestsrc', {'wave': 'gaussian-noise', 'volume': 2.16333076528e-23, 'samplesperbuffer': 16384})
123  ),
124  pipeutil.mkelems_in_bin(self,
125  ('audiotestsrc', {'wave': 'gaussian-noise', 'volume': 1.61077910675e-20, 'samplesperbuffer': 16384}),
126  ('audioiirfilter', {'a': (0.5591789, 0.5591789), 'b': (1., -0.1183578)}),
127  ('audioiirfilter', {'a': (0.03780506, -0.03780506), 'b': (1.0, -0.9243905)})
128  )
129  )
130 
131  outputchain = pipeutil.mkelems_in_bin(self,
132  ('lal_adder', {'sync': True}),
133  ('audioamplify', {'clipping-method': 3, 'amplification': 16384.**.5}),
134  ('taginject',)
135  )
136 
137  for chain in chains:
138  chain[-1].link(outputchain[0])
139 
140  self.__taginject = outputchain[-1]
141  self.add_pad(gst.ghost_pad_new_from_template('src', outputchain[-1].get_static_pad('src'), self.__gsttemplates__[0]))
142 
143 
144 
145 # Register element class
146 gobject.type_register(lal_fakeligosrc)
147 
148 __gstelementfactory__ = (
149  lal_fakeligosrc.__name__,
150  gst.RANK_NONE,
151  lal_fakeligosrc
152 )