![]() |
Value Error when Trying to Plot Filtered Waveforms - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Value Error when Trying to Plot Filtered Waveforms (/thread-42093.html) |
Value Error when Trying to Plot Filtered Waveforms - mkohler - May-09-2024 Howdy yall. I am trying to apply a highpass filter to my waveform from a specific earthquake but I cant seem to understand the error that I get when it says that "x and y must have same first dimension." Could anyone explain to me what I'm doing wrong and how I can try to fix it? Here's my code. import numpy as np import matplotlib.pyplot as plt import obspy # Read the seismogram #st = obspy.read(r"C:\Users\maddi\Spring Catch-Up\Waveform mseed\Spring Catch-UpGroundMotionM7.0Raw.mseed") st = client.get_waveforms("II","ERM","00","BHZ", UTCDateTime('2008-07-19 02:39:47'), UTCDateTime('2008-07-19 02:46:00')) # There is only one trace in the Stream object, let's work on that trace... tr = st[0] # Filtering with a lowpass on a copy of the original Trace tr_filt = tr.copy() tr_filt.filter('highpass', freq=1.0, corners=2, zerophase=True) # Now let's plot the raw and filtered data... t = np.arange(0, tr.stats.npts / tr.stats.sampling_rate, tr.stats.delta) plt.subplot(211) plt.plot(t, tr.data) plt.ylabel('Raw Data') plt.subplot(212) plt.plot(t, tr_filt.data, 'k') plt.ylabel('highpassed Data') plt.xlabel('Time [s]') plt.suptitle(tr.stats.starttime) plt.show()
RE: Value Error when Trying to Plot Filtered Waveforms - deanhystad - May-09-2024 The error message is pretty clear. The line that raises this error is.plt.plot(t, tr.data)So it looks like t and tr.data are not the same size. That points to this line being wrong. t = np.arange(0, tr.stats.npts / tr.stats.sampling_rate, tr.stats.delta)I would expect this to be: t = np.arange(0, tr.stats.npts * tr.stats.delta, tr.stats.delta)Print out the values for tr.stats.delta and tr.stats.sampling_rate. I don't think tr.stats.delta * tr.stats.sampling_rate == 1. The error is in your data, and a bad assumption in your program. Another, less likely possibility is that tr.stats.npts != len(tr.data). |