Source code for gmprocess.waveform_processing.zero_pad
"""Module for zero pad processing step."""importinspectimportnumpyasnpfromgmprocess.waveform_processing.processing_stepimportprocessing_stepfromgmprocess.waveform_processing.filteringimporthighpass_filter
[docs]@processing_stepdefzero_pad(st,length="fhp",config=None):"""Add zero pads to streams. Args: st (StationStream): Stream of data. length (float, str): The length (in sec) to pad with zeros before and after the trace, or "fhp" to compute the zero pad length from the filter order and the highpass corner as `1.5 * filter_order / flc`. config (dict): Configuration dictionary (or None). See get_config(). Returns: StationStream: Streams with the zero padding applied. """ifnotst.passed:returnstuse_fhp=Falseiflength=="fhp":use_fhp=Truepsteps=list(config["processing"])filter_order=None# Getting filter order is a bit complicated. First check the config to see if it# is set there, and if not get the default value from the filter function.forpstepinpsteps:if(("highpass_filter"inpstep)and(pstep["highpass_filter"]isnotNone)and("filter_order"inpstep["highpass_filter"])):filter_order=pstep["highpass_filter"]["filter_order"]iffilter_orderisNone:# If filter order is not set in config, then it will use the default# argument value.hp_sig=inspect.signature(highpass_filter)forfunc_arg,valinhp_sig.parameters.items():iffunc_arg=="filter_order":filter_order=val.default# Need to use a consistent fhp for all traces in stream so that the number of# points is constant.fhps=[]fortrinst:freq_dict=tr.get_parameter("corner_frequencies")fhps.append(freq_dict["highpass"])fhp=np.min(fhps)fortrinst:iftr.passed:ifuse_fhp:# Need to hand off half the length becasue it is added to both sides# (0.75 instead of 1.5, equation from Converse and Brady, 1992)length=0.75*filter_order/fhptr.zero_pad(length=length)returnst
[docs]@processing_stepdefstrip_zero_pad(st,config=None):"""Remove zero pads from streams. Args: st (StationStream): Stream of data. config (dict): Configuration dictionary (or None). See get_config(). Returns: StationStream: Streams with the zero padding removed. """ifnotst.passed:returnstfortrinst:tr.strip_zero_pad()returnst