pysmo.tools.web
Tools for fetching seismological data from web services.
Type Aliases:
| Name | Description |
|---|---|
TravelTimeBackend |
Callable |
Functions:
| Name | Description |
|---|---|
fetch_seismogram |
Fetch a seismogram from the EarthScope FDSN dataselect web service. |
fetch_travel_times |
Fetch seismic phase travel times for a given source–receiver geometry. |
TravelTimeBackend
Callable (depth_km, dist_deg, phases) -> dict[str, float] returning travel times.
Accepts source depth in kilometres, epicentral distance in degrees, and a list of
seismic phase names (e.g. ["P", "S"]). Returns a mapping of phase name to
travel time in seconds, omitting phases with no arrival at the given geometry.
Keys must match the requested phase names verbatim; fetch_seismogram raises
ValueError if none of the requested phases appear in the returned mapping.
fetch_seismogram
fetch_seismogram(
*,
station: Station,
event: Event | None = None,
starttime: Timestamp | None = None,
endtime: Timestamp | None = None,
pre: Timedelta | None = None,
post: Timedelta | None = None,
phases: list[str] | None = None,
model: str = "iasp91",
travel_time_backend: TravelTimeBackend | None = None
) -> tuple[GeoCsvSeismogram, dict[str, Timestamp]]
Fetch a seismogram from the EarthScope FDSN dataselect web service.
Provide either an absolute time window (starttime + endtime) or a phase-relative window (pre + post). The phase-relative option requires event so that the predicted arrival time can be computed.
The returned GeoCsvSeismogram can be
converted to other seismogram types with
clone_to_mini and
copy_from_mini.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
station
|
Station
|
Any object satisfying the |
required |
event
|
Event | None
|
Any object satisfying the |
None
|
starttime
|
Timestamp | None
|
Start of the requested time window (UTC). Use with endtime for an absolute window. |
None
|
endtime
|
Timestamp | None
|
End of the requested time window (UTC). Use with starttime for an absolute window. |
None
|
pre
|
Timedelta | None
|
Duration before the predicted arrival to include. Use with post for a phase-relative window. |
None
|
post
|
Timedelta | None
|
Duration after the predicted arrival to include. Use with pre for a phase-relative window. |
None
|
phases
|
list[str] | None
|
Seismic phases to compute travel times for. If |
None
|
model
|
str
|
Velocity model name passed to the EarthScope traveltime service (or travel_time_backend). |
'iasp91'
|
travel_time_backend
|
TravelTimeBackend | None
|
Optional callable that overrides the EarthScope
traveltime web service. Must accept
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
seismogram |
GeoCsvSeismogram
|
The fetched waveform. |
predicted_arrivals |
dict[str, Timestamp]
|
Predicted phase arrival times as absolute UTC
timestamps, keyed by phase name (e.g. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the time-window arguments are inconsistent, no waveform data is returned, a data gap prevents merging segments into a continuous trace, or (for a phase-relative window) none of the requested phases are found in the travel-time response. |
ResponseError
|
If the dataselect web service returns an HTTP error, or (for a phase-relative window) the traveltime web service does. |
Examples:
Fetch a 10-minute window around the predicted P arrival for the 2010 Maule earthquake recorded at IU.ANMO:
>>> import pandas as pd
>>> from pysmo import MiniEvent, MiniStation
>>> station = MiniStation(
... name="ANMO", network="IU", location="00", channel="LHZ",
... latitude=34.945981, longitude=-106.457133,
... )
>>> event = MiniEvent(
... latitude=-36.122, longitude=-72.898, depth=22900.0,
... time=pd.Timestamp("2010-02-27T06:34:11.53Z"),
... )
>>> seismogram, arrivals = fetch_seismogram( # doctest: +SKIP
... station=station,
... event=event,
... pre=pd.Timedelta(minutes=2),
... post=pd.Timedelta(minutes=8),
... )
>>>
Source code in src/pysmo/tools/web.py
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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
fetch_travel_times
fetch_travel_times(
depth_km: float,
dist_deg: float,
phases: list[str],
model: str = "iasp91",
travel_time_backend: TravelTimeBackend | None = None,
) -> dict[str, float]
Fetch seismic phase travel times for a given source–receiver geometry.
Uses the EarthScope traveltime web service by default, or a custom callable if travel_time_backend is provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
depth_km
|
float
|
Source depth in kilometres. |
required |
dist_deg
|
float
|
Epicentral distance in degrees. |
required |
phases
|
list[str]
|
Seismic phase names to request (e.g. |
required |
model
|
str
|
Velocity model name. |
'iasp91'
|
travel_time_backend
|
TravelTimeBackend | None
|
Optional callable overriding the web service. Must
accept |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Mapping of phase name to travel time in seconds. Only phases with |
dict[str, float]
|
arrivals at the given distance and depth are included. |
Examples:
Using a custom travel_time_backend instead of the EarthScope web service.
The lambda below is a stand-in; replace it with a real travel-time
calculator:
>>> from pysmo.tools.web import fetch_travel_times
>>> backend = lambda depth, dist, phases: {"P": 480.2, "S": 900.1}
>>> fetch_travel_times(22.9, 60.0, ["P", "S"], travel_time_backend=backend)
{'P': 480.2, 'S': 900.1}
>>>