-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_waveforms.py
More file actions
67 lines (53 loc) · 2.24 KB
/
Copy pathplot_waveforms.py
File metadata and controls
67 lines (53 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
"""Render miniSEED waveforms to a PNG (one panel per channel)."""
import argparse
from datetime import datetime, timezone
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from obspy import read, UTCDateTime
def plot(infile, outfile, origin=None):
st = read(infile)
st.merge(method=1) # stitch contiguous records, fill gaps with masked arrays
st.sort(["channel"])
n = len(st)
fig, axes = plt.subplots(n, 1, figsize=(12, 2.2 * n + 1), sharex=True)
if n == 1:
axes = [axes]
origin_utc = None
if origin is not None:
origin_utc = UTCDateTime(origin if isinstance(origin, str)
else origin.astimezone(timezone.utc).replace(tzinfo=None).isoformat())
for ax, tr in zip(axes, st):
times = [(tr.stats.starttime + t).datetime for t in
(tr.times())]
ax.plot(times, tr.data, lw=0.6, color="#1a1a1a")
ax.set_ylabel(tr.id.split(".")[-1], rotation=0, ha="right", va="center", fontsize=11)
ax.grid(True, alpha=0.25)
ax.margins(x=0)
if origin_utc is not None:
ax.axvline(origin_utc.datetime, color="#cc2222", lw=1.0, ls="--")
axes[-1].xaxis.set_major_formatter(mdates.DateFormatter("%H:%M:%S"))
fig.autofmt_xdate()
title = f"{st[0].id.rsplit('.', 1)[0]} | {st[0].stats.starttime.strftime('%Y-%m-%d %H:%M:%S')} UTC"
if origin_utc is not None:
title += f" | origin {origin_utc.strftime('%H:%M:%S')} UTC (red)"
fig.suptitle(title, fontsize=12)
fig.tight_layout(rect=[0, 0, 1, 0.98])
fig.savefig(outfile, dpi=130)
plt.close(fig)
return outfile
def main():
ap = argparse.ArgumentParser(description="Plot miniSEED waveforms to PNG")
ap.add_argument("--input", required=True)
ap.add_argument("--out", help="output PNG (default: alongside input)")
ap.add_argument("--origin", help="origin time UTC to mark, e.g. 2026-06-13T17:28:12")
args = ap.parse_args()
st = read(args.input)
print(st.__str__(extended=True))
out = args.out or (args.input.rsplit(".", 1)[0] + ".png")
plot(args.input, out, origin=args.origin)
print(f"plot -> {out}")
if __name__ == "__main__":
main()