23
23
"""
24
24
Functions to plot single station P-receiver functions as wiggle plots.
25
25
26
- Options to plot by receiver functions # vs time/depth, by back-azimuth vs
27
- time/depth or slowness vs time.
26
+ Options to plot by receiver functions # vs time/depth, by back-azimuth vs
27
+ time/depth or slowness vs time.
28
28
29
29
"""
30
30
41
41
def wiggle (stream1 , stream2 = None , sort = None , tmin = 0. , tmax = 30 , normalize = True ,
42
42
save = False , title = None , form = 'png' ):
43
43
"""
44
- Function to plot receiver function traces by index in stream. By default,
44
+ Function to plot receiver function traces by index in stream. By default,
45
45
only one stream is required, which produces a Figure with a single panel.
46
- Optionally, if a second stream is present, the Figure will contain two panels.
47
- The stream(s) can be sorted by stats attribute ``sort``, normalized, and
48
- the Figure can be saved as .eps.
46
+ Optionally, if a second stream is present, the Figure will contain two
47
+ panels. The stream(s) can be sorted by stats attribute ``sort``,
48
+ normalized, and the Figure can be saved as .eps.
49
49
50
50
Parameters
51
51
----------
@@ -59,16 +59,16 @@ def wiggle(stream1, stream2=None, sort=None, tmin=0., tmax=30, normalize=True,
59
59
xmax : float
60
60
Maximum x-axis value displayed in the Figure.
61
61
normalize : bool
62
- Whether or not to normalize the traces according to the max amplitude
62
+ Whether or not to normalize the traces according to the max amplitude
63
63
in ``stream1``
64
64
save : bool
65
- Whether or not to save the Figure
65
+ Whether or not to save the Figure
66
66
title : str
67
67
Title of plot
68
68
69
69
"""
70
70
71
- if sort :
71
+ if sort is not None :
72
72
try :
73
73
stream1 .traces .sort (key = lambda x : x .stats [sort ], reverse = False )
74
74
except :
@@ -150,10 +150,10 @@ def wiggle_bins(stream1, stream2=None, tr1=None, tr2=None,
150
150
norm = None , save = None , folder = None , show = True ):
151
151
"""
152
152
Function to plot receiver function according to either baz or
153
- slowness bins. By default,
154
- only one stream is required, which produces a Figure with a single panel.
155
- Optionally, if a second stream is present, the Figure will contain two panels.
156
- If the single trace arguments are present, they will be plotted at the top.
153
+ slowness bins. By default, only one stream is required, which produces a
154
+ Figure with a single panel. Optionally, if a second stream is present,
155
+ the Figure will contain two panels. If the single trace arguments are
156
+ present, they will be plotted at the top.
157
157
158
158
Parameters
159
159
----------
@@ -172,17 +172,21 @@ def wiggle_bins(stream1, stream2=None, tr1=None, tr2=None,
172
172
xtyp : str
173
173
Type of x-axis label (either 'time' or 'depth')
174
174
norm : float
175
- Normalization value applied to all traces. If not specified,
175
+ Normalization value applied to all traces. If not specified,
176
176
default amplitude ranges will be set.
177
177
save : str
178
- Filename of figure to be saved, including extension.
178
+ Filename of figure to be saved, including extension.
179
179
folder : str
180
180
Folder name where figure will be saved.
181
181
show : bool
182
182
Whether or not to show the figure upon execution.
183
183
184
184
"""
185
185
186
+ st1 = stream1 .copy ()
187
+ if stream2 is not None :
188
+ st2 = stream2 .copy ()
189
+
186
190
if not (btyp == 'baz' or btyp == 'slow' or btyp == 'dist' ):
187
191
raise (Exception ("Type has to be 'baz' or 'slow' or 'dist'" ))
188
192
if not (xtyp == 'time' or xtyp == 'depth' ):
@@ -192,10 +196,10 @@ def wiggle_bins(stream1, stream2=None, tr1=None, tr2=None,
192
196
193
197
# Figure out scaling here
194
198
if norm is not None :
195
- for tr in stream1 :
199
+ for tr in st1 :
196
200
tr .data /= norm
197
- if stream2 :
198
- for tr in stream2 :
201
+ if stream2 is not None :
202
+ for tr in st2 :
199
203
tr .data /= norm
200
204
if btyp == 'baz' :
201
205
maxval = 10.
@@ -218,21 +222,21 @@ def wiggle_bins(stream1, stream2=None, tr1=None, tr2=None,
218
222
maxvalT = maxval
219
223
220
224
# Time axis
221
- nn = stream1 [0 ].stats .npts
222
- sr = stream1 [0 ].stats .sampling_rate
225
+ nn = st1 [0 ].stats .npts
226
+ sr = st1 [0 ].stats .sampling_rate
223
227
time = np .arange (- nn / 2 , nn / 2 )/ sr
224
228
225
229
# Initialize figure
226
230
fig = plt .figure ()
227
231
plt .clf ()
228
232
229
- if stream2 and tr1 and tr2 :
233
+ if ( stream2 is not None ) and ( tr1 is not None ) and ( tr2 is not None ) :
230
234
# Get more control on subplots
231
235
ax1 = fig .add_axes ([0.1 , 0.825 , 0.3 , 0.05 ])
232
236
ax2 = fig .add_axes ([0.1 , 0.1 , 0.3 , 0.7 ])
233
237
ax3 = fig .add_axes ([0.45 , 0.825 , 0.3 , 0.05 ])
234
238
ax4 = fig .add_axes ([0.45 , 0.1 , 0.3 , 0.7 ])
235
- elif stream2 and not tr1 and not tr2 :
239
+ elif ( stream2 is not None ) and ( tr1 is None ) and ( tr2 is None ) :
236
240
ax1 = None
237
241
ax2 = fig .add_subplot (121 )
238
242
ax3 = None
@@ -258,10 +262,11 @@ def wiggle_bins(stream1, stream2=None, tr1=None, tr2=None,
258
262
# facecolor='red',
259
263
facecolor = 'k' ,
260
264
linewidth = 0 )
261
- ax1 .plot (time , tr1 .data ,
265
+ ax1 .plot (
266
+ time , tr1 .data ,
262
267
linewidth = 0.25 , c = 'k' )
263
268
ylim = np .max ([np .max (np .abs (tr1 .data )), np .max (np .abs (tr2 .data ))])
264
- if btyp == 'slow' :
269
+ if btyp == 'slow' :
265
270
ylimT = ylim / 2.
266
271
else :
267
272
ylimT = ylim
@@ -272,7 +277,7 @@ def wiggle_bins(stream1, stream2=None, tr1=None, tr2=None,
272
277
ax1 .set_xlim (trange [0 ], trange [1 ])
273
278
274
279
# Plot binned SV traces in back-azimuth on bottom left
275
- for tr in stream1 :
280
+ for tr in st1 :
276
281
277
282
# Define y axis
278
283
if btyp == 'baz' :
@@ -295,7 +300,8 @@ def wiggle_bins(stream1, stream2=None, tr1=None, tr2=None,
295
300
facecolor = 'k' ,
296
301
# facecolor='red',
297
302
linewidth = 0 )
298
- ax2 .plot (time , y + tr .data * maxval ,
303
+ ax2 .plot (
304
+ time , y + tr .data * maxval ,
299
305
linewidth = 0.25 , c = 'k' )
300
306
301
307
ax2 .set_xlim (trange [0 ], trange [1 ])
@@ -316,7 +322,7 @@ def wiggle_bins(stream1, stream2=None, tr1=None, tr2=None,
316
322
elif xtyp == 'depth' :
317
323
ax2 .set_xlabel ('Depth (km)' )
318
324
ax2 .grid (ls = ':' )
319
- if not ax1 :
325
+ if ( ax1 is None ) :
320
326
ax2 .set_title ('Radial' )
321
327
322
328
if ax3 :
@@ -334,7 +340,8 @@ def wiggle_bins(stream1, stream2=None, tr1=None, tr2=None,
334
340
facecolor = 'k' ,
335
341
# facecolor='red',
336
342
linewidth = 0 )
337
- ax3 .plot (time , tr2 .data ,
343
+ ax3 .plot (
344
+ time , tr2 .data ,
338
345
linewidth = 0.25 , c = 'k' )
339
346
ax3 .set_xlim (trange [0 ], trange [1 ])
340
347
ax3 .set_ylim (- 1. * ylimT , ylimT )
@@ -344,7 +351,7 @@ def wiggle_bins(stream1, stream2=None, tr1=None, tr2=None,
344
351
345
352
if ax4 :
346
353
# Plot binned SH traces in back-azimuth on bottom right
347
- for tr in stream2 :
354
+ for tr in st2 :
348
355
349
356
# Define y axis
350
357
if btyp == 'baz' :
@@ -367,7 +374,8 @@ def wiggle_bins(stream1, stream2=None, tr1=None, tr2=None,
367
374
# facecolor='red',
368
375
facecolor = 'k' ,
369
376
linewidth = 0 )
370
- ax4 .plot (time , y + tr .data * maxvalT ,
377
+ ax4 .plot (
378
+ time , y + tr .data * maxvalT ,
371
379
linewidth = 0.25 , c = 'k' )
372
380
373
381
ax4 .set_xlim (trange [0 ], trange [1 ])
@@ -386,15 +394,15 @@ def wiggle_bins(stream1, stream2=None, tr1=None, tr2=None,
386
394
ax4 .set_xlabel ('Depth (km)' )
387
395
ax4 .set_yticklabels ([])
388
396
ax4 .grid (ls = ':' )
389
- if not ax3 :
397
+ if ( ax3 is None ) :
390
398
ax4 .set_title ('Transverse' )
391
399
392
400
if save :
393
401
if folder is not None :
394
- plt .savefig (folder + '/' + stream1 [0 ].stats .station +
402
+ plt .savefig (folder + '/' + st1 [0 ].stats .station +
395
403
'.' + save , format = save .split ('.' )[- 1 ], dpi = 300 )
396
404
else :
397
- plt .savefig ('RF_PLOTS/' + stream1 [0 ].stats .station +
405
+ plt .savefig ('RF_PLOTS/' + st1 [0 ].stats .station +
398
406
'.' + save , format = save .split ('.' )[- 1 ], dpi = 300 )
399
407
400
408
if show :
@@ -412,14 +420,16 @@ def wiggle_single_event(rfdata, filt=None, pre_filt=None, trange=None):
412
420
taxis = np .arange (- nn / 2. , nn / 2. )/ sr
413
421
414
422
if pre_filt :
415
- lqtcopy .filter ('bandpass' , freqmin = pre_filt [0 ],
423
+ lqtcopy .filter (
424
+ 'bandpass' , freqmin = pre_filt [0 ],
416
425
freqmax = pre_filt [1 ], corners = 2 , zerophase = True )
417
426
418
427
if filt :
419
- rfcopy .filter ('bandpass' , freqmin = filt [0 ],
428
+ rfcopy .filter (
429
+ 'bandpass' , freqmin = filt [0 ],
420
430
freqmax = filt [1 ], corners = 2 , zerophase = True )
421
431
422
- fig , (ax1 , ax2 , ax3 , ax4 ) = plt .subplots (4 ,1 , figsize = (7 ,5 ))
432
+ fig , (ax1 , ax2 , ax3 , ax4 ) = plt .subplots (4 , 1 , figsize = (7 , 5 ))
423
433
424
434
ax1 .plot (taxis , lqtcopy [0 ], label = lqtcopy [0 ].stats .channel , lw = 1 )
425
435
ax2 .plot (taxis , lqtcopy [1 ], label = lqtcopy [0 ].stats .channel , lw = 1 )
@@ -442,7 +452,7 @@ def wiggle_single_event(rfdata, filt=None, pre_filt=None, trange=None):
442
452
ax4 .legend ()
443
453
plt .suptitle (
444
454
'AZ corr: {0:.1f}; BAZ: {1:.1f}\n SNR: {2:.1f}; CC: {3:.1f}' .format (
445
- rfdata .sta .azcorr , rfdata .meta .baz ,
455
+ rfdata .sta .azcorr , rfdata .meta .baz ,
446
456
rfdata .meta .snr , rfdata .meta .cc ))
447
457
448
458
plt .show ()
0 commit comments