From 6dbf518e0a99eb668e0f8fdd4240485b9d275841 Mon Sep 17 00:00:00 2001
From: Jameson Graef Rollins <jrollins@finestructure.net>
Date: Tue, 15 May 2018 10:33:49 -0700
Subject: [PATCH] simplify suspension type handling by using string names

ifo.Suspension.Type now accepts string for suspension calc func, e.g. 'Quad'
for 'suspQuad' calc.
---
 gwinc/gwinc.py                   | 16 +++++++---------
 gwinc/ifo/A+.yaml                |  4 +---
 gwinc/ifo/Voyager.yaml           |  2 +-
 gwinc/ifo/aLIGO.yaml             |  4 +---
 gwinc/noise/suspensionthermal.py | 24 +++++++++---------------
 5 files changed, 19 insertions(+), 31 deletions(-)

diff --git a/gwinc/gwinc.py b/gwinc/gwinc.py
index b12bc31f..9bf2072c 100644
--- a/gwinc/gwinc.py
+++ b/gwinc/gwinc.py
@@ -13,16 +13,14 @@ def noise_calc(ifo, f):
     """Calculate all IFO noises and return as dict
 
     """
+    ##############################
+    # suspension transfer functions
+    #
+    # this needs to be done here, instead of in precompIFO, because it
+    # requires the frequency vector
 
-    # quad cases, for backward compatability
-    if ifo.Suspension.Type in (0, 1, 2):
-        hForce, vForce, hTable, vTable = noise.suspensionthermal.suspQuad(f, ifo)
-    elif ifo.Suspension.Type == 'Quad':
-        ifo.Suspension.Type = 0
-        hForce, vForce, hTable, vTable = noise.suspensionthermal.suspQuad(f, ifo)
-    else:
-        fname = noise.suspensionthermal.__dict__['susp' + str(ifo.Suspension.Type)]
-        hForce, vForce, hTable, vTable = fname(f, ifo)
+    fname = eval('noise.suspensionthermal.susp{}'.format(ifo.Suspension.Type))
+    hForce, vForce, hTable, vTable = fname(f, ifo)
 
     # if the suspension code supports different temps for the stages
     try:
diff --git a/gwinc/ifo/A+.yaml b/gwinc/ifo/A+.yaml
index f99c9532..536e47df 100644
--- a/gwinc/ifo/A+.yaml
+++ b/gwinc/ifo/A+.yaml
@@ -70,9 +70,7 @@ Seismic:
   Omicron: 1                      # Feedforward cancellation factor
 
 Suspension:
-  # 0 for cylindrical suspension
-  #Type: 'Quad'
-  Type: 2
+  Type: 'Quad'
   # 0: round, 1: ribbons, 2: tapered
   FiberType: 2
   BreakStress: 750e6              # Pa; ref. K. Strain
diff --git a/gwinc/ifo/Voyager.yaml b/gwinc/ifo/Voyager.yaml
index 11aa1574..6b064787 100644
--- a/gwinc/ifo/Voyager.yaml
+++ b/gwinc/ifo/Voyager.yaml
@@ -79,7 +79,7 @@ Seismic:
   #darmSeiSusFile: 'CryogenicLIGO/Sensitivity/GWINC/seismic.mat'
 
 Suspension:
-  Type: 'BQuad' # 0 for cylindrical suspension
+  Type: 'BQuad'
   # Suspension fiber temperatures [TOP UIM PUM TST]
   Temp:
     - 300.0
diff --git a/gwinc/ifo/aLIGO.yaml b/gwinc/ifo/aLIGO.yaml
index 89617983..68014c4d 100644
--- a/gwinc/ifo/aLIGO.yaml
+++ b/gwinc/ifo/aLIGO.yaml
@@ -68,9 +68,7 @@ Seismic:
   Omicron: 1                      # Feedforward cancellation factor
 
 Suspension:
-  # 0 for cylindrical suspension
-  #Type: 'Quad'
-  Type: 2
+  Type: 'Quad'
   # 0: round, 1: ribbons
   FiberType: 0
   BreakStress: 750e6              # Pa; ref. K. Strain
diff --git a/gwinc/noise/suspensionthermal.py b/gwinc/noise/suspensionthermal.py
index 6e99e759..9fcd1aa9 100644
--- a/gwinc/noise/suspensionthermal.py
+++ b/gwinc/noise/suspensionthermal.py
@@ -6,10 +6,13 @@ from scipy.io.matlab.mio5_params import mat_struct
 
 
 def suspR(f, ifo):
-    """Thermal noise for quadruple pendulum
-    switches to various suspension types based on ifo.Suspension.Type
-    the general case calls the suspTYPE function to generate TFs"""
+    """Suspention thermal noise.
 
+    Assumes suspension transfer functions and V-H coupling have been
+    pre-calculated and populated into the relevant `ifo` struct
+    fields.
+
+    """
     # Assign Physical Constants
     kB   = scipy.constants.k
     Temp = ifo.Suspension.Temp
@@ -65,18 +68,9 @@ def suspR(f, ifo):
             w = 2*pi*f
             noise += 4 * kB * Temp[ii] * abs(imag(dxdF[ii,:])) / w
 
-    if ifo.Suspension.Type == 'Quad_MB':
-        raise Exception('not dealing with Quad_MB suspensions currently')
-        #mbquadlite2lateral_20090819TM_TN;
-        #tvec = sqrt(xvec.^2 + (1e-3*zvec).^2);
-        #tvec = tvec*2;  % 4 masses
-        #nn.SuspThermalB = interp1(fvec, tvec, f, [], 0);
-        #noise = nn.SuspThermalB/ifo.Infrastructure.Length;  % convert to strain
-        #noise = noise.^2; %square to make strain^2
-    else:
-        # turn into gravitational wave strain; 4 masses
-        noise *= 4 / ifo.Infrastructure.Length**2
-        return np.squeeze(noise)
+    # 4 masses, turn into gravitational wave strain
+    noise *= 4 / ifo.Infrastructure.Length**2
+    return np.squeeze(noise)
 
 
 def suspBQuad(f, ifo):
-- 
GitLab