1# http://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

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

5from __future__ import absolute_import, division 

6 

7from pyrocko import util, model 

8from .base_catalog import EarthquakeCatalog 

9from pyrocko.util import urlopen 

10 

11import logging 

12 

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

14 

15km = 1000. 

16 

17 

18class Saxony(EarthquakeCatalog): 

19 

20 def __init__(self): 

21 self._events = None 

22 

23 def retrieve(self): 

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

25 

26 f = urlopen(url) 

27 text = f.read() 

28 sec = 0 

29 events = {} 

30 for line in text.splitlines(): 

31 line = line.strip() 

32 if line == '<PRE>': 

33 sec += 1 

34 continue 

35 

36 if sec == 1 and not line: 

37 sec += 1 

38 continue 

39 

40 if sec == 1: 

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

42 name = t[0] 

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

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

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

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

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

48 region = t[1][60:] 

49 

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

51 smon = { 

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

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

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

55 

56 time = util.str_to_time( 

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

58 

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

60 

61 ev = model.event.Event( 

62 time=time, 

63 lat=float(slat), 

64 lon=float(slon), 

65 depth=float(sdepth) * 1000., 

66 magnitude=float(smag), 

67 magnitude_type='Ml', 

68 name=name, 

69 region=region, 

70 catalog='Saxony') 

71 

72 events[name] = ev 

73 

74 self._events = events 

75 

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

77 if self._events is None: 

78 self.retrieve() 

79 

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

81 if time_range is not None: 

82 ev = self._events[name] 

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

84 yield name 

85 else: 

86 yield name 

87 

88 def get_event(self, name): 

89 if self._events is None: 

90 self.retrieve() 

91 

92 return self._events[name]