Coverage for /usr/local/lib/python3.11/dist-packages/pyrocko/client/saxony.py: 25%

53 statements  

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

1# http://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

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

5 

6''' 

7Access to `regional earthquake catalog of Saxony, Germany from the University 

8of Leipzig <http://home.uni-leipzig.de/collm/auswertung_temp.html>`_. 

9''' 

10 

11from pyrocko import util, model 

12from .base_catalog import EarthquakeCatalog 

13from pyrocko.util import urlopen 

14 

15import logging 

16 

17logger = logging.getLogger('pyrocko.client.saxony') 

18 

19km = 1000. 

20 

21 

22class Saxony(EarthquakeCatalog): 

23 ''' 

24 Access to `regional earthquake catalog of Saxony, Germany from the 

25 University of Leipzig 

26 <http://home.uni-leipzig.de/collm/auswertung_temp.html>`_. 

27 ''' 

28 

29 def __init__(self): 

30 self._events = None 

31 

32 def retrieve(self): 

33 url = 'http://home.uni-leipzig.de/collm/auswertung_temp.html' 

34 

35 f = urlopen(url) 

36 text = f.read() 

37 sec = 0 

38 events = {} 

39 for line in text.splitlines(): 

40 line = line.strip() 

41 if line == '<PRE>': 

42 sec += 1 

43 continue 

44 

45 if sec == 1 and not line: 

46 sec += 1 

47 continue 

48 

49 if sec == 1: 

50 t = line.split(' ', 1) 

51 name = t[0] 

52 sdate = t[1][0:11] 

53 stime = t[1][12:22] 

54 sloc = t[1][23:36] 

55 sdepth = t[1][37:42] 

56 smag = t[1][51:55] 

57 region = t[1][60:] 

58 

59 sday, smon, syear = sdate.split('-') 

60 smon = { 

61 'Jan': '01', 'Feb': '02', 'Mar': '03', 'Apr': '04', 

62 'Mai': '05', 'Jun': '06', 'Jul': '07', 'Aug': '08', 

63 'Sep': '09', 'Okt': '10', 'Nov': '11', 'Dez': '12'}[smon] 

64 

65 time = util.str_to_time( 

66 '%s-%s-%s %s' % (syear, smon, sday, stime)) 

67 

68 slat, slon = sloc.split(';') 

69 

70 ev = model.event.Event( 

71 time=time, 

72 lat=float(slat), 

73 lon=float(slon), 

74 depth=float(sdepth) * 1000., 

75 magnitude=float(smag), 

76 magnitude_type='Ml', 

77 name=name, 

78 region=region, 

79 catalog='Saxony') 

80 

81 events[name] = ev 

82 

83 self._events = events 

84 

85 def iter_event_names(self, time_range=None, **kwargs): 

86 if self._events is None: 

87 self.retrieve() 

88 

89 for name in sorted(self._events.keys()): 

90 if time_range is not None: 

91 ev = self._events[name] 

92 if time_range[0] <= ev.time and ev.time <= time_range[1]: 

93 yield name 

94 else: 

95 yield name 

96 

97 def get_event(self, name): 

98 if self._events is None: 

99 self.retrieve() 

100 

101 return self._events[name]