get_waveforms.py 3.06 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
"""
Load waveform data for processing


# Copyright (c) 2018 by SCCER-SoE and SED at ETHZ

Version 0.0, 23.10.2018, Joseph Doetsch (doetschj)
             23.10.2018, Semih Demir

"""

from obspy import Stream
import pyasdf

doetschj's avatar
doetschj committed
15

16
def get_waveforms(param, load_file, trig_time):
doetschj's avatar
doetschj committed
17
18
    aparam = param['Acquisition']
    gparam = param['General']
19
    asdf_folder = param['Trigger']['asdf_folder']
doetschj's avatar
doetschj committed
20
    #print(gparam['stats']['network'] + '_001')
21
22
23
24
25
26
27
28
29
    start_time = trig_time - param['Trigger']['starttime']
    end_time = trig_time + param['Trigger']['endtime']

    ch_in = range(1, gparam['sensor_count' ] +1)
    r = range(len(ch_in))
    if len(load_file) == 1:  # load 2 snippets if event in overlap otherwise load 1
        wf_stream = Stream()
        ds = pyasdf.ASDFDataSet(asdf_folder + '/' + load_file[0], mode='r')
        for k in r:
30
31
            wf_stream += ds.get_waveforms(network=gparam['stats']['network'], station=str(int(ch_in[k])).zfill(3), location='00',
                                          channel='001',
32
33
34
35
36
37
                                          starttime=start_time,
                                          endtime=end_time,
                                          tag="raw_recording")

    else:
        ds1 = pyasdf.ASDFDataSet(asdf_folder + '/' + load_file[0], mode='r')
38
        ds2 = pyasdf.ASDFDataSet(asdf_folder + '/' + load_file[1], mode='r') #GR_001
39
40

        if end_time > ds2.waveforms.aparam['stats']['network']+'_001'.raw_recording.traces[0].stats["starttime"]:
41
42
43
            sta_p1 = Stream()
            sta_p2 = Stream()
            for k in r:
44
45
                sta_p1 += ds1.get_waveforms(network=gparam['stats']['network'], station=str(int(ch_in[k])).zfill(3), location='00',
                                            channel='001',
46
                                            starttime=start_time,
47
                                            endtime=ds1.waveforms.gparam['stats']['network']+'_'+'001'.raw_recording.traces[0].stats["endtime"],
48
                                            tag="raw_recording")
49
50
51
                sta_p2 += ds2.get_waveforms(network=gparam['stats']['network'], station=str(int(ch_in[k])).zfill(3), location='00',
                                            channel='001',
                                            starttime=ds2.waveforms.print(gparam['stats']['network'] + '_' +'001').raw_recording.traces[0].stats["starttime"],
52
53
54
55
56
57
58
59
                                            endtime=end_time,
                                            tag="raw_recording")
                wf_stream = sta_p1 + sta_p2
                wf_stream.merge(method=1, interpolation_samples=0)

        else:
            wf_stream = Stream()
            for k in r:
60
61
                wf_stream += ds1.get_waveforms(network=aparam['stats']['network'], station=str(int(ch_in[k])).zfill(3), location='00',
                                               channel='001',
62
63
64
65
                                               starttime=start_time,
                                               endtime=end_time,
                                               tag="raw_recording")
    return wf_stream
Semih Demir's avatar
Semih Demir committed
66

doetschj's avatar
doetschj committed
67

Semih Demir's avatar
Semih Demir committed
68