From b049918adf3f3a3eddbb66db49c3908c6e806df2 Mon Sep 17 00:00:00 2001
From: Aaron Viets <aaron.viets@ligo.org>
Date: Fri, 22 Feb 2019 23:28:37 -0800
Subject: [PATCH] lal_matrixsolver:  check determinant of matix to see if its
 singular.

---
 gstlal-calibration/gst/lal/gstlal_matrixsolver.c   | 14 ++++++++++----
 gstlal-calibration/python/calibration_parts.py     |  2 +-
 .../tests/check_calibration/Makefile               |  9 +++++----
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/gstlal-calibration/gst/lal/gstlal_matrixsolver.c b/gstlal-calibration/gst/lal/gstlal_matrixsolver.c
index 4466d06e2e..5743e1e4a4 100644
--- a/gstlal-calibration/gst/lal/gstlal_matrixsolver.c
+++ b/gstlal-calibration/gst/lal/gstlal_matrixsolver.c
@@ -199,11 +199,17 @@ static void solve_system_ ## COMPLEX ## DTYPE(const COMPLEX DTYPE *src, COMPLEX
  \
 		/* Now solve [matrix] [outvec] = [invec] for [outvec] using gsl */ \
 		gsl_linalg_ ## COMPLEX ## UNDERSCORE ## LU_decomp(matrix, permutation, &signum); \
-		gsl_linalg_ ## COMPLEX ## UNDERSCORE ## LU_solve(matrix, permutation, invec, outvec); \
+		if(!isinf(gsl_linalg_ ## COMPLEX ## UNDERSCORE ## LU_lndet(matrix))) { \
+			gsl_linalg_ ## COMPLEX ## UNDERSCORE ## LU_solve(matrix, permutation, invec, outvec); \
  \
-		/* Put the solutions into the output buffer */ \
-		for(j = 0; j < channels_out; j++) \
-			dst[i * channels_out + j] = get_ ## COMPLEX ## double_from_gsl_vector(outvec, j); \
+			/* Put the solutions into the output buffer */ \
+			for(j = 0; j < channels_out; j++) \
+				dst[i * channels_out + j] = get_ ## COMPLEX ## double_from_gsl_vector(outvec, j); \
+		} else { \
+			/* Fill output buffer with zeros */ \
+			for(j = 0; j < channels_out; j++) \
+				dst[i * channels_out + j] = 0.0; \
+		} \
 	} \
 }
 
diff --git a/gstlal-calibration/python/calibration_parts.py b/gstlal-calibration/python/calibration_parts.py
index 40725ad7de..ee588135c3 100644
--- a/gstlal-calibration/python/calibration_parts.py
+++ b/gstlal-calibration/python/calibration_parts.py
@@ -403,7 +403,7 @@ def remove_lines_with_witnesses(pipeline, signal, witnesses, freqs, freq_vars, f
 			tfs_at_f = mkinterleave(pipeline, tfs_at_f, complex_data = True)
 			# It may be necessary to remove data at the beginning so that data that
 			# is missing do to filtering is not replaced with zeros
-			tfs_at_f = pipeparts.mkgeneric(pipeline, tfs_at_f, "lal_insertgap", bad_data_intervals = [-1e35, -1e-35, 1e-35, 1e35], replace_value = 1e-35, chop_length = 1000000000 * int(1 + (1 - filter_latency) * 21))
+			tfs_at_f = pipeparts.mkgeneric(pipeline, tfs_at_f, "lal_insertgap", chop_length = 1000000000 * int(1 + (1 - filter_latency) * 21))
 			tfs_at_f = pipeparts.mkgeneric(pipeline, tfs_at_f, "lal_matrixsolver")
 			tfs_at_f = mkdeinterleave(pipeline, tfs_at_f, len(witnesses[m]), complex_data = True)
 
diff --git a/gstlal-calibration/tests/check_calibration/Makefile b/gstlal-calibration/tests/check_calibration/Makefile
index f58323090c..a792fc6d27 100644
--- a/gstlal-calibration/tests/check_calibration/Makefile
+++ b/gstlal-calibration/tests/check_calibration/Makefile
@@ -18,8 +18,8 @@ END = $(shell echo 1234694144 + 4096 + 715 | bc)
 #1185771520
 SHMRUNTIME = 400
 # How much time does the calibration need to settle at the start and end?
-PLOT_WARMUP_TIME = 885
-PLOT_COOLDOWN_TIME = 4521
+PLOT_WARMUP_TIME = 715
+PLOT_COOLDOWN_TIME = 715
 
 GDSCONFIGS = Filters/ER14/GDSFilters/H1GDS_noisesub_test_1232874910.ini 
 DCSCONFIGS = Filters/ER13/GDSFilters/L1DCS_TEST_1231620000.ini
@@ -27,9 +27,10 @@ DCSCONFIGS = Filters/ER13/GDSFilters/L1DCS_TEST_1231620000.ini
 DCSFCCCONFIGS = ../../config_files/O2/H1/tests/H1DCS_FreqIndepAndFccCorrections_Cleaning.ini
 GDSTESTCONFIGS = ../../config_files/PreER13/H1/H1GDS_TEST_1225558818.ini
 DCSTESTCONFIGS = ../../config_files/O2/H1/tests/H1DCS_AllCorrections_Cleaning_TEST.ini
-GDSSHMCONFIGS = Filters/ER14/GDSFilters/L1GDS_1234630818_latency_test.ini
+GDSSHMCONFIGS = Filters/ER14/GDSFilters/H1GDS_1234630818_latency_test.ini
 
-all: noise_subtraction_ASD_GDS noise_subtraction_range_plots_GDS
+all: latency_test
+#noise_subtraction_ASD_GDS noise_subtraction_range_plots_GDS
 
 ###############################################
 ### These commands should change less often ###
-- 
GitLab