I am working on an program to identify significant frequencies in a power density spectrum. I have found a list of significant peaks in a automated way. But now I want to look at them visually and add / delete peaks from a plot using fig.canvas.mpl_connect('key_press_event', ontype) (http://matplotlib.org/users/event_handling.html)
As I want to add multiple peaks I want to update the used list. Though I get a UnboundLocalError: local variable 'frequencyLIST' referenced before assignment error.
def interactiveMethod(frequency,PDS, frequencyLIST,figureName):
#frequency and PDS is the input list of data, frequencyLIST is my found list of
#frequencies and figureName is the figure I previously made which I want to use the
#event on.
def ontype(event):
if event.key == 'a':
#Getting the event xdata
x = event.xdata
frequencyCut = frequency[np.where((frequency > x - 2) & (frequency < x + 2))]
PDSCut = PDS[np.where((frequency > x - 2) & (frequency < x + 2))]
#Find the maximum PDS, as this corresponds to a peak
PDSMax = np.max(PDSCut)
frequencyMax = frequencyCut[np.where(PDSCut == PDSMax)][0]
#Updating the new list using the found frequency
frequencyLIST = np.append(frequencyLIST,frequencyMax)
figureName.canvas.mpl_connect('key_press_event',ontype)
I have no idea where I should put this frequencyLIST so I can update it.
python version: 2.7.3 32bit
matplotlib version: 1.3.0
numpy version: 1.7.1
ubuntu 13.1
I also have enthough canopy (not sure which version)