gstlal  0.8.1
 All Classes Namespaces Files Functions Variables Pages
segmentsrc_test_01.py
1 #!/usr/bin/env python
2 # Copyright (C) 2015 Kipp Cannon
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 #
19 # =============================================================================
20 #
21 # Preamble
22 #
23 # =============================================================================
24 #
25 
26 
27 import numpy
28 from glue import segments
29 from lal import LIGOTimeGPS
30 from gstlal import pipeio
31 from gstlal import pipeparts
32 
33 import test_common
34 from test_common import gst
35 import cmp_nxydumps
36 
37 
38 #
39 # =============================================================================
40 #
41 # Pipelines
42 #
43 # =============================================================================
44 #
45 
46 
47 def segmentsrc_test_01(pipeline, name, seg):
48  segs = segments.segmentlist([segments.segment(LIGOTimeGPS(100), LIGOTimeGPS(200)), segments.segment(LIGOTimeGPS(250), LIGOTimeGPS(300))])
49 
50  head = pipeparts.mksegmentsrc(pipeline, segs, blocksize = 1)
51  head = pipeparts.mkcapsfilter(pipeline, head, "audio/x-raw-int, rate=4")
52  head = pipeparts.mknxydumpsink(pipeline, head, "%s_out.dump" % name)
53 
54  f = open("%s_in.dump" % name, "w")
55  for t in numpy.arange(float(seg[0]), float(seg[1]), 0.25):
56  print >>f, "%g\t%d" % (t, 128 if t in segs else 0)
57 
58  return pipeline
59 
60 
61 #
62 # =============================================================================
63 #
64 # Main
65 #
66 # =============================================================================
67 #
68 
69 
70 seg = segments.segment(LIGOTimeGPS(0), LIGOTimeGPS(350))
71 test_common.build_and_run(segmentsrc_test_01, segment = seg, seg = seg, name = "segmentsrc_test_01a")
72 cmp_nxydumps.compare("segmentsrc_test_01a_in.dump", "segmentsrc_test_01a_out.dump")