Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plot psd instead of normal waveform #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions seedlink_plotter/seedlink_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from matplotlib.ticker import MaxNLocator
from matplotlib.patheffects import withStroke
import matplotlib.pyplot as plt
from matplotlib.mlab import detrend_linear
from obspy.core import UTCDateTime
from obspy.core.event import Catalog
from obspy.fdsn import Client
Expand Down Expand Up @@ -112,7 +113,7 @@ def plot_graph(self):
try:
stream.merge()
stream.trim(starttime=self.start_time, endtime=self.stop_time,
pad=True, nearest_sample=False)
pad=False, nearest_sample=False)
logging.info(str(stream.split()))
if not stream:
raise Exception("Empty stream for plotting")
Expand Down Expand Up @@ -159,10 +160,28 @@ def plot_lines(self, stream):
data = np.zeros(2)
stream.append(Trace(data=data, header=header))
stream.sort()
self.figure.clear()
#self.figure.clear()
fig = self.figure
stream.plot(fig=fig, method="fast", draw=False, equal_scale=False,
size=(self.args.x_size, self.args.y_size), title="", color='Blue', tick_format=self.args.tick_format, number_of_ticks=self.args.time_tick_nb)
for ax in fig.axes:
ax.lines = ax.lines[-10:]
for line, alpha in zip(ax.lines, np.linspace(0, 1, len(ax.lines)+2)[1:-1]):
line.set_alpha(alpha)
line.set_lw(line.get_lw() * alpha)
if not stream:
return
for i, tr in enumerate(stream):
ax = fig.add_subplot(len(stream), 1, i+1)
if len(tr) == 0:
continue
nfft = int(len(tr) * 0.4)
logging.debug("nfft:", str(nfft))
overlap = 0.80
noverlap = int(nfft * overlap)
logging.debug(str(tr))
ax.psd(tr.data, NFFT=nfft, Fs=tr.stats.sampling_rate,
detrend=detrend_linear, noverlap=noverlap, color="b")
#ax.set_xscale('log')
ax.set_xlim(10, 70)
fig.subplots_adjust(left=0, right=1, top=1, bottom=0)
bbox = dict(boxstyle="round", fc="w", alpha=0.8)
path_effects = [withStroke(linewidth=4, foreground="w")]
Expand All @@ -187,8 +206,8 @@ def plot_lines(self, stream):
plt.setp(xlabels, visible=False)
locator = MaxNLocator(nbins=4, prune="both")
ax.yaxis.set_major_locator(locator)
ax.yaxis.grid(False)
ax.grid(True, axis="x")
ax.grid(True, axis="y")
for ax in fig.axes[::2]:
ax.set_axis_bgcolor("0.8")
fig.canvas.draw()
Expand Down