changeset 42:184ea77c10e7

Use scipys interpolation routines rather than hand rolling.
author Daniel O'Connor <darius@dons.net.au>
date Wed, 28 Sep 2011 14:38:23 +0930
parents df1b4d7e988f
children 7ba7207df078
files sitesurvey.py
diffstat 1 files changed, 3 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/sitesurvey.py	Wed Sep 28 13:35:45 2011 +0930
+++ b/sitesurvey.py	Wed Sep 28 14:38:23 2011 +0930
@@ -31,6 +31,7 @@
 import exceptions
 import numpy
 import os
+import scipy.interpolate
 import scpi
 import specan
 import sys
@@ -86,21 +87,8 @@
         self.calfreqs = freqs
         self.calgains = gains
 
-    def interp(self, freqs):
-        '''Interoplate the calibration over freqs and return an array'''
-        deltas = numpy.zeros(freqs.shape)
-
-        for i in range(len(freqs)):
-            if freqs[i] < self.calfreqs[0] or freqs[i] > self.calfreqs[-1]:
-                raise exceptions.SyntaxError("Frequency %.1f is out of range of calibration %f - %f" % (f, calfreqs[0], calfreqs[-1]))
-
-            # Find idx such that calfreqs[idx - 1] < freqs[i] <= calfreqs[idx]
-            idx = self.calfreqs.searchsorted(freqs[i])
-            sf = (freqs[i] - self.calfreqs[idx - 1]) / (self.calfreqs[idx] - self.calfreqs[idx - 1])
-            delta = ((self.calgains[idx] - self.calgains[idx - 1]) * sf) + self.calgains[idx]
-            deltas[i] = delta
-        return deltas
-
+        # Create interpolation function
+        self.interp = scipy.interpolate.interp1d(self.calfreqs, self.calgains, bound_error = True)
 
 def getexpt(sequence):
     '''Given a sequence return the experiment which should be run next and how long until it should start'''