gstlal 1.13.0
Loading...
Searching...
No Matches
peak_test_01.py
1#!/usr/bin/env python3
2# Copyright (C) 2014 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
27import numpy
28import sys
29from gstlal import pipeparts
30import test_common
31import cmp_nxydumps
32
33
34#
35# =============================================================================
36#
37# Pipelines
38#
39# =============================================================================
40#
41
42
43#
44# is the element an identity transform when given 1 channel of 1s and n = 1 ?
45#
46
47
48def peak_test_01(pipeline, name, width):
49 #
50 # try changing these. test should still work!
51 #
52
53 rate = 2048 # Hz
54 gap_frequency = 13.0 # Hz
55 gap_threshold = 0.8 # of 1
56 buffer_length = 1.0 # seconds
57 test_duration = 100.0 # seconds
58 n = 1 # samples
59
60 #
61 # build pipeline. square wave with 0 frequency = stream of 1s
62 #
63
64 head = test_common.gapped_test_src(pipeline, buffer_length = buffer_length, rate = rate, width = width, wave = 1, freq = 0, channels = 1, test_duration = test_duration, gap_frequency = gap_frequency, gap_threshold = gap_threshold, control_dump_filename = "%s_control.dump" % name)
65 head = tee = pipeparts.mktee(pipeline, head)
66
67 head = pipeparts.mkpeak(pipeline, head, n = n)
68 head = pipeparts.mkchecktimestamps(pipeline, head)
69 pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, head), "%s_out.dump" % name)
70 pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, tee), "%s_in.dump" % name)
71
72 #
73 # done
74 #
75
76 return pipeline
77
78
79#
80# test the transformation of a specific buffer
81#
82
83
84def peak_test_02(name, dtype, arrays, n, sample_fuzz = cmp_nxydumps.default_sample_fuzz):
85 channels_in = 1
86 numpy.random.seed(0)
87 input_array = None
88 output_reference = None
89 for a in range(arrays):
90 IA = numpy.random.random((n, channels_in)).astype(dtype)
91 OR = numpy.copy(IA)
92 OR[OR < max(OR)] = 0.
93 if input_array is not None:
94 input_array = numpy.append(input_array, IA, axis = 0)
95 output_reference = numpy.append(output_reference, OR, axis = 0)
96 else:
97 input_array = IA
98 output_reference = OR
99
100 output_array = numpy.reshape(numpy.ndarray.flatten(numpy.array(test_common.transform_arrays([input_array], pipeparts.mkpeak, name, n = n))), output_reference.shape)
101 residual = abs((output_array - output_reference))
102 if residual[residual > sample_fuzz].any():
103 raise ValueError("incorrect output: expected %s, got %s\ndifference = %s" % (output_reference, output_array, residual))
104
105
106#
107# =============================================================================
108#
109# Main
110#
111# =============================================================================
112#
113
114
115test_common.build_and_run(peak_test_01, "peak_test_01a", width = 64)
116cmp_nxydumps.compare("peak_test_01a_in.dump", "peak_test_01a_out.dump", flags = cmp_nxydumps.COMPARE_FLAGS_EXACT_GAPS)
117test_common.build_and_run(peak_test_01, "peak_test_01b", width = 32)
118cmp_nxydumps.compare("peak_test_01b_in.dump", "peak_test_01b_out.dump", flags = cmp_nxydumps.COMPARE_FLAGS_EXACT_GAPS)
119
120peak_test_02("peak_test_02a", "float64", arrays = 29, n = 117, sample_fuzz = cmp_nxydumps.default_sample_fuzz)
121peak_test_02("peak_test_02b", "float32", arrays = 29, n = 117, sample_fuzz = cmp_nxydumps.default_sample_fuzz**.5)
compare(filename1, filename2, *args, **kwargs)
transform_arrays(input_arrays, elemfunc, name, rate=1, **elemfunc_kwargs)
build_and_run(pipelinefunc, name, segment=None, **pipelinefunc_kwargs)
gapped_test_src(pipeline, buffer_length=1.0, rate=2048, width=64, channels=1, test_duration=10.0, wave=5, freq=0, gap_frequency=None, gap_threshold=None, control_dump_filename=None, tags=None, is_live=False, verbose=True)