The following is a snippet of code from my program:
def get_data(self):
self.position = self.hfile.tell()/self.sizeof_data
try:
self.iq = scipy.fromfile(self.hfile, dtype=self.datatype, count=self.block_length)
except MemoryError:
print "End of File"
else:
self.iq_fft = self.dofft(self.iq)
x = self.iq_fft
maximum = np.argmax(x)
average = np.mean(x)
print "\nAvage Value: ", average
#set up Get Data loop
loops = self.files/self.block_length
self.counter += 1
count = self.counter
count += 1
print "\nCOUNT: ", count
#print "\nloop: ", loops
if count == loop:
raise SystemExit #Exits program gracefully
else:
self.get_data()
def dofft(self, iq):
N = len(iq)
iq_fft = scipy.fftpack.fftshift(scipy.fft(iq)) # fft and shift axis
iq_fft = scipy.log10(abs((iq_fft))) # convert to decibels, adjust power
# adding 1e-15 (-300 dB) to protect against value errors if an item in iq_fft is 0
return iq_fft
It works great unless loop is greater than 989, then the whole thing blows up. I have seen some talk about how in Python recursion is limited to 999, so I know that's the problem, but how can I rewrite the loop to avoid the error? The loop has potential to get pretty large so I don't think using the setrecursionlimit() function is a good idea.