Source code for gmprocess.waveform_processing.clipping.clipping_check
"""Module for the clipping detection method."""importnumpyasnpfromobspy.geodetics.baseimportgps2dist_azimuthfromgmprocess.waveform_processing.clipping.clipping_annimportclipNetfromgmprocess.waveform_processing.clipping.max_ampimportMaxAmpfromgmprocess.waveform_processing.clipping.histogramimportHistogramfromgmprocess.waveform_processing.clipping.pingimportPingfromgmprocess.waveform_processing.processing_stepimportprocessing_stepM_TO_KM=1.0/1000
[docs]@processing_stepdefcheck_clipping(st,event,threshold=0.2,config=None):"""Apply clipping check. Lower thresholds will pass fewer streams but will give less false negatives (i.e., streams in which clipping actually occurred but were missed). Args: st (gmprocess.core.stationstream.StationStream): Trace of data. event (gmprocess.utils.scalar_event.ScalarEvent): ScalarEvent object. threshold (float): Threshold probability. config (dict): Configuration dictionary (or None). See get_config(). Returns: StationStream: With clipping check applied. """# Don't bother with test for strong motion instrumentschan_code=st[0].stats.channelifchan_code[1]=="N":returnst# Don't bother with test if it has already failedifnotst.passed:returnstevent_mag=event.magnitudeevent_lon=event.longitudeevent_lat=event.latitudedist=(gps2dist_azimuth(lat1=event_lat,lon1=event_lon,lat2=st[0].stats["coordinates"]["latitude"],lon2=st[0].stats["coordinates"]["longitude"],)[0]*M_TO_KM)# Clip mag/dist to range of training datasetevent_mag=np.clip(event_mag,4.0,8.8)dist=np.clip(dist,0.0,445.0)clip_nnet=clipNet()max_amp_method=MaxAmp(st,max_amp_thresh=6e6)hist_method=Histogram(st)ping_method=Ping(st)inputs=[event_mag,dist,max_amp_method.is_clipped,hist_method.is_clipped,ping_method.is_clipped,]prob_clip=clip_nnet.evaluate(inputs)[0][0]fortrinst:tr.set_parameter("clipping_probability",{"probability":prob_clip})ifprob_clip>=threshold:tr.fail("Failed clipping check.")returnst