comparison sitesurvey.py @ 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 660a2997e720
children 7ba7207df078
comparison
equal deleted inserted replaced
41:df1b4d7e988f 42:184ea77c10e7
29 import ConfigParser 29 import ConfigParser
30 import datetime 30 import datetime
31 import exceptions 31 import exceptions
32 import numpy 32 import numpy
33 import os 33 import os
34 import scipy.interpolate
34 import scpi 35 import scpi
35 import specan 36 import specan
36 import sys 37 import sys
37 import time 38 import time
38 39
84 raise exceptions.SyntaxError("Format of cal file incorrect (length of gain and freqs aren't equal)") 85 raise exceptions.SyntaxError("Format of cal file incorrect (length of gain and freqs aren't equal)")
85 86
86 self.calfreqs = freqs 87 self.calfreqs = freqs
87 self.calgains = gains 88 self.calgains = gains
88 89
89 def interp(self, freqs): 90 # Create interpolation function
90 '''Interoplate the calibration over freqs and return an array''' 91 self.interp = scipy.interpolate.interp1d(self.calfreqs, self.calgains, bound_error = True)
91 deltas = numpy.zeros(freqs.shape)
92
93 for i in range(len(freqs)):
94 if freqs[i] < self.calfreqs[0] or freqs[i] > self.calfreqs[-1]:
95 raise exceptions.SyntaxError("Frequency %.1f is out of range of calibration %f - %f" % (f, calfreqs[0], calfreqs[-1]))
96
97 # Find idx such that calfreqs[idx - 1] < freqs[i] <= calfreqs[idx]
98 idx = self.calfreqs.searchsorted(freqs[i])
99 sf = (freqs[i] - self.calfreqs[idx - 1]) / (self.calfreqs[idx] - self.calfreqs[idx - 1])
100 delta = ((self.calgains[idx] - self.calgains[idx - 1]) * sf) + self.calgains[idx]
101 deltas[i] = delta
102 return deltas
103
104 92
105 def getexpt(sequence): 93 def getexpt(sequence):
106 '''Given a sequence return the experiment which should be run next and how long until it should start''' 94 '''Given a sequence return the experiment which should be run next and how long until it should start'''
107 95
108 now = datetime.datetime.utcnow() 96 now = datetime.datetime.utcnow()