Skip to content
Snippets Groups Projects
Commit f5b1a1f3 authored by Aaron Viets's avatar Aaron Viets
Browse files

State Vector test for CI

parent be9cf351
No related branches found
No related tags found
No related merge requests found
Pipeline #648188 passed
#!/usr/bin/env python3
# Copyright (C) 2018 Aaron Viets, Alexander Bartoletti
# Copyright (C) 2023 Aaron Viets, Alexander Bartoletti
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
......@@ -27,10 +27,6 @@ from tests.tests_pytest.plot import plot_ASD
from lal import LIGOTimeGPS
from ligo import segments
import configparser
#from utils import common
gps_start_time = 1404305400
gps_end_time = 1404308200
......
#!/usr/bin/env python3
# Copyright (C) 2018 Aaron Viets, Alexander Bartoletti
# Copyright (C) 2024 Aaron Viets, Alexander Bartoletti
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
......@@ -15,30 +15,95 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# use bin() in python to convert to binary, or % 2 to determine if the last bit of the State Vector (h(t) ok) is on, 54759354 & 35797435 gives binary (1 only of both are 1s in that place)
import numpy as np
def bit_mask():
fail_times = []
standard = np.loadtxt('tests/tests_pytest/H1_Standard_State_Vector.txt')
data = np.loadtxt('tests/tests_pytest/H1_State_Vector.txt')
standard = np.transpose(standard)
data = np.transpose(data)
time = data[0]
standard = standard[1]
data = data[1]
e_file = open('tests/tests_pytest/error_results.txt', 'a')
for i in range(len(standard)):
int_standard = int(standard[i])
int_data = int(data[i])
bin_standard = bin(int(int_standard))
bin_data = bin(int(int_data))
str_standard = str(bin_standard)[-1]
str_data = str(bin_data)[-1]
bits = int(str_standard) & int(str_data)
if int_data % 2 != int_standard % 2:
#if bits % 2 == 0:
fail_times.append(int(time[i]))
e_file.write('h(t) not on for both: ' + str(fail_times) + '\n')
assert len(fail_times) == 0
def check_bits(filename):
# Numbers corresponding to each bit
bits = []
for i in range(21):
bits.append(2**i)
# Bit definitions
bitnames = []
bitnames.append("hoft_ok_bit")
bitnames.append("obs_intent_bit")
bitnames.append("lownoise_bit")
bitnames.append("filters_ok_bit")
bitnames.append("no_gap_bit")
bitnames.append("no_stoch_inj_bit")
bitnames.append("no_cbc_inj_bit")
bitnames.append("no_burst_inj_bit")
bitnames.append("no_detchar_inj_bit")
bitnames.append("undisturbed_ok_bit")
bitnames.append("ktst_smooth_bit")
bitnames.append("kpum_smooth_bit")
bitnames.append("kuim_smooth_bit")
bitnames.append("kc_smooth_bit")
bitnames.append("fcc_smooth_bit")
bitnames.append("fs_smooth_bit")
bitnames.append("fs_over_Q_smooth_bit")
bitnames.append("line_sub_bit")
bitnames.append("noise_sub_bit")
bitnames.append("noise_sub_gate_bit")
bitnames.append("nonsens_sub_bit")
standard = np.loadtxt('tests/tests_pytest/State_Vector_data/%s_standard.txt' % filename)
data = np.loadtxt('tests/tests_pytest/State_Vector_data/%s.txt' % filename)
# Make sure the data overlaps a reasonable amount
assert abs(standard[0][0] - data[0][0]) < 100
assert abs(standard[-1][0] - data[-1][0]) < 100
# Trim if needed
missing_initial_data_samples = int(16 * (data[0][0] - standard[0][0]))
missing_final_data_samples = int(16 * (standard[-1][0] - data[-1][0]))
if missing_initial_data_samples > 0:
# Trim beginning of "standard" data
standard = standard[missing_initial_data_samples:]
elif missing_initial_data_samples < 0:
# Trim beginning of test data
data = data[abs(missing_initial_data_samples):]
if missing_final_data_samples > 0:
# Trim end of "standard" data
standard = standard[:-missing_final_data_samples]
elif missing_final_data_samples < 0:
# Trim end of test data
data = data[:missing_final_data_samples]
standard = np.transpose(standard)[1]
data = np.transpose(data)[1]
for i in [1, 2, 3, 4, 5, 6, 7, 8, 9, 19]:
# Require agreement at each sample
e_file = open('tests/tests_pytest/error_results.txt', 'a')
e_file.write("Testing %s\n" % bitnames[i])
for j in range(len(data)):
assert int(data[j]) & bits[i] == int(standard[j]) & bits[i], "%s failure!" % bitnames[i]
e_file.write("%s passed\n" % bitnames[i])
e_file.close()
for i in [0, 10, 11, 12, 13, 14, 15, 16]:
# Allow small differences in on/off transition times
e_file = open('tests/tests_pytest/error_results.txt', 'a')
e_file.write("Testing %s\n" % bitnames[i])
consecutive_failures = 0
for j in range(len(data)):
if int(data[j]) & bits[i] != int(standard[j]) & bits[i]:
consecutive_failures += 1
else:
consecutive_failures = 0
assert consecutive_failures < 160, "%s failure!" % bitnames[i] # 10 seconds at a 16-Hz sample rate
e_file.write("%s passed\n" % bitnames[i])
e_file.close()
for i in [17, 18, 20]:
# Require agreement at a majority of samples
e_file = open('tests/tests_pytest/error_results.txt', 'a')
e_file.write("Testing %s\n" % bitnames[i])
failures = 0
for j in range(len(data)):
if int(data[j]) & bits[i] != int(standard[j]) & bits[i]:
failures += 1
assert float(failures) / len(data) < 0.1, "%s failure!" % bitnames[i]
e_file.write("%s passed\n" % bitnames[i])
e_file.close()
#!/usr/bin/env python3
# Copyright (C) 2018 Aaron Viets, Alexander Bartoletti
# Copyright (C) 2023 Aaron Viets, Alexander Bartoletti
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
......@@ -15,15 +15,8 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import numpy
from math import pi
from math import erf
import resource
import datetime
import glob
import configparser
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst
......@@ -40,32 +33,35 @@ from gstlal import datasource
from ligo import segments
from gstlalcalibration import test_common
from tests.tests_pytest.STV_error import bit_mask
from optparse import OptionParser, Option
import configparser
parser = OptionParser()
parser.add_option("--gps-start-time", metavar = "seconds", type = int, default = 1370674240, help = "GPS time at which to start processing data")
parser.add_option("--gps-end-time", metavar = "seconds", type = int, default = 1370678400, help = "GPS time at which to stop processing data")
parser.add_option("--ifo", metavar = "name", default = "H1", help = "Name of the interferometer (IFO), e.g., H1, L1")
from tests.tests_pytest.STV_error import check_bits
options, filenames = parser.parse_args()
ifo = options.ifo
ifo = 'H1'
gps_start_time = 1404304248
gps_end_time = 1404308216
Approx_txtfilename = 'State_Vector_Approx'
Exact_txtfilename = 'State_Vector_Exact'
def state_vector_Approx(pipeline, name):
data = pipeparts.mklalcachesrc(pipeline, location = "tests/tests_pytest/GDS_Approx_frames.cache", cache_dsc_regex = ifo)
data = pipeparts.mkframecppchanneldemux(pipeline, data, do_file_checksum = False, skip_bad_files = True, channel_list = list(map("%s:%s".__mod__, [("H1", "GDS-CALIB_STATE_VECTOR")])))
data = calibration_parts.hook_up(pipeline, data, "GDS-CALIB_STATE_VECTOR", ifo, 1.0)
data = calibration_parts.caps_and_progress(pipeline, data, "audio/x-raw,format=U32LE,channels=1,channel-mask=(bitmask)0x0", "State_Vector")
data = pipeparts.mknxydumpsink(pipeline, data, "tests/tests_pytest/State_Vector_data/%s.txt" % Approx_txtfilename)
return pipeline
def state_vector(pipeline, name):
data = pipeparts.mklalcachesrc(pipeline, location = "tests/tests_pytest/GDS_frames.cache", cache_dsc_regex = ifo)
data = pipeparts.mkframecppchanneldemux(pipeline, data, do_file_checksum = False, skip_bad_files = True, channel_list = list(map("%s:%s".__mod__, [("H1", "GDS-CALIB_STATE_VECTOR")])))
data = calibration_parts.hook_up(pipeline, data, "GDS-CALIB_STATE_VECTOR", ifo, 1.0)
data = calibration_parts.caps_and_progress(pipeline, data, "audio/x-raw,format=U32LE,channels=1,channel-mask=(bitmask)0x0", "State_Vector")
data = pipeparts.mknxydumpsink(pipeline, data, "tests/tests_pytest/%s_State_Vector.txt" % ifo)
return pipeline
def state_vector_Exact(pipeline, name):
data = pipeparts.mklalcachesrc(pipeline, location = "tests/tests_pytest/GDS_Approx_frames.cache", cache_dsc_regex = ifo)
data = pipeparts.mkframecppchanneldemux(pipeline, data, do_file_checksum = False, skip_bad_files = True, channel_list = list(map("%s:%s".__mod__, [("H1", "GDS-CALIB_STATE_VECTOR")])))
data = calibration_parts.hook_up(pipeline, data, "GDS-CALIB_STATE_VECTOR", ifo, 1.0)
data = calibration_parts.caps_and_progress(pipeline, data, "audio/x-raw,format=U32LE,channels=1,channel-mask=(bitmask)0x0", "State_Vector")
data = pipeparts.mknxydumpsink(pipeline, data, "tests/tests_pytest/State_Vector_data/%s.txt" % Exact_txtfilename)
return pipeline
def State_Vector():
test_common.build_and_run(state_vector, "state_vector", segment = segments.segment((LIGOTimeGPS(0, 1000000000 * options.gps_start_time), LIGOTimeGPS(0, 1000000000 * options.gps_end_time))))
bit_mask()
test_common.build_and_run(state_vector_Approx, "state_vector_Approx", segment = segments.segment((LIGOTimeGPS(0, 1000000000 * gps_start_time), LIGOTimeGPS(0, 1000000000 * gps_end_time))))
test_common.build_and_run(state_vector_Exact, "state_vector_Exact", segment = segments.segment((LIGOTimeGPS(0, 1000000000 * gps_start_time), LIGOTimeGPS(0, 1000000000 * gps_end_time))))
check_bits(Approx_txtfilename)
check_bits(Exact_txtfilename)
Source diff could not be displayed: it is stored in LFS. Options to address this: view the blob.
Source diff could not be displayed: it is stored in LFS. Options to address this: view the blob.
#!/usr/bin/env python3
# Copyright (C) 2023 Aaron Viets, Alexander Bartoletti
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import subprocess
import shlex
import os
#from tests.tests_pytest.State_Vector import State_Vector
#from tests.tests_pytest.ASD import ASD
from tests.tests_pytest.State_Vector import State_Vector
from tests.tests_pytest.ASD import ASD
from tests.tests_pytest.act2darm_timeseries import Act2darm
from tests.tests_pytest.pcal2darm_timeseries import Pcal2darm
from tests.tests_pytest.run_calib_pipeline import Run_calib
......@@ -15,10 +33,10 @@ def test_Calib_Pipeline():
def test_ASD():
ASD()
'''
def test_state_vector():
State_Vector()
'''
def test_act2darm():
Act2darm()
......@@ -31,4 +49,3 @@ def test_diff():
def test_latency():
Latency()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment