From d6bb4c2a29d3a0cfcffb43ec2c2ebd440e31b7a6 Mon Sep 17 00:00:00 2001
From: Jameson Graef Rollins <jrollins@finestructure.net>
Date: Sat, 12 May 2018 09:05:35 -0700
Subject: [PATCH] use improved Struct interface without accessing internal
 __dict__

---
 gwinc/noise/newtonian.py        |  2 +-
 gwinc/noise/quantum.py          | 14 +++++++-------
 gwinc/noise/substratethermal.py |  4 ++--
 gwinc/struct.py                 |  3 +++
 gwinc/util.py                   |  6 +++---
 5 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/gwinc/noise/newtonian.py b/gwinc/noise/newtonian.py
index a8a6054f..15026d53 100644
--- a/gwinc/noise/newtonian.py
+++ b/gwinc/noise/newtonian.py
@@ -86,7 +86,7 @@ def ground(Seismic, f):
     coeff = 1/(1 + 3**(gamma*(f-fk)))
 
     # modelization of seismic noise (velocity)
-    if 'Site' not in Seismic.__dict__:
+    if 'Site' not in Seismic:
         print('defaulting to Livingston site')
         Seismic.Site = 'LLO'
 
diff --git a/gwinc/noise/quantum.py b/gwinc/noise/quantum.py
index 883635c7..5d8324c4 100644
--- a/gwinc/noise/quantum.py
+++ b/gwinc/noise/quantum.py
@@ -12,7 +12,7 @@ def shotrad(f, ifo, verbose=False):
 
     # deal with multiple bounces, required for resonant delay lines
     # Stefan Ballmer 2012
-    if 'NFolded' in ifo.Infrastructure.__dict__:
+    if 'NFolded' in ifo.Infrastructure:
         if ifo.Infrastructure.travellingWave:
             ifo.Materials.MirrorMass=ifo.Materials.MirrorMass/ifo.Infrastructure.NFolded**2
         else:
@@ -24,7 +24,7 @@ def shotrad(f, ifo, verbose=False):
     # Call IFO Quantum Model
     #####################################################
 
-    if 'Type' not in ifo.Optics.__dict__:
+    if 'Type' not in ifo.Optics:
         fname = shotradSignalRecycled
     else:
         namespace = globals()
@@ -66,10 +66,10 @@ def shotrad(f, ifo, verbose=False):
     # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     # determine squeezer type, if any
     # and extract common parameters
-    if 'Squeezer' not in ifo.__dict__:
+    if 'Squeezer' not in ifo:
         sqzType = 'None'
     else:
-        if 'Type' not in ifo.Squeezer.__dict__:
+        if 'Type' not in ifo.Squeezer:
             sqzType = 'Freq Independent'
         else:
             sqzType = ifo.Squeezer.Type
@@ -84,7 +84,7 @@ def shotrad(f, ifo, verbose=False):
         SQZ_DB = ifo.Squeezer.AmplitudedB        # Squeeing in dB
         lambda_in = ifo.Squeezer.InjectionLoss   # Loss to squeezing before injection [Power]
         alpha = ifo.Squeezer.SQZAngle            # Freq Indep Squeeze angle
-        if 'AntiAmplitudedB' in ifo.Squeezer.__dict__:
+        if 'AntiAmplitudedB' in ifo.Squeezer:
             ANTISQZ_DB = ifo.Squeezer.AntiAmplitudedB # Anti squeezing in db
         else:
             ANTISQZ_DB = SQZ_DB
@@ -146,7 +146,7 @@ def shotrad(f, ifo, verbose=False):
 
     # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     # Inject squeezed field into the IFO via some filter cavities
-    if sqzType == 'Freq Dependent' and 'FilterCavity' in ifo.Squeezer.__dict__:
+    if sqzType == 'Freq Dependent' and 'FilterCavity' in ifo.Squeezer:
         if verbose:
             print('  Applying %d input filter cavities' % np.atleast_1d(ifo.Squeezer.FilterCavity).size)
         Mr, Msqz = sqzFilterCavityChain(f, np.atleast_1d(ifo.Squeezer.FilterCavity), Msqz)
@@ -164,7 +164,7 @@ def shotrad(f, ifo, verbose=False):
 
     # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     # pass IFO output through some filter cavities
-    if 'OutputFilter' in ifo.__dict__:
+    if 'OutputFilter' in ifo:
         if ifo.OutputFilter.Type == 'None':
             # do nothing, say nothing
             pass
diff --git a/gwinc/noise/substratethermal.py b/gwinc/noise/substratethermal.py
index ad9592a7..ba02e3f6 100644
--- a/gwinc/noise/substratethermal.py
+++ b/gwinc/noise/substratethermal.py
@@ -146,7 +146,7 @@ def subbrownianFiniteCorr(ifo, opticName):
     # get some numbers
     a = ifo.Materials.MassRadius
     h = ifo.Materials.MassThickness
-    w = ifo.Optics.__dict__[opticName].BeamRadius
+    w = ifo.Optics[opticName].BeamRadius
     Y = ifo.Materials.Substrate.MirrorY
     sigma = ifo.Materials.Substrate.MirrorSigma
     zeta = ifo.Constants.BesselZeros
@@ -226,7 +226,7 @@ def subthermFiniteCorr(ifo, opticName):
     # extract some numbers
     a = ifo.Materials.MassRadius
     h = ifo.Materials.MassThickness
-    w = ifo.Optics.__dict__[opticName].BeamRadius
+    w = ifo.Optics[opticName].BeamRadius
     sigma = ifo.Materials.Substrate.MirrorSigma
     zeta = ifo.Constants.BesselZeros
 
diff --git a/gwinc/struct.py b/gwinc/struct.py
index deb8a422..04f1a513 100644
--- a/gwinc/struct.py
+++ b/gwinc/struct.py
@@ -75,6 +75,9 @@ class Struct(object):
 
     ##########
 
+    def __getitem__(self, item):
+        return self.__dict__[item]
+
     def __contains__(self, item):
         return item in self.__dict__
 
diff --git a/gwinc/util.py b/gwinc/util.py
index 7a49cec9..f21f0d52 100644
--- a/gwinc/util.py
+++ b/gwinc/util.py
@@ -26,7 +26,7 @@ def precompIFO(ifo, PRfixed=0):
 
     ################################# DERIVED TEMP
 
-    if 'Temp' not in ifo.Materials.Substrate.__dict__:
+    if 'Temp' not in ifo.Materials.Substrate:
         ifo.Materials.Substrate.Temp = ifo.Constants.Temp
 
     ################################# DERIVED OPTICS VALES
@@ -38,7 +38,7 @@ def precompIFO(ifo, PRfixed=0):
     ifo.Optics.ITM.Thickness = ifo.Materials.MassThickness
 
     # coating layer optical thicknesses - mevans 2 May 2008
-    if 'CoatLayerOpticalThickness' not in ifo.Optics.ITM.__dict__:
+    if 'CoatLayerOpticalThickness' not in ifo.Optics.ITM:
         T = ifo.Optics.ITM.Transmittance
         dL = ifo.Optics.ITM.CoatingThicknessLown
         dCap = ifo.Optics.ITM.CoatingThicknessCap
@@ -74,7 +74,7 @@ def precompIFO(ifo, PRfixed=0):
 
     # Seismic noise term is saved in a .mat file defined in your respective IFOModel.m
     # It is loaded here and put into the ifo structure.
-    if 'darmSeiSusFile' in ifo.Seismic.__dict__:
+    if 'darmSeiSusFile' in ifo.Seismic and ifo.Seismic.darmSeiSusFile:
         darmsei = loadmat(ifo.Seismic.darmSeiSusFile)
         ifo.Seismic.darmseis_f = darmsei['darmseis_f'][0]
         ifo.Seismic.darmseis_x = darmsei['darmseis_x'][0]
-- 
GitLab