gstlal  0.8.1
 All Classes Namespaces Files Functions Variables Pages
lal_fakeadvligosrc.py
1 # Copyright (C) 2010 Leo Singer
2 # Copyright (C) 2010 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 """
18 Generate simulated Advanced LIGO h(t) based on ZERO DET, high power in
19 http://lhocds.ligo-wa.caltech.edu:8000/advligo/AdvLIGO_noise_curves
20 """
21 __author__ = "Drew Keppel <drew.keppel@ligo.org>, Leo Singer <leo.singer@ligo.org>"
22 
23 #
24 # The filter design is by Drew Keppel, who added the mkfakeadvLIGOsrc()
25 # function to pipeparts.py in Apr 2010 (git hash 232ee6bf97). The code was
26 # subsequently ported to a stand-alone Python element by Leo Singer (git
27 # hash c79657d297).
28 #
29 
30 from gstlal import pipeutil
31 from gstlal.pipeutil import gobject, gst
32 from math import cos, pi, sqrt
33 
34 
35 class lal_fakeadvligosrc(gst.Bin):
36 
37  __gstdetails__ = (
38  'Fake Advanced LIGO Source',
39  'Source',
40  __doc__,
41  __author__
42  )
43 
44  __gproperties__ = {
45  'blocksize': (
46  gobject.TYPE_UINT64,
47  'blocksize',
48  'Number of samples in each outgoing buffer',
49  0, gobject.G_MAXULONG, 16384 * 8 * 1, # min, max, default
50  gobject.PARAM_WRITABLE
51  ),
52  'instrument': (
53  gobject.TYPE_STRING,
54  'instrument',
55  'Instrument name (e.g., "H1")',
56  None,
57  gobject.PARAM_WRITABLE
58  ),
59  'channel-name': (
60  gobject.TYPE_STRING,
61  'channel-name',
62  'Channel name (e.g., "LSC-STRAIN")',
63  None,
64  gobject.PARAM_WRITABLE
65  )
66  }
67 
68  __gsttemplates__ = (
69  gst.PadTemplate("src",
70  gst.PAD_SRC, gst.PAD_ALWAYS,
71  gst.caps_from_string("""
72  audio/x-raw-float,
73  channels = (int) 1,
74  endianness = (int) BYTE_ORDER,
75  width = (int) 64,
76  rate = (int) 16384
77  """)
78  ),
79  )
80 
81  def do_set_property(self, prop, val):
82  if prop.name == 'blocksize':
83  # Set property on all sources
84  for elem in self.iterate_sources():
85  elem.set_property('blocksize', val)
86  elif prop.name in ('instrument', 'channel-name'):
87  self.__tags[prop.name] = val
88  tagstring = ','.join('%s="%s"' % kv for kv in self.__tags.iteritems())
89  self.__taginject.set_property('tags', tagstring)
90 
91 
92  def do_send_event(self, event):
93  """
94  Send SEEK and EOS events to the source elements, all others
95  to the by default bins send all events to the sink
96  elements.
97  """
98  # FIXME: seeks should go to sink elements as well
99  success = True
100  if event.type in (gst.EVENT_SEEK, gst.EVENT_EOS):
101  for elem in self.iterate_sources():
102  success &= elem.send_event(event)
103  else:
104  for elem in self.iterate_sinks():
105  success &= elem.send_event(event)
106  return success
107 
108 
109  def __init__(self):
110  super(lal_fakeadvligosrc, self).__init__()
111 
112  self.__tags = {'units':'strain'}
113 
114  chains = (
115  pipeutil.mkelems_in_bin(self,
116  ('audiotestsrc', {'wave':'gaussian-noise', 'volume': 4e-28, 'samplesperbuffer': 16384}),
117  ('audioiirfilter', {'a': (1.,), 'b': (-1., 2*cos(2*pi*9.103/16384)*0.99995, -1.*0.99995**2)}),
118  ),
119  pipeutil.mkelems_in_bin(self,
120  ('audiotestsrc', {'wave':'gaussian-noise', 'volume': 1.1e-23, 'samplesperbuffer': 16384}),
121  ('audiofirfilter', {'kernel': (1., -1.)}),
122  ),
123  pipeutil.mkelems_in_bin(self,
124  ('audiotestsrc', {'wave':'gaussian-noise', 'volume': 1e-27, 'samplesperbuffer': 16384}),
125  ('audioiirfilter', {'a': (1.,), 'b': (-1.0, 2 * 0.999, -.999**2)}),
126  ),
127  pipeutil.mkelems_in_bin(self,
128  ('audiotestsrc', {'wave':'gaussian-noise', 'volume': 4e-26, 'samplesperbuffer': 16384}),
129  ('audioiirfilter', {'a': (1.,), 'b': (-1., 2*cos(2*pi*50./16384)*.87, -.87**2)}),
130  ),
131  pipeutil.mkelems_in_bin(self,
132  ('audiotestsrc', {'wave':'gaussian-noise', 'volume': 6.5e-24, 'samplesperbuffer': 16384}),
133  ('audioiirfilter', {'a': (1.,), 'b': (-1., -2*.45, -.45**2)}),
134  ),
135  )
136 
137  outputchain = pipeutil.mkelems_in_bin(self,
138  ('lal_adder', {'sync': True}),
139  ('audioamplify', {'clipping-method': 3, 'amplification': sqrt(16384.)*3/4}),
140  ('taginject',)
141  )
142 
143  for chain in chains:
144  chain[-1].link(outputchain[0])
145 
146  self.__taginject = outputchain[-1]
147  self.add_pad(gst.ghost_pad_new_from_template('src', outputchain[-1].get_static_pad('src'), self.__gsttemplates__[0]))
148 
149 
150 
151 # Register element class
152 gobject.type_register(lal_fakeadvligosrc)
153 
154 __gstelementfactory__ = (
155  lal_fakeadvligosrc.__name__,
156  gst.RANK_NONE,
157  lal_fakeadvligosrc
158 )