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

22 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-10-06 06:59 +0000

1# https://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

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

5 

6from ..snuffling import Snuffling 

7from ..marker import EventMarker 

8 

9from pyrocko.client import catalog 

10 

11 

12class GeofonEvents(Snuffling): 

13 ''' 

14 Get events from GEOFON catalog. 

15 ''' 

16 

17 def __init__(self, magmin=None): 

18 self._magmin = magmin 

19 Snuffling.__init__(self) 

20 

21 def setup(self): 

22 ''' 

23 Customization of the snuffling. 

24 ''' 

25 

26 if self._magmin is None: 

27 self.set_name('Get GEOFON Events') 

28 else: 

29 self.set_name('Get GEOFON Events (> M %g)' % self._magmin) 

30 

31 def call(self): 

32 ''' 

33 Main work routine of the snuffling. 

34 ''' 

35 

36 # get time range visible in viewer 

37 viewer = self.get_viewer() 

38 tmin, tmax = viewer.get_time_range() 

39 

40 # download event information from GEOFON web page 

41 # 1) get list of event names 

42 geofon = catalog.Geofon() 

43 event_names = geofon.get_event_names( 

44 time_range=(tmin, tmax), 

45 magmin=self._magmin) 

46 

47 # 2) get event information and add a marker in the snuffler window 

48 for event_name in event_names: 

49 event = geofon.get_event(event_name) 

50 marker = EventMarker(event) 

51 self.add_markers([marker]) 

52 

53 

54def __snufflings__(): 

55 ''' 

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

57 ''' 

58 

59 return [ 

60 GeofonEvents(), 

61 GeofonEvents(magmin=6), 

62 GeofonEvents(magmin=7), 

63 GeofonEvents(magmin=8)]