From 23468b28c9574a54734f7fcc4038fa2dacc3cd8e Mon Sep 17 00:00:00 2001
From: Aaron Viets <aaron.viets@ligo.org>
Date: Sat, 17 Nov 2018 20:43:41 -0800
Subject: [PATCH] gstlal_compute_strain:  Better way to to check for config
 file options that may not be present.  New option to flip sign of the pcal
 channel.

---
 gstlal-calibration/bin/gstlal_compute_strain | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/gstlal-calibration/bin/gstlal_compute_strain b/gstlal-calibration/bin/gstlal_compute_strain
index 719251ed46..8458794978 100755
--- a/gstlal-calibration/bin/gstlal_compute_strain
+++ b/gstlal-calibration/bin/gstlal_compute_strain
@@ -169,9 +169,6 @@ Bitmasks = ConfigSectionMap("Bitmasks")
 PipelineConfigs = ConfigSectionMap("PipelineConfigurations")
 DataCleaningConfigs = ConfigSectionMap("DataCleaningConfigurations")
 
-# Track the "version" of the config file, which tells us what variables are contained
-config_version = int(InputConfigs["configversion"])
-
 
 # Sanity checks for command line options
 data_sources = set(("frames", "lvshm"))
@@ -255,6 +252,7 @@ actuation_filter_taper_length = int(TDCFConfigs["actuationfiltertaperlength"])
 sensing_filter_update_time = float(TDCFConfigs["sensingfilterupdatetime"])
 sensing_filter_averaging_time = float(TDCFConfigs["sensingfilteraveragingtime"])
 sensing_filter_taper_length = int(TDCFConfigs["sensingfiltertaperlength"])
+pcal_sign = float(TDCFConfigs["pcalsign"]) if "pcalsign" in TDCFConfigs else 1.0
 cleaning_check_rms_time = float(DataCleaningConfigs["cleaningcheckrmstime"])
 cleaning_check_range_low_min = float(DataCleaningConfigs["cleaningcheckrangelowmin"])
 cleaning_check_range_low_max = float(DataCleaningConfigs["cleaningcheckrangelowmax"])
@@ -346,7 +344,7 @@ remove_cal_lines = Config.getboolean("DataCleaningConfigurations", "removecallin
 remove_power_lines = Config.getboolean("DataCleaningConfigurations", "removepowerlines")
 remove_dc = Config.getboolean("DataCleaningConfigurations", "removedc")
 witness_tf_use_median = Config.getboolean("DataCleaningConfigurations", "witnesstfusemedian")
-witness_tf_parallel_mode = False if config_version < 2 else Config.getboolean("DataCleaningConfigurations", "witnesstfparallelmode")
+witness_tf_parallel_mode = Config.getboolean("DataCleaningConfigurations", "witnesstfparallelmode") if "witnesstfparallelmode" in DataCleaningConfigs else False
 # If td is true we will perform filtering in the time domain (direct convolution) in all FIR filtering routines below
 td = not Config.getboolean("PipelineConfigurations", "frequencydomainfiltering")
 # Boolean for dewhitening
@@ -936,7 +934,7 @@ if compute_kappapu:
 if compute_kappatst or compute_kappapum or compute_kappauim or compute_kappapu or compute_kappac or compute_fcc or compute_srcq or compute_fs:
 
 	# demodulate the PCAL channel and apply the PCAL correction factor at the DARM actuation line frequency
-	pcal_at_act_pcal_freq = calibration_parts.demodulate(pipeline, pcaltee, act_pcal_line_freq, td, compute_factors_sr, demodulation_filter_time, filter_latency_factor, prefactor_real = pcal_corr_at_act_freq_real, prefactor_imag = pcal_corr_at_act_freq_imag)
+	pcal_at_act_pcal_freq = calibration_parts.demodulate(pipeline, pcaltee, act_pcal_line_freq, td, compute_factors_sr, demodulation_filter_time, filter_latency_factor, prefactor_real = pcal_sign * pcal_corr_at_act_freq_real, prefactor_imag = pcal_sign * pcal_corr_at_act_freq_imag)
 	pcal_at_act_pcal_freq = pipeparts.mktee(pipeline, pcal_at_act_pcal_freq)
 	if remove_cal_lines:
 		# This will save having to demodulate it again
@@ -1151,7 +1149,7 @@ if compute_kappapu:
 # Compute \kappa_c and f_cc
 if compute_kappac or compute_fcc or compute_fs or compute_srcq:
 	# demodulate the PCAL channel and apply the PCAL correction factor at optical gain and f_cc line frequency
-	pcal_at_opt_gain_freq = calibration_parts.demodulate(pipeline, pcaltee, opt_gain_fcc_line_freq, td, compute_factors_sr, demodulation_filter_time, filter_latency_factor, prefactor_real = pcal_corr_at_opt_gain_fcc_freq_real, prefactor_imag = pcal_corr_at_opt_gain_fcc_freq_imag)
+	pcal_at_opt_gain_freq = calibration_parts.demodulate(pipeline, pcaltee, opt_gain_fcc_line_freq, td, compute_factors_sr, demodulation_filter_time, filter_latency_factor, prefactor_real = pcal_sign * pcal_corr_at_opt_gain_fcc_freq_real, prefactor_imag = pcal_sign * pcal_corr_at_opt_gain_fcc_freq_imag)
 	if remove_cal_lines:
 		# This will save having to demodulate it again
 		pcal_at_opt_gain_freq = pipeparts.mktee(pipeline, pcal_at_opt_gain_freq)
@@ -1266,7 +1264,7 @@ if compute_fs or compute_srcq:
 	if src_pcal_line_freq == act_pcal_line_freq:
 		pcal_at_src_freq = pcal_at_act_pcal_freq
 	else:
-		pcal_at_src_freq = calibration_parts.demodulate(pipeline, pcaltee, src_pcal_line_freq, td, compute_factors_sr, demodulation_filter_time, filter_latency_factor, prefactor_real = pcal_corr_at_src_freq_real, prefactor_imag = pcal_corr_at_src_freq_imag)
+		pcal_at_src_freq = calibration_parts.demodulate(pipeline, pcaltee, src_pcal_line_freq, td, compute_factors_sr, demodulation_filter_time, filter_latency_factor, prefactor_real = pcal_sign * pcal_corr_at_src_freq_real, prefactor_imag = pcal_sign * pcal_corr_at_src_freq_imag)
 		pcal_at_src_freq = pipeparts.mktee(pipeline, pcal_at_src_freq)
 	if "pcal4" in pcal_line_removal_dict:
 		# This will save having to demodulate it again
@@ -2120,7 +2118,7 @@ if remove_cal_lines:
 	for pcal_line_name in pcal_line_removal_dict:
 		if not pcal_line_removal_dict[pcal_line_name][4]:
 			# This line still needs to be demodulated
-			pcal_line_removal_dict[pcal_line_name][0] = calibration_parts.demodulate(pipeline, pcal_line_removal_dict[pcal_line_name][0], pcal_line_removal_dict[pcal_line_name][1], td, compute_factors_sr, demodulation_filter_time, filter_latency_factor, prefactor_real = pcal_line_removal_dict[pcal_line_name][2], prefactor_imag = pcal_line_removal_dict[pcal_line_name][3])
+			pcal_line_removal_dict[pcal_line_name][0] = calibration_parts.demodulate(pipeline, pcal_line_removal_dict[pcal_line_name][0], pcal_line_removal_dict[pcal_line_name][1], td, compute_factors_sr, demodulation_filter_time, filter_latency_factor, prefactor_real = pcal_sign * pcal_line_removal_dict[pcal_line_name][2], prefactor_imag = pcal_sign * pcal_line_removal_dict[pcal_line_name][3])
 		# Reconstruct a pcal signal at only this pcal line
 		pcal_line_removal_dict[pcal_line_name][0] = calibration_parts.mkresample(pipeline, pcal_line_removal_dict[pcal_line_name][0], 3, False, "audio/x-raw, format=Z128LE, rate=%d, channel-mask=(bitmask)0x0" % hoft_sr)
 		pcal_line_removal_dict[pcal_line_name][0] = pipeparts.mkgeneric(pipeline, pcal_line_removal_dict[pcal_line_name][0], "lal_demodulate", line_frequency = -1.0 * pcal_line_removal_dict[pcal_line_name][1], prefactor_real = 2.0)
@@ -2166,7 +2164,7 @@ if remove_cal_lines:
 	clean_strain = calibration_parts.mkadder(pipeline, calibration_parts.list_srcs(pipeline, straintee, calibration_lines))
 
 # Pick a bit from the ODC state vector to gate the power mains and noise subtraction
-noisesub_gate_bitmask = 2 if config_version < 1 else int(Bitmasks["noisesubgatebitmask"])
+noisesub_gate_bitmask = int(Bitmasks["noisesubgatebitmask"]) if "noisesubgatebitmask" in Bitmasks else 2
 if compute_calib_statevector and (remove_power_lines or witness_channel_list is not None) and noisesub_gate_bitmask >= 0:
 	noisesubgate = pipeparts.mkgeneric(pipeline, odcstatevectortee, "lal_logicalundersample", required_on = noisesub_gate_bitmask, status_out = pow(2,28))
 	noisesubgate = pipeparts.mkcapsfilter(pipeline, noisesubgate, calibstate_caps)
-- 
GitLab