Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

56

57

58

59

60

61

62

63

64

# -*- coding: utf-8 -*- 

""" 

Optional feature generators for ObsPy Trace objects. 

 

:copyright: 

    The ObsPy Development Team (devs@obspy.org) 

:license: 

    GNU Lesser General Public License, Version 3 

    (http://www.gnu.org/copyleft/lesser.html) 

""" 

 

from obspy.core.util import scoreatpercentile 

 

 

class BandpassPreviewFeature(object): 

    """ 

    Bandpass filter (freqmin=0.1, freqmax=20.0) all trace previews. 

    """ 

 

    def process(self, trace): 

        """ 

        Bandpass filter (freqmin=0.1, freqmax=20.0) all trace previews. 

        """ 

        # applying bandpass on trace directly - this will not modify the 

        # original waveform file but it will influence the preview trace 

        trace.filter("bandpass", freqmin=0.1, freqmax=20.0) 

        return {} 

 

 

class MinMaxAmplitudeFeature(object): 

    """ 

    Generates statistics about the amplitude values. 

    """ 

 

    def process(self, trace): 

        """ 

        Generates statistics about the amplitude values. 

 

        This may take a while to calculate - use a moderate looping interval. 

 

        .. rubric:: Example 

 

        >>> from obspy import Trace 

        >>> import numpy as np 

        >>> tr = Trace(data=np.arange(-5,5)) 

        >>> result = MinMaxAmplitudeFeature().process(tr) 

        >>> result['max'] 

        4.0 

        >>> result['upper_quantile'] 

        1.75 

        """ 

        result = {} 

        result['min'] = float(trace.data.min()) 

        result['max'] = float(trace.data.max()) 

        result['avg'] = float(trace.data.mean()) 

        result['median'] = float(scoreatpercentile(trace.data, 50, False)) 

        result['lower_quantile'] = float(scoreatpercentile(trace.data, 25)) 

        result['upper_quantile'] = float(scoreatpercentile(trace.data, 75)) 

        return result 

 

 

if __name__ == '__main__': 

    import doctest 

    doctest.testmod(exclude_empty=True)