当前位置: 首页>>代码示例>>Python>>正文


Python Stream.append方法代码示例

本文整理汇总了Python中obspy.core.Stream.append方法的典型用法代码示例。如果您正苦于以下问题:Python Stream.append方法的具体用法?Python Stream.append怎么用?Python Stream.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在obspy.core.Stream的用法示例。


在下文中一共展示了Stream.append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: split_traces

# 需要导入模块: from obspy.core import Stream [as 别名]
# 或者: from obspy.core.Stream import append [as 别名]
def split_traces(s, length_in_sec, min_len, verbose, ofid):
    """
    Split an ObsPy stream object with multiple traces into a stream with traces of a predefined
    maximum length.
    """

    s_new = Stream()

    # - loop through traces ------------------------------------------------------------------------

    for k in np.arange(len(s)):

        # - set initial start time
        start = s[k].stats.starttime

        # - march through the trace until the endtime is reached
        while start < s[k].stats.endtime - min_len:
            s_copy = s[k].copy()
            s_copy.trim(start, start + length_in_sec - 1 / (s[k].stats.sampling_rate))
            s_new.append(s_copy)
            del s_copy
            collect()
            start += length_in_sec

    return s_new
开发者ID:echolite,项目名称:ANTS,代码行数:27,代码来源:processing.py

示例2: write_adjoint_traces

# 需要导入模块: from obspy.core import Stream [as 别名]
# 或者: from obspy.core.Stream import append [as 别名]
    def write_adjoint_traces(self, path, syn, dat, channel):
        """ Computes adjoint traces from observed and synthetic traces
        """
        nt, dt, _ = self.get_time_scheme(syn)
        nr, _ = self.get_network_size(syn)

        Del = np.loadtxt(path +'/'+ '../../delta_syn_ij')
        rsd = np.loadtxt(path +'/'+ '../../rsd_ij')

        # initialize trace arrays
        adj = Stream()
        for i in range(nr):
            adj.append(Trace(
                data=np.zeros(nt, dtype='float32'),
                header=syn[i].stats))

        # generate adjoint traces
        for i in range(nr):
            for j in range(i):
                si = syn[i].data
                sj = syn[j].data

                adj[i].data += rsd[i,j] * \
                               self.adjoint_dd(si, sj, +Del[i,j], nt, dt)
                adj[j].data -= rsd[i,j] * \
                               self.adjoint_dd(sj, si, -Del[i,j], nt, dt)


        # optional weighting
        adj = self.apply_weights(adj)

        # write adjoint traces
        self.writer(adj, path, channel)
开发者ID:PrincetonUniversity,项目名称:seisflows,代码行数:35,代码来源:double_difference.py

示例3: set_dummy

# 需要导入模块: from obspy.core import Stream [as 别名]
# 或者: from obspy.core.Stream import append [as 别名]
 def set_dummy(self):
     """
     Create a dummy stream object. This is used by the sm_gui.py script 
     in case no data is found.
     """
     smdict = {}
     smdict['lat'] = 0.
     smdict['lon'] = 0.
     smdict['site'] = 'None'
     smdict['site-name'] = 'None'
     smdict['instrument'] = 'None'
     smdict['eventtime'] = UTCDateTime(1970, 1, 1, 0, 0, 0, 0) 
     smdict['hypodep'] = 0.
     smdict['centdep'] = 0.
     smdict['lilax'] = 0.
     smdict['compdir'] = 0.
     smdict['epicdist'] = 0.
     smdict['prepend'] = 0.
     smdict['append'] = 0.
     smdict['Ml'] = 0.
     smdict['Ms'] = 0.
     smdict['Mw'] = 0.
     smdict['Mb'] = 0.
     st = Stream()
     stats = {'network': '', 'delta': 1.0,
              'station': 'No data available', 'location': '',
              'starttime': UTCDateTime(1970, 1, 1, 0, 0, 0, 0),
              'npts': 100, 'calib': 1.0,
              'sampling_rate': 1.0, 'channel': 'None','smdict':smdict}
     data = np.zeros(100)
     for i in xrange(9):
         st.append(Trace(data,stats))
     return st
开发者ID:obspy,项目名称:branches,代码行数:35,代码来源:read_gns_sm_data.py

示例4: process_syn

# 需要导入模块: from obspy.core import Stream [as 别名]
# 或者: from obspy.core.Stream import append [as 别名]
def process_syn(stream,starttime,endtime,sampling_rate,npts,filt_freq,max_percentage=0.05) :

    stream_process = Stream()
    for tr in stream :
        new_tr=tr.copy()
        cut_func(new_tr, starttime, endtime)

        # detrend, demean, taper
        new_tr.detrend("linear")
        new_tr.detrend("demean")
        new_tr.taper(max_percentage=max_percentage, type="hann")

        # geometric compensation
        # filter and interpolation
        filter_synt(new_tr, filt_freq)
        new_tr.interpolate(sampling_rate=sampling_rate,\
                starttime=new_tr.stats.starttime,npts=npts)

        # detrend, demean, taper
        new_tr.detrend("linear")
        new_tr.detrend("demean")
        new_tr.taper(max_percentage=max_percentage, type="hann")

        new_tr.data = np.require(new_tr.data, dtype=np.float32)
        stream_process.append(new_tr)

    return stream_process
开发者ID:ArianeDucellier,项目名称:multiscale,代码行数:29,代码来源:process_test.py

示例5: selectUniqueTraces

# 需要导入模块: from obspy.core import Stream [as 别名]
# 或者: from obspy.core.Stream import append [as 别名]
def selectUniqueTraces(tr,args):

    # Test on orizontal component, since if only vertical component exists, 
    # no xcorr on horiz allowed --> crash
  
    st = Stream()
    List = []
    ST = []
    CleanList = []

    for i in range(len(tr)):
        if(tr[i].stats.channel[2:3] == "N"):
           List.append(tr[i].stats.station)

    for i in range(len(tr)):
       a = List.count(tr[i].stats.station)
       if(a > 1):
           ST.append(tr[i].stats.station)

    d = Counter(ST)
    for key in d:
        CleanList.append(key) 
    
    for i in range(len(tr)):
        if CleanList.count(tr[i].stats.station) == 0:
           st.append(tr[i]) 

    return st 
开发者ID:Fran89,项目名称:pydmt,代码行数:30,代码来源:processData.py

示例6: noise_window_trace

# 需要导入模块: from obspy.core import Stream [as 别名]
# 或者: from obspy.core.Stream import append [as 别名]
def noise_window_trace(st,window_len_time):
    """Get noise window for st"""
    noise_st = Stream()
    for tr in st:
        noise_tr = tr.slice(tr.stats.starttime,tr.stats.starttime+window_len_time)
        noise_st.append(noise_tr)
    return noise_st
开发者ID:alanfbaird,项目名称:ms_attenuation,代码行数:9,代码来源:bs_lsr.py

示例7: get_waveforms

# 需要导入模块: from obspy.core import Stream [as 别名]
# 或者: from obspy.core.Stream import append [as 别名]
def get_waveforms(session, wfdisc, station=None, channel=None, starttime=None, 
        endtime=None, wfids=None):
    """
    Get waveforms.

    Parameters
    ----------
    session : sqlalchemy.orm.Session instance
        Must be bound.
    wfdisc : mapped Wfdisc table class
    station, channel : str, optional
        Desired station, channel code strings
    starttimes, endtimes : float, optional
        Epoch start times, end times.  
        Traces will be cut to these times.
    wfids : iterable of int, optional
        Wfdisc wfids.  Obviates the above arguments and just returns full Wfdisc
        row waveforms.

    Returns
    -------
    obspy.Stream
        Traces are merged and cut to requested times.

    """
    #TODO: add evids= option?, use with stawin= option in .execute method?
    #TODO: implement get_arrivals if arrivals=True
    Wfdisc = wfdisc

    st = Stream()
    if not wfids:
        t1 = float(starttime)
        t2 = float(endtime)
        sta = station
        chan = channel

        t1_utc = UTCDateTime(float(t1))
        t2_utc = UTCDateTime(float(t2))

        wfs = get_wfdisc_rows( session,Wfdisc, sta, chan, t1, t2)

        #TODO: do arrival stuff here
        for wf in wfs:
            try:
                tr = wfdisc2trace(wf)
                tr.trim(t1_utc, t2_utc)
                st.append(tr)
            except AttributeError:
                #tr is None b/c data couldn't be read
                pass
    else:
        wfs = get_wfdisc_rows( session,Wfdisc, wfids=wfids)
        for wf in wfs:
            try:
                tr = wfdisc2trace(wf)
                st.append(tr)
            except AttributeError:
                pass

    return st
开发者ID:mitchburnett,项目名称:pisces,代码行数:62,代码来源:request.py

示例8: ascii

# 需要导入模块: from obspy.core import Stream [as 别名]
# 或者: from obspy.core.Stream import append [as 别名]
def ascii(path, filenames):
    """ Reads SPECFEM3D-style ascii data
    """
    from numpy import loadtxt
    from obspy.core import Stream, Stats, Trace

    stream = Stream()
    for filename in filenames:
        stats = Stats()
        data = loadtxt(path +'/'+ filename)

        stats.filename = filename
        stats.starttime = data[0,0]
        stats.sampling_rate = data[0,1] - data[0,0]
        stats.npts = len(data[:,0])

        try:
            parts = filename.split('.')
            stats.network = parts[0]
            stats.station = parts[1]
            stats.channel = temp[2]
        except:
            pass

        stream.append(Trace(data=data[:,1], header=stats))

    return stream
开发者ID:PrincetonUniversity,项目名称:seisflows,代码行数:29,代码来源:readers.py

示例9: test_SavingSmallASCII

# 需要导入模块: from obspy.core import Stream [as 别名]
# 或者: from obspy.core.Stream import append [as 别名]
 def test_SavingSmallASCII(self):
     """
     Tests writing small ASCII strings.
     """
     tempfile = NamedTemporaryFile().name
     st = Stream()
     st.append(Trace(data=np.fromstring("A" * 8, "|S1")))
     st.write(tempfile, format="MSEED")
     os.remove(tempfile)
开发者ID:kasra-hosseini,项目名称:obspy,代码行数:11,代码来源:test_mseed_reading_and_writing.py

示例10: window_trace

# 需要导入模块: from obspy.core import Stream [as 别名]
# 或者: from obspy.core.Stream import append [as 别名]
def window_trace(st,before_p,after_p):
    """Cuts a window around an obspy trace using a before and after p pick time (sec)"""
    p_st = Stream()
    for tr in st:
        #Removing traces without p picks
        if tr.stats.sac['t0'] != -12345.0:
            
            p_pick=tr.stats.starttime+tr.stats.sac['t0']
            p_tr = tr.slice(p_pick-before_p,p_pick+after_p)
            p_st.append(p_tr)
    
                
    return p_st
开发者ID:alanfbaird,项目名称:ms_attenuation,代码行数:15,代码来源:bs_lsr.py

示例11: purgeStream

# 需要导入模块: from obspy.core import Stream [as 别名]
# 或者: from obspy.core.Stream import append [as 别名]
def purgeStream(st,l):

    # Parameters: st: Stream, l: linst with station number [0 to nr stations]

    new=Stream()

    ls_Sta = getSTationslist(st)
    for i in range(len(l)):
        a = l[i]-i
        ls_Sta.pop(a)

    for i in range(len(st)):
        sta = st[i].stats.station
        rem = [y for y in ls_Sta if sta == y]
        if (len(rem)==1):
           new.append(st[i])
    
    return new
开发者ID:Fran89,项目名称:pydmt,代码行数:20,代码来源:cleanSetMT.py

示例12: _format_data

# 需要导入模块: from obspy.core import Stream [as 别名]
# 或者: from obspy.core.Stream import append [as 别名]
    def _format_data(self, timeseries, channels, stats):
        """Format all data lines.

        Parameters
        ----------
            timeseries : obspy.core.Stream
                Stream containing traces with channel listed in channels
            channels : sequence
                List and order of channel values to output.

        Returns
        -------
        str
            A string formatted to be the data lines in a PCDCP file.
        """
        buf = []

        # create new stream
        timeseriesLocal = Stream()
        # Use a copy of the trace so that we don't modify the original.
        for trace in timeseries:
            traceLocal = trace.copy()
            if traceLocal.stats.channel == "D":
                traceLocal.data = ChannelConverter.get_minutes_from_radians(traceLocal.data)

            # TODO - we should look into multiplying the trace all at once
            # like this, but this gives an error on Windows at the moment.
            # traceLocal.data = \
            #     numpy.round(numpy.multiply(traceLocal.data, 100)).astype(int)

            timeseriesLocal.append(traceLocal)

        traces = [timeseriesLocal.select(channel=c)[0] for c in channels]
        starttime = float(traces[0].stats.starttime)
        delta = traces[0].stats.delta

        for i in xrange(len(traces[0].data)):
            buf.append(
                self._format_values(
                    datetime.utcfromtimestamp(starttime + i * delta), (t.data[i] for t in traces), stats
                )
            )

        return "".join(buf)
开发者ID:jmfee-usgs,项目名称:geomag-algorithms,代码行数:46,代码来源:PCDCPWriter.py

示例13: time_difference

# 需要导入模块: from obspy.core import Stream [as 别名]
# 或者: from obspy.core.Stream import append [as 别名]
def time_difference(isource, j):
	"""Compute the time difference between data and synthetics

	Input:
	isource = index of the source
	j = scale at which we run the inversion process"""

	namedir1 = 'Source_' + str(isource + 1)
	os.chdir(namedir1)

	filename_d = 'OUTPUT_FILES/data_process.su'
	filename_s = 'OUTPUT_FILES/synthetics_process.su'
	filename_i = 'OUTPUT_FILES/Up_file_single.su'
	stream_d = read(filename_d, format='SU', byteorder='<')
	stream_s = read(filename_s, format='SU', byteorder='<')
	stream_i = read(filename_i, format='SU')

	misfit = 0.0
	stream_adj = Stream()
	for irec in range(0, nrec):
		adj = numpy.zeros(nt_s)
		trace_i = stream_i[irec].copy()
		if irec >= rstart - 1 and irec <= rend - 1:
			trace_d = stream_d[irec].copy()
			trace_s = stream_s[irec].copy()
			if trace_d.data.size != trace_s.data.size:
				raise ValueError("Data and synthetic signals should have the same length")
			nstep = trace_s.data.size
			adj_temp = numpy.zeros(nt_ref)
			starttime = tstart[j - 1] + irec * 25.0 * sstart[j - 1]
			istart = int(starttime / dt_ref)
			for it in range(0, nstep):
				misfit += 0.5 * numpy.power(f * trace_s.data[it] - trace_d.data[it], 2.0)
				adj_temp[istart + it] = f * trace_s.data[it] - trace_d.data[it]
			trace_adj = Trace(data=adj_temp, header=trace_s.stats)
			trace_adj.interpolate(sampling_rate=1.0 / dt_s, starttime=trace_adj.stats.starttime, npts=nt_s)
		else:
			trace_adj = Trace(data=adj, header=trace_i.stats)
		trace_adj.data = numpy.require(trace_adj.data, dtype=numpy.float32)
		stream_adj.append(trace_adj)
	stream_adj.write('SEM/Up_file_single.su.adj', format='SU')
	os.chdir('..')

	return misfit
开发者ID:ArianeDucellier,项目名称:multiscale,代码行数:46,代码来源:optimization.py

示例14: dir_read_stream

# 需要导入模块: from obspy.core import Stream [as 别名]
# 或者: from obspy.core.Stream import append [as 别名]
def dir_read_stream(base_dir='', pattern='*.raw', sort_flag=True, \
                    format='None (Automatic)'):
    """ Read all files in specified directory into one single stream object.

    Reads all files in the directory assuming one trace per file and stores it
    in one stream.
    """

    import glob

    if sort_flag:
        file_list = sorted(glob.glob(os.path.join(base_dir, pattern)))
    else:
        file_list = glob.glob(os.path.join(base_dir, pattern))
    stack_st = Stream()
    for this_file in file_list:
        st, _, _, _ = stream_read(filename=this_file, format=format)
        for tr in st:
            stack_st.append(tr)

    return(stack_st)
开发者ID:ftilmann,项目名称:miic,代码行数:23,代码来源:alpha_mod.py

示例15: process

# 需要导入模块: from obspy.core import Stream [as 别名]
# 或者: from obspy.core.Stream import append [as 别名]
def process(isource, j):
	"""Read the DWT results in SU file
	and apply preprocessing

	Input:
	isource = index of the source
	j = scale at which we run the inversion process"""

	namedir1 = 'Source_' + str(isource + 1)
	os.chdir(namedir1)

	stream_d = read('OUTPUT_FILES/data_DWT.su', format='SU', byteorder='<')
	stream_s = read('OUTPUT_FILES/synthetics_DWT.su', format='SU', byteorder='<')

	stream_d_new = Stream()
	stream_s_new = Stream()
	for irec in range(0, nrec):
		trace_d = stream_d[irec].copy()
		trace_s = stream_s[irec].copy()
		# Window
		starttime = tstart[j - 1] + irec * 25.0 * sstart[j - 1]
		endtime = tend[j - 1] + irec * 25.0 * send[j - 1]
		cut_func(trace_d, starttime, endtime)
		cut_func(trace_s, starttime, endtime)
		# Tapering
		trace_d.taper(max_percentage=0.8, type="hann")
		trace_s.taper(max_percentage=0.8, type="hann")
		# Filtering
		filter_synt(trace_d, filt_freq)
		filter_synt(trace_s, filt_freq)
		# Tapering
		trace_d.taper(max_percentage=0.8, type="hann")
		trace_s.taper(max_percentage=0.8, type="hann")
		trace_d.data = numpy.require(trace_d.data, dtype=numpy.float32)
		trace_s.data = numpy.require(trace_s.data, dtype=numpy.float32)
		stream_d_new.append(trace_d)
		stream_s_new.append(trace_s)
	stream_d_new.write('OUTPUT_FILES/data_process.su', format='SU', byteorder='<')
	stream_s_new.write('OUTPUT_FILES/synthetics_process.su', format='SU', byteorder='<')
	os.chdir('..')
开发者ID:ArianeDucellier,项目名称:multiscale,代码行数:42,代码来源:preprocess.py


注:本文中的obspy.core.Stream.append方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。