pysmo.tools.web
Tools for fetching seismological data from web services.
Thin wrappers around FDSN web services (EarthScope's, except fetch_quakeml,
which targets USGS since EarthScope retired its event service).
fetch_stationxml, fetch_station_inventory, fetch_sacpz,
fetch_geocsvseismogram, fetch_sac, fetch_mseed, and fetch_quakeml
return raw, unparsed responses, mostly a lower-level counterpart to a
class's own parsing entry point (e.g.
SAC.fetch,
QuakeML.all_from_bytes), useful on
their own for saving a raw response to disk and deferring parsing to later,
without another network request.
Predicted arrival times, used to window these fetches, are computed
locally by pysmo.tools.traveltime with no web service involved.
Type Aliases:
| Name | Description |
|---|---|
QuakeMLOrderBy |
Allowed |
Functions:
| Name | Description |
|---|---|
fetch_geocsvseismogram |
Fetch raw GeoCSV waveform bytes for a station/channel and time window. |
fetch_mseed |
Fetch raw miniSEED waveform bytes for a station/channel and time window. |
fetch_quakeml |
Fetch raw QuakeML 1.2 event metadata bytes from the USGS fdsnws-event service. |
fetch_sac |
Fetch a raw SAC zip archive for a station/channel and time window. |
fetch_sacpz |
Fetch raw SAC PZ response metadata text for a station/channel. |
fetch_station_inventory |
Fetch raw FDSN StationXML inventory bytes from EarthScope's fdsnws-station. |
fetch_stationxml |
Fetch raw StationXML response metadata bytes for a station/channel. |
QuakeMLOrderBy
QuakeMLOrderBy = Literal[
"time", "time-asc", "magnitude", "magnitude-asc"
]
Allowed orderby values for fetch_quakeml.
fetch_geocsvseismogram
Fetch raw GeoCSV waveform bytes for a station/channel and time window.
A lower-level counterpart to
GeoCsvSeismogram.fetch:
returns the waveform unparsed and uninterpreted. Save it to disk to
defer parsing to later (offline, without another network request)
via GeoCsvSeismogram.from_text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
station
|
Station
|
Any object satisfying the |
required |
starttime
|
Timestamp
|
Start of the requested time window (UTC). |
required |
endtime
|
Timestamp
|
End of the requested time window (UTC). |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
Raw GeoCSV document bytes. |
Raises:
| Type | Description |
|---|---|
ResponseError
|
If the dataselect web service returns an HTTP error. |
Examples:
>>> import pandas as pd
>>> from pathlib import Path
>>> from pysmo import MiniStation
>>> from pysmo.tools.web import fetch_geocsvseismogram
>>> station = MiniStation(
... name="ANMO", network="IU", location="00", channel="LHZ",
... latitude=34.945981, longitude=-106.457133,
... )
>>> data = fetch_geocsvseismogram(
... station=station,
... starttime=pd.Timestamp("2010-02-27T06:44:00Z"),
... endtime=pd.Timestamp("2010-02-27T06:54:00Z"),
... )
>>> _ = Path("ANMO.geocsv").write_bytes(data)
>>>
Source code in src/pysmo/tools/web.py
fetch_mseed
Fetch raw miniSEED waveform bytes for a station/channel and time window.
A lower-level counterpart to MSeed.fetch:
returns the miniSEED body returned by the dataselect web service
unparsed and uninterpreted. Save it to disk to defer parsing to later (offline, without another
network request) via
MSeed.from_bytes or
MSeed.all_from_bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
station
|
Station
|
Any object satisfying the |
required |
starttime
|
Timestamp
|
Start of the requested time window (UTC). |
required |
endtime
|
Timestamp
|
End of the requested time window (UTC). |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
Raw miniSEED bytes, as returned by the dataselect web service. An |
bytes
|
empty |
Raises:
| Type | Description |
|---|---|
ResponseError
|
If the dataselect web service returns an HTTP error. |
Examples:
>>> import pandas as pd
>>> from pathlib import Path
>>> from pysmo import MiniStation
>>> from pysmo.tools.web import fetch_mseed
>>> station = MiniStation(
... name="ANMO", network="IU", location="00", channel="LHZ",
... latitude=34.945981, longitude=-106.457133,
... )
>>> data = fetch_mseed(
... station=station,
... starttime=pd.Timestamp("2010-02-27T06:44:00Z"),
... endtime=pd.Timestamp("2010-02-27T06:54:00Z"),
... )
>>> _ = Path("ANMO.mseed").write_bytes(data)
>>>
Source code in src/pysmo/tools/web.py
fetch_quakeml
fetch_quakeml(
*,
starttime: Timestamp | None = None,
endtime: Timestamp | None = None,
updatedafter: Timestamp | None = None,
minlatitude: float | None = None,
maxlatitude: float | None = None,
minlongitude: float | None = None,
maxlongitude: float | None = None,
latitude: float | None = None,
longitude: float | None = None,
minradius: float | None = None,
maxradius: float | None = None,
mindepth_km: float | None = None,
maxdepth_km: float | None = None,
minmagnitude: float | None = None,
maxmagnitude: float | None = None,
magnitudetype: str | None = None,
eventtype: str | None = None,
eventid: str | None = None,
limit: int | None = None,
offset: int | None = None,
orderby: QuakeMLOrderBy | None = None,
catalog: str | None = None,
contributor: str | None = None
) -> bytes
Fetch raw QuakeML 1.2 event metadata bytes from the USGS fdsnws-event service.
A lower-level counterpart to
QuakeML.all_from_query: returns
the QuakeML document unparsed. All parameters are optional;
fetch_quakeml() with no arguments is a valid "everything" request,
bounded only by the service's own limits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
starttime
|
Timestamp | None
|
Keep events at or after this origin time (UTC). |
None
|
endtime
|
Timestamp | None
|
Keep events at or before this origin time (UTC). |
None
|
updatedafter
|
Timestamp | None
|
Keep events modified after this time (UTC). |
None
|
minlatitude
|
float | None
|
Southern edge of a bounding box, in degrees. |
None
|
maxlatitude
|
float | None
|
Northern edge of a bounding box, in degrees. |
None
|
minlongitude
|
float | None
|
Western edge of a bounding box, in degrees. |
None
|
maxlongitude
|
float | None
|
Eastern edge of a bounding box, in degrees. |
None
|
latitude
|
float | None
|
Centre latitude for a radial search, in degrees. |
None
|
longitude
|
float | None
|
Centre longitude for a radial search, in degrees. |
None
|
minradius
|
float | None
|
Inner radius for a radial search, in degrees. |
None
|
maxradius
|
float | None
|
Outer radius for a radial search, in degrees. |
None
|
mindepth_km
|
float | None
|
Minimum event depth, in kilometres (the
fdsnws-event filter unit; the parsed
|
None
|
maxdepth_km
|
float | None
|
Maximum event depth, in kilometres. |
None
|
minmagnitude
|
float | None
|
Minimum event magnitude. |
None
|
maxmagnitude
|
float | None
|
Maximum event magnitude. |
None
|
magnitudetype
|
str | None
|
Magnitude type to filter on (e.g. |
None
|
eventtype
|
str | None
|
QuakeML event type, or a comma-separated list of them. |
None
|
eventid
|
str | None
|
Select a single event by the service's event id. |
None
|
limit
|
int | None
|
Maximum number of events to return. |
None
|
offset
|
int | None
|
Return events starting from this 1-based position. |
None
|
orderby
|
QuakeMLOrderBy | None
|
Sort order, one of |
None
|
catalog
|
str | None
|
Restrict to a named catalog. |
None
|
contributor
|
str | None
|
Restrict to a named contributor. |
None
|
Returns:
| Type | Description |
|---|---|
bytes
|
Raw QuakeML 1.2 document bytes. |
Raises:
| Type | Description |
|---|---|
ResponseError
|
If the event web service returns an HTTP error, including a 404 when no event matches. |
Examples:
>>> import pandas as pd
>>> from pathlib import Path
>>> from pysmo.tools.web import fetch_quakeml
>>> xml = fetch_quakeml(
... starttime=pd.Timestamp("2010-02-27T00:00:00Z"),
... endtime=pd.Timestamp("2010-02-28T00:00:00Z"),
... minmagnitude=8.0,
... )
>>> _ = Path("maule.quakeml").write_bytes(xml)
>>>
Source code in src/pysmo/tools/web.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
fetch_sac
Fetch a raw SAC zip archive for a station/channel and time window.
A lower-level counterpart to SAC.fetch:
returns the zip archive returned by the dataselect web service
unparsed and uninterpreted, without extracting or reading any of its
members. Save it to disk to defer parsing to later (offline, without another
network request) via
SAC.from_zip or
SAC.all_from_zip.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
station
|
Station
|
Any object satisfying the |
required |
starttime
|
Timestamp
|
Start of the requested time window (UTC). |
required |
endtime
|
Timestamp
|
End of the requested time window (UTC). |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
Raw zip archive bytes, as returned by the dataselect web service. |
Raises:
| Type | Description |
|---|---|
ResponseError
|
If the dataselect web service returns an HTTP error. |
Examples:
>>> import pandas as pd
>>> from pathlib import Path
>>> from pysmo import MiniStation
>>> from pysmo.tools.web import fetch_sac
>>> station = MiniStation(
... name="ANMO", network="IU", location="00", channel="LHZ",
... latitude=34.945981, longitude=-106.457133,
... )
>>> data = fetch_sac(
... station=station,
... starttime=pd.Timestamp("2010-02-27T06:44:00Z"),
... endtime=pd.Timestamp("2010-02-27T06:54:00Z"),
... )
>>> _ = Path("ANMO.sac.zip").write_bytes(data)
>>>
Source code in src/pysmo/tools/web.py
fetch_sacpz
Fetch raw SAC PZ response metadata text for a station/channel.
Fetched from fdsnws-station with level=response&format=sacpz,
EarthScope's designated replacement for the irisws-sacpz service.
A lower-level counterpart to
SacPZ.fetch: returns the response
metadata unparsed and uninterpreted. Save it to disk to defer parsing
to later (offline, without another network request) via
SacPZ.from_text or
SacPZ.all_from_text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
station
|
Station
|
Any object satisfying the |
required |
time
|
Timestamp | None
|
Timestamp used to select the response epoch server-side, so
exactly one epoch is returned. If |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Raw SAC PZ text. |
Raises:
| Type | Description |
|---|---|
ResponseError
|
If the web service returns an HTTP error. |
Examples:
>>> from pathlib import Path
>>> from pysmo import MiniStation
>>> from pysmo.tools.web import fetch_sacpz
>>> station = MiniStation(
... name="ANMO", network="IU", location="00", channel="BHZ",
... latitude=34.945981, longitude=-106.457133,
... )
>>> text = fetch_sacpz(station=station)
>>> _ = Path("ANMO.pz").write_text(text)
>>>
Source code in src/pysmo/tools/web.py
fetch_station_inventory
fetch_station_inventory(
*,
network: str,
station: str = "*",
location: str = "*",
channel: str,
starttime: Timestamp | None = None,
endtime: Timestamp | None = None,
updatedafter: Timestamp | None = None,
minlatitude: float | None = None,
maxlatitude: float | None = None,
minlongitude: float | None = None,
maxlongitude: float | None = None,
latitude: float | None = None,
longitude: float | None = None,
minradius: float | None = None,
maxradius: float | None = None,
includerestricted: bool | None = None,
matchtimeseries: bool | None = None
) -> bytes
Fetch raw FDSN StationXML inventory bytes from EarthScope's fdsnws-station.
A bulk, query-style counterpart to
fetch_stationxml (which is
single-station and level=response). Returns a level=channel
document covering every <Channel> epoch matching the query; parse it
with StationXML.all_from_bytes
and narrow in memory (the results carry no response).
network and channel are required (a query without them attempts to
download the entire global inventory); station and location default
to the FDSN "any" wildcard. Selection strings are sent verbatim, so the
service's native comma-lists and * / ? wildcards work
(network="IU,II", channel="BH?").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
str
|
Network code(s); comma-list and |
required |
station
|
str
|
Station code(s), defaulting to all. |
'*'
|
location
|
str
|
Location code(s), defaulting to all. |
'*'
|
channel
|
str
|
Channel code(s); comma-list and wildcards allowed. |
required |
starttime
|
Timestamp | None
|
Keep metadata epochs intersecting at or after this time (UTC). Does not collapse to one epoch per channel. |
None
|
endtime
|
Timestamp | None
|
Keep metadata epochs intersecting at or before this time (UTC). |
None
|
updatedafter
|
Timestamp | None
|
Keep metadata modified after this time (UTC). |
None
|
minlatitude
|
float | None
|
Southern edge of a bounding box, in degrees. |
None
|
maxlatitude
|
float | None
|
Northern edge of a bounding box, in degrees. |
None
|
minlongitude
|
float | None
|
Western edge of a bounding box, in degrees. |
None
|
maxlongitude
|
float | None
|
Eastern edge of a bounding box, in degrees. |
None
|
latitude
|
float | None
|
Centre latitude for a radial search, in degrees. |
None
|
longitude
|
float | None
|
Centre longitude for a radial search, in degrees. |
None
|
minradius
|
float | None
|
Inner radius for a radial search, in degrees. |
None
|
maxradius
|
float | None
|
Outer radius for a radial search, in degrees. |
None
|
includerestricted
|
bool | None
|
Include metadata for restricted stations
(service default is |
None
|
matchtimeseries
|
bool | None
|
Limit to metadata with recoverable timeseries data
(service default is |
None
|
Returns:
| Type | Description |
|---|---|
bytes
|
Raw StationXML document bytes. |
Raises:
| Type | Description |
|---|---|
ResponseError
|
If the station web service returns an HTTP error, including a 404 when nothing matches. |
Examples:
>>> from pathlib import Path
>>> from pysmo.tools.web import fetch_station_inventory
>>> xml = fetch_station_inventory(network="IU", station="ANMO", channel="BHZ")
>>> _ = Path("iu_anmo.xml").write_bytes(xml)
>>>
Source code in src/pysmo/tools/web.py
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 | |
fetch_stationxml
Fetch raw StationXML response metadata bytes for a station/channel.
A lower-level counterpart to
StationXML.fetch: returns the
StationXML document unparsed and uninterpreted, covering every response
epoch on record for the requested channel. Save it to disk to defer
parsing to later (offline, without another network request) via
StationXML.from_bytes or
StationXML.all_from_bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
station
|
Station
|
Any object satisfying the |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
Raw StationXML document bytes. |
Raises:
| Type | Description |
|---|---|
ResponseError
|
If the station web service returns an HTTP error. |
Examples:
>>> from pathlib import Path
>>> from pysmo import MiniStation
>>> from pysmo.tools.web import fetch_stationxml
>>> station = MiniStation(
... name="ANMO", network="IU", location="00", channel="BHZ",
... latitude=34.945981, longitude=-106.457133,
... )
>>> xml = fetch_stationxml(station=station)
>>> _ = Path("ANMO.xml").write_bytes(xml)
>>>