0

I am attempting to apply an assortment of filters to a seismogram, after the seismogram is plotted. So, if I plot the original seismogram, and I click the button "Apply Bandpass Filter", it'll apply the bandpass filter automatically to the trace that is currently on the screen.

My code (below) is currently programmed so that I must delete a figure before being able to successfully click one of the other buttons that I created. Do you have any suggestions for how I could make the above edits to my code? I'll spare you the lines creating the GUI, as they won't affect what I'm trying to accomplish. The functions defined below will plot the seismogram, the seismogram with a high-pass filter, the seismogram w/ a bandpass filter, or the spectrogram. Thanks for your help.

#!/usr/bin/env python
from Tkinter import *
from obspy.core import read
import obspy.signal
import matplotlib.pyplot as plt
import numpy as np
import pylab
import math
   class Plot_Seismogram:
    def __init__(self, parent):
 .....
# Widget design that I omitted
# Quit Function
    def quit(self, event=None):
        self.master.quit()

    # Seismogram Function
    def plot_seis(self, event=None):
        event = read(self.List1.get(self.List1.curselection()[0]))
        event.plot()
    # BandPass Filter Function
    def highpass_filter(self, event=None):
        event_filter = read(self.List1.get(self.List1.curselection()[0]))
        event_filter.filter('highpass', freq=1.0, corners=1, zerophase=True)
        event_filter.plot()
    def bandpass_filter(self, event=None):
        event_filter = read(self.List1.get(self.List1.curselection()[0]))
        event_filter.filter('bandpass', freqmin=2, freqmax=5, corners=4, zerophase=False)
        event_filter.plot()
    # Spectrogram Function
    def plot_spectro(self, event=None):
        event_spect = read(self.List1.get(self.List1.curselection()[0]))
        event_spect.spectrogram(log=False, )

root = Tk()
Plot_Seismo = Plot_Seismogram(root)
root.mainloop()
martineau
  • 119,623
  • 25
  • 170
  • 301
geeb.24
  • 527
  • 2
  • 7
  • 25
  • Just to clarify: Are you able to plot / display one of your plots? – albert Aug 29 '15 at 20:13
  • Hi Albert, yes. I am able to plot and display one of my plots. What I'd love to do is to first plot the seismogram, then click "Apply bandpass filter", and the seismogram is updated in that same figure without having to close the figure and then click "Apply Bandpass Filter". Thanks. – geeb.24 Aug 29 '15 at 20:16
  • You can think about putting the different plots (original and filtered data) into several widgets and try to hide resp. show them which should look like 'applying filters live'. There a several methods to do so, depending on your geometry manager, which are summarized in this [answer](http://stackoverflow.com/a/10268076/3991125). – albert Aug 29 '15 at 20:34

0 Answers0