-
Notifications
You must be signed in to change notification settings - Fork 0
/
fdsn.py
72 lines (58 loc) · 2.11 KB
/
fdsn.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""
fdsn
The module to interacte with an FDSN web service.
See: https://www.fdsn.org/webservices/fdsnws-event-1.2.pdf
"""
from typing import Optional
from datetime import datetime
import requests
class Fdsn:
"""Interact with an fdsn web service."""
def __init__(self, base_url: str):
"""Init the object with the base_url."""
self.base_url = base_url
def query_events(
self,
minlatitude: Optional[float] = None,
maxlatitude: Optional[float] = None,
minlongitude: Optional[float] = None,
maxlongitude: Optional[float] = None,
starttime: Optional[datetime] = None,
endtime: Optional[datetime] = None,
mindepth: Optional[float] = None,
maxdepth: Optional[float] = None,
minmagnitude: Optional[float] = None,
maxmagnitude: Optional[float] = None,
limit: Optional[int] = None,
):
"""Query events and return the xml text."""
event_query_url = self.base_url + "/event/1/query"
parameters = {
"format": "xml",
"magnitudetype": "Mw",
}
if minlatitude is not None:
parameters["minlatitude"] = minlatitude
if maxlatitude is not None:
parameters["maxlatitude"] = maxlatitude
if minlongitude is not None:
parameters["minlongitude"] = minlongitude
if maxlongitude is not None:
parameters["maxlongitude"] = maxlongitude
if starttime is not None:
parameters["starttime"] = starttime
if endtime is not None:
parameters["endtime"] = endtime
if mindepth is not None:
parameters["mindepth"] = mindepth
if maxdepth is not None:
parameters["maxdepth"] = maxdepth
if minmagnitude is not None:
parameters["minmagnitude"] = minmagnitude
if maxmagnitude is not None:
parameters["maxmagnitude"] = maxmagnitude
if limit is not None:
parameters["limit"] = limit
resp = requests.get(event_query_url, parameters)
resp.raise_for_status()
return resp.text