1# http://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

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

5 

6from pyrocko import util, model 

7from .base_catalog import EarthquakeCatalog 

8from pyrocko.util import urlopen 

9 

10import logging 

11 

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

13 

14km = 1000. 

15 

16 

17class Saxony(EarthquakeCatalog): 

18 

19 def __init__(self): 

20 self._events = None 

21 

22 def retrieve(self): 

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

24 

25 f = urlopen(url) 

26 text = f.read() 

27 sec = 0 

28 events = {} 

29 for line in text.splitlines(): 

30 line = line.strip() 

31 if line == '<PRE>': 

32 sec += 1 

33 continue 

34 

35 if sec == 1 and not line: 

36 sec += 1 

37 continue 

38 

39 if sec == 1: 

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

41 name = t[0] 

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

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

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

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

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

47 region = t[1][60:] 

48 

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

50 smon = { 

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

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

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

54 

55 time = util.str_to_time( 

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

57 

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

59 

60 ev = model.event.Event( 

61 time=time, 

62 lat=float(slat), 

63 lon=float(slon), 

64 depth=float(sdepth) * 1000., 

65 magnitude=float(smag), 

66 magnitude_type='Ml', 

67 name=name, 

68 region=region, 

69 catalog='Saxony') 

70 

71 events[name] = ev 

72 

73 self._events = events 

74 

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

76 if self._events is None: 

77 self.retrieve() 

78 

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

80 if time_range is not None: 

81 ev = self._events[name] 

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

83 yield name 

84 else: 

85 yield name 

86 

87 def get_event(self, name): 

88 if self._events is None: 

89 self.retrieve() 

90 

91 return self._events[name]