Wiki source code of FDSN Guide

Version 2.4 by robert on 2025/03/24 10:30

Show last authors
1 {{box cssClass="floatinginfobox" title="**Contents**"}}
2 {{toc/}}
3 {{/box}}
4
5 = [[How to Install ObsPy>>url:https://github.com/obspy/obspy/wiki#installation]] =
6
7 = [[Seed-Vault>>https://github.com/AuScope/seed-vault]] =
8
9 = Connecting to an FDSN Server =
10
11 == How to connect to AusPass with & without authenticated access ==
12
13
14 {{code language="python"}}
15 import obspy
16 from obspy.clients.fdsn import Client
17
18 # Initialize FDSN client for AusPass
19
20 # For open access data, no username or password is required.
21 client = Client('AUSPASS')
22
23 # To access restricted data, supply your username and password
24 # Replace 'Z1' and '12345' with your actual credentials
25 client = Client('AUSPASS', user='Z1', password='12345')
26 {{/code}}
27
28 = Station Metadata =
29
30 Information such as site locations, sensor and data logger types, response information, etc are in the station metadata. This can be accessed directly(link) or via the obspy get_stations (link) tool.
31
32
33 == How to download event, station, instrument response ==
34
35
36 {{code language="python"}}
37 import obspy
38 from obspy.clients.fdsn import Client
39
40 # Use AusPass client for station, waveform, and earthquake information
41 client = Client("AUSPASS")
42
43
44 # Download station information for AUMTC station in S1 network at the response level
45 inv = client.get_stations(network="S1", station="AUMTC", location="*",
46 channel="*", starttime=event_time - 60,
47 endtime=event_time + 1000, level="response")
48 print(inv)
49
50 # Inventory metadata is stored in a Inventory > Network > Station > Channel hierarchy
51
52 print(inv) #inventory level
53
54 print(inv[0]) # network level (the first network in the inventory)
55
56 print(inv[0][0]) # station level (the first station of the first network in the inventory)
57
58 print(inv[0][0][0]) # channel level (the first channel of the first station of the first network in the inventoy)
59
60 # you can also select items directly
61
62 print(inv.select(station='AUMTC',channel='HHZ')[0][0][0])
63
64 # instrument response is attached to a channel object
65
66 response = inv.select(station='AUMTC',channel='HHZ')[0][0][0].response
67 {{/code}}
68
69
70 === Sub-sub paragraph ===
71
72 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
73
74
75 = Waveform Data =
76
77 Waveform data (e.g. the actual seismic data) can be accessed directly (link) or via obspy's get_waveforms (link) tool. It can also be accessed via various tools such as seed-vault, pyweed, etc (add links).
78
79 == How to download waveform data ==
80
81 {{code language="python"}}
82 from obspy import UTCDateTime
83 from obspy.clients.fdsn import Client
84
85 # Initialize the FDSN client (you can also specify other data centers)
86 client = Client("AUSPASS")
87
88 # Event information
89 network = "S1"
90 station = "AUGRF"
91 starttime = UTCDateTime("2021-09-21T23:15:53") # The time of the earthquake
92 endtime = starttime + 360 # One hour of data after the earthquake
93
94 # Download the MiniSEED data
95 st = client.get_waveforms(network=network, station=station, location="*", channel="BHZ",
96 starttime=starttime, endtime=endtime)
97 # Save the stream to a MiniSEED file
98 st.write("Woodspoint_2021.mseed", format="MSEED")
99 print("Downloaded and saved the MiniSEED file.")
100 {{/code}}
101
102 == How to remove instrument response ==
103
104 {{code language="python"}}
105 from obspy import read
106 from obspy.core.util import AttribDict
107
108 # Load the MiniSEED file
109 st = read("Woodspoint_2021.mseed")
110
111 # Download the instrument response
112 inv = client.get_stations(network=network, station=station, location="*",
113 channel="*", starttime=starttime, endtime=endtime,
114 level="response")
115
116 # Remove the instrument response
117 output = 'VEL' # Output unit ('VEL' = velocity (default), 'DISP' = displacement, 'ACC' = acceleration)
118
119 for tr in st:
120 tr.remove_response(inventory=inv, output=output, plot=True)
121
122 # Save the corrected MiniSEED file
123 st.write("Woodspoint_2021_corrected.mseed", format="MSEED")
124 {{/code}}
125
126 == How to apply a bandpass filter ==
127
128 {{code language="python"}}
129 from obspy import read
130
131 # Load the MiniSEED file
132 st = read("Woodspoint_2021.mseed")
133
134 # Define the frequency band
135 freq_min = 0.1 # Minimum frequency in Hz
136 freq_max = 1.0 # Maximum frequency in Hz
137
138 # Apply the bandpass filter
139 for tr in st:
140 tr.filter(type='bandpass', freqmin=freq_min, freqmax=freq_max)
141
142 # Save the filtered MiniSEED file
143 st.write("Woodspoint_2021_filtered.mseed", format="MSEED")
144 {{/code}}
145
146 == How to slice a waveform ==
147
148 {{code language="python"}}
149 from obspy import read, UTCDateTime, Stream # Importing Stream here
150
151 # Load the filtered MiniSEED file
152 st = read("Woodspoint_2021_filtered.mseed")
153
154 # Define the time window for slicing
155 slice_start = UTCDateTime("2021-09-21T23:20:00")
156 slice_end = slice_start +10
157
158 # Slice the waveform for each Trace in the Stream
159 sliced_st = Stream() # Now Stream is defined
160 for tr in st:
161 sliced_tr = tr.slice(starttime=slice_start, endtime=slice_end)
162 sliced_st.append(sliced_tr)
163
164 # Save the sliced MiniSEED file
165 sliced_st.write("Woodspoint_2021_filtered_sliced.mseed", format="MSEED")
166 {{/code}}
167
168 == How to save a waveform ==
169
170 {{code language="python"}}
171 # Save the sliced file as MiniSEED
172 sliced_st.write("Woodspoint_2021_filtered_sliced.mseed", format="MSEED")
173
174 # Or, save the sliced SAC file
175 sliced_st.write("Woodspoint_2021_filtered_sliced.sac", format="SAC")
176 {{/code}}
177
178 == How to convert miniseed to sac ==
179
180 {{code language="python"}}
181 from obspy import read
182
183 # Read the MiniSEED file
184 st = read("Woodspoint_2021.mseed")
185
186 # Take the first Trace from the Stream
187 tr = st[0]
188
189 # Save that Trace as a SAC file
190 tr.write("Woodspoint_2021.sac", format="SAC")
191 {{/code}}
192
193
194 = Earthquake Data =
195
196
197 == How to download an Earthquake Catalog ==
198
199 {{code language="python"}}
200 from obspy.clients.fdsn import Client
201 from obspy import UTCDateTime
202
203 # Initialize the AusPass FDSN client
204 client = Client("AUSPASS")
205
206 # Define the time range for the earthquake catalog
207 start_time = UTCDateTime("2021-08-01")
208 end_time = UTCDateTime("2022-01-01") # End of year
209
210 # Define the geographic region (latitude and longitude for Woodspoint, Victoria, Australia)
211 latitude = -37.47
212 longitude = 146.10
213 max_radius = 5 # in degrees
214
215 # Download the earthquake catalog
216 catalog = client.get_events(starttime=start_time, endtime=end_time,
217 minmagnitude=2, latitude=latitude, longitude=longitude,
218 maxradius=max_radius)
219
220 # Save the catalog to a file (e.g., QuakeML format)
221 catalog.write("Woodspoint_earthquakes.xml", format="QUAKEML")
222 {{/code}}
223
224 == How to plot (Global) Earthquakes ==
225
226 {{code language="python"}}
227 from obspy import UTCDateTime
228 from obspy.clients.fdsn import Client
229
230 # Initialize FDSN client to connect to the IRIS data center
231 client = Client("IRIS")
232
233 # Set the time range for fetching earthquake data
234 # Start time: January 1, 2023
235 # End time: Current time
236 starttime = UTCDateTime("2023-01-01")
237 endtime = UTCDateTime()
238
239 # Fetch earthquake events with a minimum magnitude of 7
240 catalog = client.get_events(starttime=starttime, endtime=endtime, minmagnitude=7)
241 #client.get_events(). This function returns a Catalog object that contains a list of Event objects.
242 #Each Event object, in turn, has an Origins attribute that contains the depth information
243
244 # Plot the fetched earthquake data using an orthographic projection
245 catalog.plot(projection="ortho", title="Global Earthquakes with Magnitude >= 7 since 2023")
246 #catalog.plot(), ObsPy automatically uses the depth information to color the events in the plot
247 {{/code}}
248
249 == How to plot (Local) Earthquakes ==
250
251 {{code language="python"}}
252 from obspy import UTCDateTime
253 from obspy.clients.fdsn import Client
254
255 # Initialize FDSN client
256 client = Client("AUSPASS")
257
258 # Define time range
259 starttime = UTCDateTime("2023-01-01")
260 endtime = UTCDateTime()
261
262 # Latitude and longitude bounds for Australia
263 minlatitude = -44.0
264 maxlatitude = -10.0
265 minlongitude = 113.0
266 maxlongitude = 154.0
267
268 # Fetch event data for Australia with a minimum magnitude
269 catalog = client.get_events(starttime=starttime, endtime=endtime, minmagnitude=4,
270 minlatitude=minlatitude, maxlatitude=maxlatitude,
271 minlongitude=minlongitude, maxlongitude=maxlongitude)
272
273 # Plot the earthquakes
274 catalog.plot(projection="local", title="Australia Earthquakes", resolution="i")
275 {{/code}}