Coverage for /usr/local/lib/python3.11/dist-packages/pyrocko/gui/snuffler/snufflings/minmax.py: 47%

19 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2024-03-07 11:54 +0000

1# https://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

4# ---|P------/S----------~Lg---------- 

5 

6from ..snuffling import Snuffling 

7from pyrocko import trace 

8 

9 

10class MinMaxSnuffling(Snuffling): 

11 

12 ''' 

13 Reports minimum, maximum, and peak-to-peak values of selected data. 

14 

15 To use it, use the picker tool to mark a region or select existing regions 

16 and call this snuffling. The values are printed via standard output to the 

17 termimal. 

18 ''' 

19 

20 def setup(self): 

21 ''' 

22 Customization of the snuffling. 

23 ''' 

24 

25 self.set_name('Minimum Maximum Peak-To-Peak') 

26 self.tinc = None 

27 

28 def call(self): 

29 ''' 

30 Main work routine of the snuffling. 

31 ''' 

32 

33 # to select a reasonable increment for the chopping, the smallest 

34 # sampling interval in the pile is looked at. this is only done, 

35 # the first time the snuffling is called. 

36 if self.tinc is None: 

37 self.tinc = self.get_pile().get_deltats()[0] * 10000. 

38 

39 # the chopper yields lists of traces but for minmax() below, an 

40 # iterator yielding single traces is needed; using a converter: 

41 def iter_single_traces(): 

42 for traces in self.chopper_selected_traces( 

43 tinc=self.tinc, degap=False, fallback=True): 

44 

45 for tr in traces: 

46 yield tr 

47 

48 # the function minmax() in the trace module can get minima and maxima 

49 # grouped by (network,station,location,channel): 

50 mima = trace.minmax(iter_single_traces()) 

51 

52 for nslc in sorted(mima.keys()): 

53 p2p = mima[nslc][1] - mima[nslc][0] 

54 print('%s.%s.%s.%s: %12.5g %12.5g %12.5g' % ( 

55 nslc + mima[nslc] + (p2p,))) 

56 

57 

58def __snufflings__(): 

59 ''' 

60 Returns a list of snufflings to be exported by this module. 

61 ''' 

62 

63 return [MinMaxSnuffling()]