gstlal  0.8.1
 All Classes Namespaces Files Functions Variables Pages
lal_lho_coherent_null.py
1 # Copyright (C) 2012 Madeline Wade
2 #
3 # This program is free software; you can redistribute it and/or modify it
4 # under the terms of the GNU General Public License as published by the
5 # Free Software Foundation; either version 2 of the License, or (at your
6 # option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11 # Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License along
14 # with this program; if not, write to the Free Software Foundation, Inc.,
15 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 
17 #
18 # =============================================================================
19 #
20 # Preamble
21 #
22 # =============================================================================
23 #
24 
25 """Produce LHO coherent and null data streams"""
26 __author__ = "Madeline Wade <madeline.wade@ligo.org>"
27 
28 import scipy.fftpack
29 import numpy
30 
31 import gobject
32 gobject.threads_init()
33 import pygtk
34 pygtk.require('2.0')
35 import pygst
36 pygst.require('0.10')
37 import gst
38 
39 from gstlal import pipeparts
40 
41 #
42 # =============================================================================
43 #
44 # Functions
45 #
46 # =============================================================================
47 #
48 
49 class lal_lho_coherent_null(gst.Bin):
50 
51  __gstdetails__ = (
52  'LHO Coherent and Null Streams',
53  'Filter',
54  __doc__,
55  __author__
56  )
57 
58  __gproperties__ = {
59  'block-stride' : (
60  gobject.TYPE_UINT,
61  'block stride',
62  'block stride for fir bank',
63  1, gobject.G_MAXUINT, 1024,
64  gobject.PARAM_READWRITE
65  ),
66  'H1-impulse' : (
67  gobject.TYPE_PYOBJECT,
68  'H1 impulse',
69  'impulse response for H1',
70  gobject.PARAM_READWRITE
71  ),
72  'H2-impulse' : (
73  gobject.TYPE_PYOBJECT,
74  'H2 impulse',
75  'impulse response for H2',
76  gobject.PARAM_READWRITE
77  ),
78  'H1-latency' : (
79  gobject.TYPE_UINT,
80  'H1 latency',
81  'latency for H1',
82  0, gobject.G_MAXUINT, 0,
83  gobject.PARAM_READWRITE
84  ),
85  'H2-latency' : (
86  gobject.TYPE_UINT,
87  'H2 latency',
88  'latency for H2',
89  0, gobject.G_MAXUINT, 0,
90  gobject.PARAM_READWRITE
91  )
92  }
93 
94  def do_set_property(self, prop, val):
95  if prop.name == "block-stride":
96  self.H1firfilter.set_property("block-stride", val)
97  self.H2firfilter.set_property("block-stride", val)
98  elif prop.name == "H1-impulse":
99  self.H1firfilter.set_property("fir-matrix", [val])
100  elif prop.name == "H2-impulse":
101  self.H2firfilter.set_property("fir-matrix", [val])
102  elif prop.name == "H1-latency":
103  self.H1firfilter.set_property("latency", val)
104  elif prop.name == "H2-latency":
105  self.H2firfilter.set_property("latency", val)
106  else:
107  raise AssertionError
108 
109  def do_get_property(self, prop):
110  if prop.name == "block-stride":
111  return self.H1firfilter.get_property("block-stride")
112  elif prop.name == "H1-impulse":
113  return self.H1firfilter.get_property("fir-matrix")[0]
114  elif prop.name == "H2-impulse":
115  return self.H2firfilter.get_property("fir-matrix")[0]
116  elif prop.name == "H1-latency":
117  return self.H1firfilter.get_property("latency")
118  elif prop.name == "H2-latency":
119  return self.H2firfilter.get_property("latency")
120  else:
121  raise AssertionError
122 
123  def __init__(self):
124  super(lal_lho_coherent_null, self).__init__()
125 
126  # tee off sources
127  H1tee = gst.element_factory_make("tee")
128  self.add(H1tee)
129  H2tee = gst.element_factory_make("tee")
130  self.add(H2tee)
131 
132  self.add_pad(gst.GhostPad("H1sink", H1tee.get_pad("sink")))
133  self.add_pad(gst.GhostPad("H2sink", H2tee.get_pad("sink")))
134 
135  # apply fir filter to H1 data
136  self.H1firfilter = H1head = pipeparts.mkfirbank(self, H1tee)
137 
138  # apply fir filter to H2 data
139  self.H2firfilter = H2head = pipeparts.mkfirbank(self, H2tee)
140 
141  #
142  # create coherent stream
143  #
144 
145  COHhead = gst.element_factory_make("lal_adder")
146  COHhead.set_property("sync", True)
147  self.add(COHhead)
148  pipeparts.mkqueue(self, H1head).link(COHhead)
149  pipeparts.mkqueue(self, H2head).link(COHhead)
150 
151  #
152  # create null stream
153  #
154 
155  NULLhead = gst.element_factory_make("lal_adder")
156  NULLhead.set_property("sync", True)
157  self.add(NULLhead)
158  pipeparts.mkqueue(self, H1tee).link(NULLhead)
159  pipeparts.mkaudioamplify(self, pipeparts.mkqueue(self, H2tee), -1).link(NULLhead)
160 
161  self.add_pad(gst.GhostPad("COHsrc", COHhead.get_pad("src")))
162  self.add_pad(gst.GhostPad("NULLsrc", NULLhead.get_pad("src")))
163 
164 gobject.type_register(lal_lho_coherent_null)
165 
166 __gstelementfactory__ = (
167  lal_lho_coherent_null.__name__,
168  gst.RANK_NONE,
169  lal_lho_coherent_null
170 )