@@ -119,14 +119,15 @@ class Orient(object):
119
119
120
120
"""
121
121
122
- def __init__ (self , sta ):
122
+ def __init__ (self , sta , zcomp = 'Z' ):
123
123
124
124
# Attributes from parameters
125
125
self .sta = sta
126
126
127
127
# Initialize meta and data objects as None
128
128
self .meta = None
129
129
self .data = None
130
+ self .zcomp = zcomp
130
131
131
132
def add_event (self , event , gacmin = None , gacmax = None ,
132
133
depmax = 1000. , returned = False ):
@@ -193,6 +194,9 @@ def download_data(self, client, stdata=[], ndval=np.nan, new_sr=None,
193
194
:class:`~obspy.core.UTCDateTime` object.
194
195
returned : bool
195
196
Whether or not to return the ``accept`` attribute
197
+ zcomp : str
198
+ Character representing the vertical component. Should be
199
+ a single character :str:. Default Z
196
200
197
201
Returns
198
202
-------
@@ -228,14 +232,19 @@ def download_data(self, client, stdata=[], ndval=np.nan, new_sr=None,
228
232
# Download data
229
233
err , stream = io .download_data (
230
234
client = client , sta = self .sta , start = tstart , end = tend ,
231
- stdata = stdata , ndval = ndval , new_sr = new_sr ,
235
+ stdata = stdata , ndval = ndval , new_sr = new_sr , zcomp = self . zcomp ,
232
236
verbose = verbose )
233
237
238
+ if err or stream is None :
239
+ print ("* Waveform Request Failed...Skipping" )
240
+ self .meta .accept = False
241
+ return self .meta .accept
242
+
234
243
# Store as attributes with traces in dictionary
235
244
try :
236
245
trE = stream .select (component = 'E' )[0 ]
237
246
trN = stream .select (component = 'N' )[0 ]
238
- trZ = stream .select (component = 'Z' )[0 ]
247
+ trZ = stream .select (component = self . zcomp )[0 ]
239
248
self .data = Stream (traces = [trZ , trN , trE ])
240
249
241
250
# Filter Traces and resample
@@ -246,26 +255,24 @@ def download_data(self, client, stdata=[], ndval=np.nan, new_sr=None,
246
255
247
256
# If there is no ZNE, perhaps there is Z12?
248
257
except :
258
+ tr1 = stream .select (component = '1' )[0 ]
259
+ tr2 = stream .select (component = '2' )[0 ]
260
+ trZ = stream .select (component = self .zcomp )[0 ]
261
+ self .data = Stream (traces = [trZ , tr1 , tr2 ])
249
262
250
- try :
251
- tr1 = stream .select (component = '1' )[0 ]
252
- tr2 = stream .select (component = '2' )[0 ]
253
- trZ = stream .select (component = 'Z' )[0 ]
254
- self .data = Stream (traces = [trZ , tr1 , tr2 ])
255
-
256
- # Filter Traces and resample
257
- if new_sr :
258
- self .data .filter ('lowpass' , freq = 0.5 * new_sr ,
259
- corners = 2 , zerophase = True )
260
- self .data .resample (new_sr )
261
-
262
- if not np .sum ([np .std (tr .data ) for tr in self .data ]) > 0. :
263
- print ('Error: Data are all zeros' )
264
- self .meta .accept = False
263
+ # Filter Traces and resample
264
+ if new_sr :
265
+ self .data .filter ('lowpass' , freq = 0.5 * new_sr ,
266
+ corners = 2 , zerophase = True )
267
+ self .data .resample (new_sr )
265
268
266
- except :
269
+ if not np .sum ([np .std (tr .data ) for tr in self .data ]) > 0. :
270
+ print ('Error: Data are all zeros' )
267
271
self .meta .accept = False
268
272
273
+ # except:
274
+ # self.meta.accept = False
275
+
269
276
if returned :
270
277
return self .meta .accept
271
278
@@ -311,9 +318,9 @@ class BNG(Orient):
311
318
312
319
"""
313
320
314
- def __init__ (self , sta ):
321
+ def __init__ (self , sta , zcomp = 'Z' ):
315
322
316
- Orient .__init__ (self , sta )
323
+ Orient .__init__ (self , sta , zcomp = zcomp )
317
324
318
325
319
326
def calc (self , dphi , dts , tt , bp = None , showplot = False ):
@@ -366,21 +373,23 @@ def calc(self, dphi, dts, tt, bp=None, showplot=False):
366
373
test_sets = {
367
374
'ZNE' :{'Z' , 'N' , 'E' },
368
375
'Z12' :{'Z' , '1' , '2' },
369
- 'Z23' :{'Z' , '2' , '3' },
376
+ 'Z23' :{'Z' , '2' , '3' },
377
+ '312' :{'3' , '1' , '2' },
370
378
'123' :{'1' , '2' , '3' } # probably should raise an exception if this is the case,
371
379
} # as no correction is estimated for the vertical component
372
380
for test_key in test_sets :
373
381
test_set = test_sets [test_key ]
374
382
if test_set .issubset (set (comps_id )): # use sets to avoid sorting complications
375
383
comps_codes = list (test_key )
376
384
break
377
-
385
+
378
386
#-- temporarily modify channel codes, assuming that N/E are not oriented properly
379
387
channel_code_prefix = stream [0 ].stats .channel [:2 ] # prefix should be the same for all
380
388
# 3 components by now
381
389
stream .select (component = comps_codes [1 ])[0 ].stats .channel = channel_code_prefix + '1'
382
390
stream .select (component = comps_codes [2 ])[0 ].stats .channel = channel_code_prefix + '2'
383
- stream .select (component = comps_codes [0 ])[0 ].stats .channel = channel_code_prefix + 'Z'
391
+ stream .select (component = comps_codes [0 ])[0 ].stats .channel = channel_code_prefix + self .zcomp .upper ()
392
+
384
393
385
394
# Filter if specified
386
395
if bp :
@@ -396,8 +405,8 @@ def calc(self, dphi, dts, tt, bp=None, showplot=False):
396
405
# Define signal and noise
397
406
tr1 = stdata .select (component = '1' )[0 ].copy ()
398
407
tr2 = stdata .select (component = '2' )[0 ].copy ()
399
- trZ = stdata .select (component = 'Z' )[0 ].copy ()
400
- ntrZ = stnoise .select (component = 'Z' )[0 ].copy ()
408
+ trZ = stdata .select (component = self . zcomp . upper () )[0 ].copy ()
409
+ ntrZ = stnoise .select (component = self . zcomp . upper () )[0 ].copy ()
401
410
402
411
# Calculate and store SNR as attribute
403
412
self .meta .snr = 10. * np .log10 (
@@ -517,9 +526,9 @@ class DL(Orient):
517
526
518
527
"""
519
528
520
- def __init__ (self , sta ):
529
+ def __init__ (self , sta , zcomp = 'Z' ):
521
530
522
- Orient .__init__ (self , sta )
531
+ Orient .__init__ (self , sta , zcomp = zcomp )
523
532
524
533
525
534
def calc (self , showplot = False ):
@@ -609,15 +618,15 @@ def calc(self, showplot=False):
609
618
610
619
# R1 path
611
620
R1phi [k ], R1cc [k ] = utils .DLcalc (
612
- stream . copy () , item [0 ], item [1 ],
621
+ stream , item [0 ], item [1 ],
613
622
item [2 ], self .meta .epi_dist , self .meta .baz , Ray1 ,
614
- winlen = item [3 ], ptype = 0 )
623
+ winlen = item [3 ], ptype = 0 , zcomp = self . zcomp )
615
624
616
625
# R2 path
617
626
R2phi [k ], R2cc [k ] = utils .DLcalc (
618
- stream . copy () , item [0 ], item [1 ],
627
+ stream , item [0 ], item [1 ],
619
628
item [2 ], dist2 , baz2 , Ray2 ,
620
- winlen = item [4 ], ptype = 0 )
629
+ winlen = item [4 ], ptype = 0 , zcomp = self . zcomp )
621
630
622
631
# Store azimuths and CC values as attributes
623
632
self .meta .R1phi = R1phi
0 commit comments