-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheve.py
executable file
·153 lines (133 loc) · 3.86 KB
/
eve.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env python3
"""
Eve
The **eve**nt catalogue service.
A python script to query events from an fdsn service.
"""
import sys
from datetime import datetime
from enum import Enum
from functools import partial
import typer
from fdsn import Fdsn
from quakeml import to_valid_quakeml
class Provider(str, Enum):
"""Possible provider values for the fdsn service."""
GFZ = "gfz"
KNOWN_FDSN_SERVICE_PROVIDER = {
Provider.GFZ: "https://geofon.gfz-potsdam.de/fdsnws/"
}
def main(
# First the bounding box
lonmin: float = typer.Argument(
None,
help="".join(
[
"The minimum longitude of the search bounding ",
"box in decimal degree.",
]
),
),
lonmax: float = typer.Argument(
None,
help="".join(
[
"The maximum longitude of the search ",
"bounding box in decimal degree.",
]
),
),
latmin: float = typer.Argument(
None,
help="".join(
[
"The minimum latitude of the search bounding ",
"box in decimal degree.",
]
),
),
latmax: float = typer.Argument(
None,
help="".join(
[
"The maximum latitude of the search bounding ",
"box in decimal degree.",
]
),
),
# Then the time restristions
starttime: datetime = typer.Argument(
None,
help="The start of the time interval to search for (UTC).",
formats=[
"%Y-%m-%d",
"%Y-%m-%dT%H:%M:%S",
"%Y-%m-%d %H:%M:%S",
"%Y-%m-%dT%H:%M:%S.%fZ",
],
),
endtime: datetime = typer.Argument(
None,
help="The end of the time interval to search for (UTC).",
formats=[
"%Y-%m-%d",
"%Y-%m-%dT%H:%M:%S",
"%Y-%m-%d %H:%M:%S",
"%Y-%m-%dT%H:%M:%S.%fZ",
],
),
# And then magnitude
mmin: float = typer.Argument(
None, help="The minimum magnitude to search for."
),
mmax: float = typer.Argument(
None, help="The maximum magnitude to search for."
),
# and depth
zmin: float = typer.Argument(None, help="Minimal depth in km."),
zmax: float = typer.Argument(None, help="Maximal depth in km."),
# The last one is the limit, so that we don't
# query all of the catalogue.
limit: int = typer.Argument(200, help="The limit of events to query."),
provider: Provider = typer.Argument(
Provider.GFZ, help="The fdsn provider to query."
),
):
"""Eve - the **eve**nt catalogue."""
print_err = partial(print, file=sys.stderr)
die = partial(sys.exit, 1)
fdsn_service = Fdsn(KNOWN_FDSN_SERVICE_PROVIDER[provider])
if starttime > endtime:
print_err(f"Starttime {starttime} is after endtime {endtime}.")
print_err(f"There are no such events.")
die()
if mmin > mmax:
print_err(
f"Minimum magnitude {mmin} is larger than"
+ f"maximum magnitude {mmax}."
)
print_err(f"There are no such events.")
die()
if zmin > zmax:
print_err(f"Minimum depth {zmin} is larger than maximum depth {zmax}.")
print_err(f"There are no such events.")
die()
events = fdsn_service.query_events(
minlatitude=latmin,
maxlatitude=latmax,
minlongitude=lonmin,
maxlongitude=lonmax,
starttime=starttime,
endtime=endtime,
mindepth=zmin,
maxdepth=zmax,
minmagnitude=mmin,
maxmagnitude=mmax,
limit=limit,
)
events_valid_quakeml = to_valid_quakeml(events)
output_file = "output.xml"
with open(output_file, "w") as outfile:
outfile.write(events_valid_quakeml)
if __name__ == "__main__":
typer.run(main)