-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_PEs.py
55 lines (42 loc) · 1.94 KB
/
simple_PEs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from dispel4py.seismo.seismo import SeismoPE
from obspy.core import read
import scipy
class StreamProducer(SeismoPE):
INPUT_NAME = 'file'
OUTPUT_NAME = 'output'
def __init__(self, numIterations=1):
SeismoPE.__init__(self)
self._add_input('file')
def getDataStreams(self, inputs):
self._timestamp = {'starttime': None, 'endtime': None}
self._location = {'channel': None, 'network': None, 'station': None}
inputStr = inputs['file']
self.attr = {'network': None, 'channel': None, 'station': None,
'location': None, 'starttime': None, 'endtime': None,
'sampling_rate': None, 'npts': None}
return {"streams": [{'data': inputStr, 'attr': self.attr}]}
def compute(self):
stream = read(self.st)
# fills gaps with 0, gap correction should be implemented as PE
stream.merge()
outputattr = dict(self.attr)
outputattr['starttime'] = str(stream[0].stats.starttime)
outputattr['endtime'] = str(stream[0].stats.endtime)
outputattr['sampling_rate'] = stream[0].stats.sampling_rate
outputattr['npts'] = stream[0].stats.npts
outputattr['location'] = stream[0].stats.location
outputattr['network'] = stream[0].stats.network
outputattr['channel'] = stream[0].stats.channel
outputattr['station'] = stream[0].stats.station
self._timestamp['starttime'] = outputattr['starttime']
self._timestamp['endtime'] = outputattr['endtime']
self._location['network'] = outputattr['network']
self._location['channel'] = outputattr['channel']
self._location['station'] = outputattr['station']
self.outputattr = [outputattr]
self.outputstreams = [stream[0].data]
class DetrendPE(SeismoPE):
def __init__(self):
SeismoPE.__init__(self)
def compute(self):
return scipy.signal.detrend(self.st, type='linear')