@@ -399,6 +399,7 @@ def _build_spectrum(config, trace):
399
399
400
400
def _build_uniform_weight (spec ):
401
401
weight = spec .copy ()
402
+ weight .snratio = None
402
403
weight .data = np .ones_like (weight .data )
403
404
weight .data_log = np .ones_like (weight .data_log )
404
405
return weight
@@ -420,8 +421,8 @@ def _build_weight_from_frequency(config, spec):
420
421
def _build_weight_from_ratio (spec , specnoise , smooth_width_decades ):
421
422
weight = spec .copy ()
422
423
weight .data /= specnoise .data
423
- # save data to raw_data
424
- weight .data_raw = weight .data .copy ()
424
+ # save signal-to-noise ratio before log10, smoothing, and normalization
425
+ weight .snratio = weight .data .copy ()
425
426
# The inversion is done in magnitude units,
426
427
# so let's take log10 of weight
427
428
weight .data = np .log10 (weight .data )
@@ -513,14 +514,17 @@ def _build_H(spec_st, specnoise_st=None, vertical_channel_codes=None,
513
514
514
515
def _check_spectral_sn_ratio (config , spec , specnoise ):
515
516
weight = _build_weight_from_noise (config , spec , specnoise )
517
+ # if no noise window is available, snratio is not computed
518
+ if weight .snratio is None :
519
+ return
516
520
if config .spectral_sn_freq_range is not None :
517
521
sn_fmin , sn_fmax = config .spectral_sn_freq_range
518
522
freqs = weight .get_freq ()
519
523
idx = np .where ((sn_fmin <= freqs )* (freqs <= sn_fmax ))
520
524
else :
521
- idx = range (len (weight .data_raw ))
525
+ idx = range (len (weight .snratio ))
522
526
spectral_snratio = \
523
- weight .data_raw [idx ].sum ()/ len (weight .data_raw [idx ])
527
+ weight .snratio [idx ].sum ()/ len (weight .snratio [idx ])
524
528
spec .stats .spectral_snratio = spectral_snratio
525
529
spec_id = spec .get_id ()
526
530
logger .info (
0 commit comments