Skip to content

Commit c0f1867

Browse files
committed
Updated window and section plotting
1 parent 791fbdf commit c0f1867

File tree

3 files changed

+43
-25
lines changed

3 files changed

+43
-25
lines changed

src/obsplotlib/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
except PackageNotFoundError:
66
# If the package is not installed, don't add __version__
77
pass
8+
9+

src/obsplotlib/section.py

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def section(streams: tp.List[obspy.Stream], *args,
2121
align: bool = False,
2222
absmax: float | None = None,
2323
window: bool = False,
24+
plot_geometry: bool = True,
25+
plot_amplitudes: bool = True,
2426
**kwargs):
2527
"""Plots a section of seismograms of given stream or stream set. The
2628
stream(s) need(s) to contain traces which have the distance parameter
@@ -153,9 +155,10 @@ def section(streams: tp.List[obspy.Stream], *args,
153155
maxs.append(streammaxs)
154156

155157
if absmax is None:
156-
absmax = np.max(maxs)
158+
absmax = np.max(np.max(maxs))
157159

158160
# Plot overall max amplitude label
161+
print(maxs)
159162
plot_label(ax, f'max|u|: {absmax:.5g} m',
160163
fontsize='small', box=False, dist=0.0, location=4)
161164

@@ -169,11 +172,13 @@ def section(streams: tp.List[obspy.Stream], *args,
169172
# Define ylabels on the left axis to station info
170173
ylabels = []
171174
for tr in pstreams[0]:
172-
ylabel = f"{tr.stats.network}.{tr.stats.station}\n" \
173-
f"D:{tr.stats.distance:>6.2f}"
175+
ylabel = f"{tr.stats.network}.{tr.stats.station}"
176+
177+
if plot_geometry:
178+
f"\nD:{tr.stats.distance:>6.2f}"
174179

175-
if hasattr(tr.stats, 'azimuth'):
176-
ylabel += f"\nAz: {tr.stats.azimuth:>5.1f}"
180+
if hasattr(tr.stats, 'azimuth'):
181+
ylabel += f"\nAz: {tr.stats.azimuth:>5.1f}"
177182

178183
ylabels.append(ylabel)
179184

@@ -187,29 +192,36 @@ def section(streams: tp.List[obspy.Stream], *args,
187192
# Set y values on the right axis to max values
188193
ax2 = ax.secondary_yaxis("right")
189194

190-
# Make ticks contain the absolute max value of each trace
191-
ticks = []
192-
for _i in range(Ntraces):
193-
label = ""
194-
for _j in range(Nstreams):
195-
label += f"{labels[_j][0].upper()}:{maxs[_j][_i]:>10.4g}"
196-
# Add newline if not last trace
197-
if Nstreams > 1 and _j != Nstreams - 1:
198-
label += "\n"
199-
ticks.append(label)
200-
201-
# Set tick labels
202-
ax2.set_yticks(y, ticks,
203-
verticalalignment='center',
204-
horizontalalignment='left',
205-
fontsize='small')
206-
207-
# Remove spine
195+
# Remove spine
208196
ax2.spines.right.set_visible(False)
209197

210198
# Remove ticks
211199
ax2.tick_params(left=False, right=False)
212200

201+
if plot_amplitudes:
202+
203+
# Make ticks contain the absolute max value of each trace
204+
ticks = []
205+
for _i in range(Ntraces):
206+
label = ""
207+
for _j in range(Nstreams):
208+
label += f"{labels[_j][0].upper()}:{maxs[_j][_i]:>10.4g}"
209+
# Add newline if not last trace
210+
if Nstreams > 1 and _j != Nstreams - 1:
211+
label += "\n"
212+
ticks.append(label)
213+
214+
# Set tick labels
215+
ax2.set_yticks(y, ticks,
216+
verticalalignment='center',
217+
horizontalalignment='left',
218+
fontsize='small')
219+
220+
else:
221+
222+
# Remove ticks
223+
ax2.tick_params(left=False, right=False, labelright=False)
224+
213225
# Set time arguments for the plotting
214226
if origin_time is not None:
215227
time_args = dict(type='relative', reftime=origin_time)

src/obsplotlib/window.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ def __init__(self, tr: obspy.Trace, *args, **kwargs):
2626
and make measurements that way."""
2727
super().__init__(*args, **kwargs)
2828

29-
self.startidx = self.get_index(tr, self.starttime)
30-
self.endidx = self.get_index(tr, self.endtime)
29+
if 'startidx' in kwargs:
30+
self.startidx = kwargs['startidx']
31+
self.endidx = kwargs['endidx']
32+
else:
33+
self.startidx = self.get_index(tr, self.starttime)
34+
self.endidx = self.get_index(tr, self.endtime)
3135

3236
# Correct the starttime to the index
3337
self.starttime = tr.stats.starttime \

0 commit comments

Comments
 (0)