pysmo.lib
Internal utilities, validators, defaults, and I/O used by pysmo.
Modules:
| Name | Description |
|---|---|
defaults |
Default values for pysmo's functions and classes. |
io |
Low-level I/O classes for reading and writing seismological data. |
mini_utils |
Match objects and protocols to pysmo's Mini classes. |
validators |
Validators and converters for pysmo's |
defaults
Default values for pysmo's functions and classes.
io
Low-level I/O classes for reading and writing seismological data.
Classes in this module handle file format details but do not implement
pysmo protocol types directly. The parse_* functions here return
uninterpreted raw records meant to be wrapped by a pysmo.classes type
before use, and should generally not be used directly for that reason.
write_geocsv and
write_mseed are the exception: they accept any
object satisfying the relevant pysmo protocol directly (not just a
pysmo.classes type) and are intended to be used directly, either standalone
or via GeoCsvSeismogram.write /
MSeed.write.
Classes:
| Name | Description |
|---|---|
GeoCsvDataset |
A single uninterpreted dataset from a GeoCSV text body. |
SacIO |
Access SAC files in Python. |
Functions:
| Name | Description |
|---|---|
extract_geocsv_timeseries |
Interpret a GeoCSV dataset as a waveform segment. |
http_get |
Perform an HTTP GET request, retrying transient failures. |
merge_geocsv_timeseries |
Merge contiguous waveform segments into a single segment. |
parse_geocsv |
Split a GeoCSV text body into a list of datasets. |
parse_quakeml |
Parse the event hypocentre and origin time from a QuakeML 1.2 document. |
parse_sacpz |
Split SAC PZ text into a list of uninterpreted records. |
parse_stationxml |
Parse station identity, coordinates and response from a StationXML document. |
write_geocsv |
Write one or more Seismogram objects to a GeoCSV 2.0 file. |
write_mseed |
Write one or more waveform segments to a miniSEED file. |
GeoCsvDataset
dataclass
A single uninterpreted dataset from a GeoCSV text body.
Attributes:
| Name | Type | Description |
|---|---|---|
column_names |
list[str]
|
Field names from the header line. |
delimiter |
str
|
Field delimiter for this dataset (defaults to a comma). |
headers |
dict[str, str]
|
Keyword comment values, keyed by lowercased keyword. |
rows |
list[list[str]]
|
Data lines split on the dataset delimiter, values stripped of |
Source code in src/pysmo/lib/io/_geocsv.py
column_names
class-attribute
instance-attribute
Field names from the header line.
headers
class-attribute
instance-attribute
Keyword comment values, keyed by lowercased keyword.
SacIO
Bases: SacIOBase
Access SAC files in Python.
The SacIO class reads and writes data and header values to and from a
SAC file. Instances of SacIO provide attributes named identically to
header names in the SAC file format. Additional attributes may be set, but
are not written to a SAC file (because there is no space reserved for them
there). Class attributes with corresponding header fields in a SAC file
(for example the begin time b) are checked for a
valid format before being saved in the SacIO instance.
For advanced use cases only
This class should typically never be used directly. Instead use the
SAC class, which wraps a SacIO instance
(reachable as SAC.native) and exposes it
through pysmo types.
Examples:
Create a new instance from a file and print seismogram data:
>>> from pysmo.lib.io import SacIO
>>> sac = SacIO.from_file("example.sac")
>>> data = sac.data
>>> data
array([-47201., -47361., -47511., ..., -82144., -71072., -59960.],
shape=(57465,))
>>>
Read the sampling rate:
Change the sampling rate:
Methods:
| Name | Description |
|---|---|
change_ref_time |
Re-point the reference time to a different time header. |
from_buffer |
Create a new SAC instance from a SAC data buffer. |
from_file |
Create a new SAC instance from a SAC file. |
raw |
Temporarily relax cross-field header restrictions on this instance. |
read |
Read data and headers from a SAC file into an existing SAC instance. |
read_buffer |
Read data and headers from a SAC byte buffer into an existing SAC instance. |
write |
Write data and headers to a SAC file. |
Attributes:
| Name | Type | Description |
|---|---|---|
a |
float | None
|
First arrival time (seconds relative to reference time). |
az |
int | float
|
Event to station azimuth (degrees). |
b |
float
|
Beginning value of the independent variable. |
baz |
int | float
|
Station to event azimuth (degrees). |
cmpaz |
float | None
|
Component azimuth (degrees clockwise from north). |
cmpinc |
float | None
|
Component incident angle (degrees from upward vertical; SEED/MINISEED uses dip: degrees from horizontal down). |
data |
NDArray[floating]
|
Seismogram data. |
data2 |
NDArray[floating]
|
Second data section (real/imaginary, amplitude/phase, or independent |
delta |
float
|
Increment between evenly spaced samples (nominal value). |
depmax |
int | float | None
|
Maximum value of dependent variable. |
depmen |
int | float | None
|
Mean value of dependent variable. |
depmin |
int | float | None
|
Minimum value of dependent variable. |
dist |
int | float
|
Station to event distance (km). |
e |
int | float
|
Ending value of the independent variable. |
evdp |
float | None
|
Event depth below surface (kilometres; previously metres). |
evel |
float | None
|
Event elevation (metres). |
evla |
float | None
|
Event latitude (degrees, north positive). |
evlo |
float | None
|
Event longitude (degrees, east positive). |
f |
float | None
|
Fini or end of event time (seconds relative to reference time). |
gcarc |
int | float
|
Station to event great circle arc length (degrees). |
ibody |
str | None
|
Body / Spheroid definition used in Distance Calculations. |
idep |
str
|
Type of dependent variable. |
ievreg |
str | None
|
Event geographic region. |
ievtyp |
str
|
Type of event. |
iftype |
str
|
Type of file. |
iinst |
str | None
|
Type of recording instrument. |
imagsrc |
str | None
|
Source of magnitude information. |
imagtyp |
str | None
|
Magnitude type. |
iqual |
str | None
|
Quality of data. |
istreg |
str | None
|
Station geographic region. |
isynth |
str | None
|
Synthetic data flag. |
iztype |
str
|
Reference time equivalence. Read-only; changed via |
ka |
str | None
|
First arrival time identification. |
kcmpnm |
str | None
|
Channel name. SEED volumes use three character names, and the third is the component/orientation. For horizontals, the current trend is to use 1 and 2 instead of N and E. |
kdatrd |
str | None
|
Date data was read onto computer. |
kevnm |
str | None
|
Event name. |
kf |
str | None
|
Fini identification. |
khole |
str | None
|
Nuclear: hole identifier; Other: location identifier (LOCID). |
kinst |
str | None
|
Generic name of recording instrument. |
knetwk |
str | None
|
Name of seismic network. |
ko |
str | None
|
Event origin time identification. |
kstnm |
str | None
|
Station name. |
kt0 |
str | None
|
User defined time pick identification. |
kt1 |
str | None
|
User defined time pick identification. |
kt2 |
str | None
|
User defined time pick identification. |
kt3 |
str | None
|
User defined time pick identification. |
kt4 |
str | None
|
User defined time pick identification. |
kt5 |
str | None
|
User defined time pick identification. |
kt6 |
str | None
|
User defined time pick identification. |
kt7 |
str | None
|
User defined time pick identification. |
kt8 |
str | None
|
User defined time pick identification. |
kt9 |
str | None
|
User defined time pick identification. |
kuser0 |
str | None
|
User defined variable storage area. |
kuser1 |
str | None
|
User defined variable storage area. |
kuser2 |
str | None
|
User defined variable storage area. |
kzdate |
str | None
|
ISO 8601 format of GMT reference date. |
kztime |
str | None
|
Alphanumeric form of GMT reference time. |
lcalda |
Literal[True]
|
TRUE if DIST, AZ, BAZ, and GCARC are computed from station/event coordinates. |
leven |
bool
|
TRUE if data is evenly spaced. |
lovrok |
bool | None
|
TRUE if it is okay to overwrite this file on disk. |
lpspol |
bool | None
|
TRUE if station components have a positive polarity (left-hand rule). |
mag |
float | None
|
Event magnitude. |
nevid |
int | None
|
Event ID (CSS 3.0). |
norid |
int | None
|
Origin ID (CSS 3.0). |
npts |
int
|
Number of points per data component. |
nsnpts |
int | None
|
Number of points of original time series file (Stored NPTS). Only meaningful when NVHDR=7 (this word is unused/internal otherwise). |
nvhdr |
int
|
Header version number. |
nwfid |
int | None
|
Waveform ID (CSS 3.0). |
nxsize |
int | None
|
Spectral Length (Spectral files only). |
nysize |
int | None
|
Spectral Width (Spectral files only). |
nzhour |
int | None
|
GMT hour. |
nzjday |
int | None
|
GMT julian day. |
nzmin |
int | None
|
GMT minute. |
nzmsec |
int | None
|
GMT millisecond. |
nzsec |
int | None
|
GMT second. |
nzyear |
int | None
|
GMT year corresponding to reference (zero) time in file. |
o |
float | None
|
Event origin time (seconds relative to reference time). |
odelta |
float | None
|
Observed increment if different from nominal value. |
ref_datetime |
datetime | None
|
GMT reference time and date, as a Python |
resp0 |
float | None
|
Instrument response parameter 0 (not currently used). |
resp1 |
float | None
|
Instrument response parameter 1 (not currently used). |
resp2 |
float | None
|
Instrument response parameter 2 (not currently used). |
resp3 |
float | None
|
Instrument response parameter 3 (not currently used). |
resp4 |
float | None
|
Instrument response parameter 4 (not currently used). |
resp5 |
float | None
|
Instrument response parameter 5 (not currently used). |
resp6 |
float | None
|
Instrument response parameter 6 (not currently used). |
resp7 |
float | None
|
Instrument response parameter 7 (not currently used). |
resp8 |
float | None
|
Instrument response parameter 8 (not currently used). |
resp9 |
float | None
|
Instrument response parameter 9 (not currently used). |
sb |
float | None
|
Begin value of the original time series file (Stored B). |
sdelta |
float | None
|
Time increment in the original time series file (Stored DELTA). |
stdp |
float | None
|
Station depth below surface (metres). |
stel |
float | None
|
Station elevation above sea level (metres). |
stla |
float | None
|
Station latitude (degrees, north positive). |
stlo |
float | None
|
Station longitude (degrees, east positive). |
t0 |
float | None
|
User defined time pick or marker 0 (seconds relative to reference time). |
t1 |
float | None
|
User defined time pick or marker 1 (seconds relative to reference time). |
t2 |
float | None
|
User defined time pick or marker 2 (seconds relative to reference time). |
t3 |
float | None
|
User defined time pick or marker 3 (seconds relative to reference time). |
t4 |
float | None
|
User defined time pick or marker 4 (seconds relative to reference time). |
t5 |
float | None
|
User defined time pick or marker 5 (seconds relative to reference time). |
t6 |
float | None
|
User defined time pick or marker 6 (seconds relative to reference time). |
t7 |
float | None
|
User defined time pick or marker 7 (seconds relative to reference time). |
t8 |
float | None
|
User defined time pick or marker 8 (seconds relative to reference time). |
t9 |
float | None
|
User defined time pick or marker 9 (seconds relative to reference time). |
user0 |
float | None
|
User defined variable storage area. |
user1 |
float | None
|
User defined variable storage area. |
user2 |
float | None
|
User defined variable storage area. |
user3 |
float | None
|
User defined variable storage area. |
user4 |
float | None
|
User defined variable storage area. |
user5 |
float | None
|
User defined variable storage area. |
user6 |
float | None
|
User defined variable storage area. |
user7 |
float | None
|
User defined variable storage area. |
user8 |
float | None
|
User defined variable storage area. |
user9 |
float | None
|
User defined variable storage area. |
xmaximum |
int | float | None
|
Maximum value of X (Spectral files only). |
xminimum |
int | float | None
|
Minimum value of X (Spectral files only). |
ymaximum |
int | float | None
|
Maximum value of Y (Spectral files only). |
yminimum |
int | float | None
|
Minimum value of Y (Spectral files only). |
Source code in src/pysmo/lib/io/_sacio/sacio.py
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 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 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 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 508 509 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 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 | |
a
class-attribute
instance-attribute
a: float | None = field(
default=None,
converter=_convert_a,
validator=validators.optional(
validators.and_(
validators.instance_of(float),
_validate_with_iztype,
)
),
)
First arrival time (seconds relative to reference time).
b
class-attribute
instance-attribute
b: float = field(
default=SacIODefaults.b,
converter=_convert_b,
validator=validators.and_(
validators.instance_of(float), _validate_with_iztype
),
)
Beginning value of the independent variable.
cmpaz
class-attribute
instance-attribute
cmpaz: float | None = field(
default=None,
converter=_convert_cmpaz,
validator=validators.optional(
validators.instance_of(float)
),
)
Component azimuth (degrees clockwise from north).
cmpinc
class-attribute
instance-attribute
cmpinc: float | None = field(
default=None,
converter=_convert_cmpinc,
validator=validators.optional(
validators.instance_of(float)
),
)
Component incident angle (degrees from upward vertical; SEED/MINISEED uses dip: degrees from horizontal down).
data
class-attribute
instance-attribute
data: NDArray[floating] = field(
factory=lambda: np.array([]),
converter=convert_to_ndarray,
validator=validators.instance_of(np.ndarray),
on_setattr=setters.pipe(
setters.convert, setters.validate
),
)
Seismogram data.
data2
class-attribute
instance-attribute
data2: NDArray[floating] = field(
factory=lambda: np.array([]),
converter=convert_to_ndarray,
validator=validators.instance_of(np.ndarray),
on_setattr=setters.pipe(
setters.convert, setters.validate
),
)
Second data section (real/imaginary, amplitude/phase, or independent variable, depending on IFTYPE). Empty for evenly-spaced ITIME files, which have only one data section.
delta
class-attribute
instance-attribute
delta: float = field(
default=SacIODefaults.delta,
converter=_convert_delta,
validator=validators.instance_of(float),
)
Increment between evenly spaced samples (nominal value).
evdp
class-attribute
instance-attribute
evdp: float | None = field(
default=None,
converter=_convert_evdp,
validator=validators.optional(
validators.instance_of(float)
),
)
Event depth below surface (kilometres; previously metres).
evel
class-attribute
instance-attribute
evel: float | None = field(
default=None,
converter=_convert_evel,
validator=validators.optional(
validators.instance_of(float)
),
)
Event elevation (metres).
evla
class-attribute
instance-attribute
evla: float | None = field(
default=None,
converter=converters.optional(float),
validator=validators.optional(
validators.and_(
validators.instance_of(float),
validators.ge(-90),
validators.le(90),
)
),
)
Event latitude (degrees, north positive).
evlo
class-attribute
instance-attribute
evlo: float | None = field(
default=None,
converter=converters.optional(float),
validator=validators.optional(
validators.and_(
validators.instance_of(float),
validators.ge(-180),
validators.le(180),
)
),
)
Event longitude (degrees, east positive).
f
class-attribute
instance-attribute
f: float | None = field(
default=None,
converter=_convert_f,
validator=validators.optional(
validators.and_(
validators.instance_of(float),
_validate_with_iztype,
)
),
)
Fini or end of event time (seconds relative to reference time).
ibody
class-attribute
instance-attribute
ibody: str | None = field(
default=None,
validator=validators.optional(_validate_sacenum),
)
Body / Spheroid definition used in Distance Calculations.
idep
class-attribute
instance-attribute
Type of dependent variable.
ievreg
class-attribute
instance-attribute
ievreg: str | None = field(
default=None,
converter=_convert_ievreg,
validator=validators.optional(
validators.and_(
validators.instance_of(str),
validators.max_len(4),
)
),
)
Event geographic region.
ievtyp
class-attribute
instance-attribute
Type of event.
iftype
class-attribute
instance-attribute
Type of file.
iinst
class-attribute
instance-attribute
iinst: str | None = field(
default=None,
converter=_convert_iinst,
validator=validators.optional(
validators.and_(
validators.instance_of(str),
validators.max_len(4),
)
),
)
Type of recording instrument.
imagsrc
class-attribute
instance-attribute
imagsrc: str | None = field(
default=None,
validator=validators.optional(_validate_sacenum),
)
Source of magnitude information.
imagtyp
class-attribute
instance-attribute
imagtyp: str | None = field(
default=None,
validator=validators.optional(_validate_sacenum),
)
Magnitude type.
iqual
class-attribute
instance-attribute
iqual: str | None = field(
default=None,
validator=validators.optional(_validate_sacenum),
)
Quality of data.
istreg
class-attribute
instance-attribute
istreg: str | None = field(
default=None,
converter=_convert_istreg,
validator=validators.optional(
validators.and_(
validators.instance_of(str),
validators.max_len(4),
)
),
)
Station geographic region.
isynth
class-attribute
instance-attribute
isynth: str | None = field(
default=None,
validator=validators.optional(_validate_sacenum),
)
Synthetic data flag.
iztype
class-attribute
instance-attribute
iztype: str = field(
default=SacIODefaults.iztype,
validator=_validate_sacenum,
on_setattr=setters.frozen,
)
Reference time equivalence. Read-only; changed via SacIO.change_ref_time.
ka
class-attribute
instance-attribute
ka: str | None = field(
default=None,
converter=_convert_ka,
validator=validators.optional(
validators.and_(
validators.instance_of(str),
validators.max_len(8),
)
),
)
First arrival time identification.
kcmpnm
class-attribute
instance-attribute
kcmpnm: str | None = field(
default=None,
converter=_convert_kcmpnm,
validator=validators.optional(
validators.and_(
validators.instance_of(str),
validators.max_len(8),
)
),
)
Channel name. SEED volumes use three character names, and the third is the component/orientation. For horizontals, the current trend is to use 1 and 2 instead of N and E.
kdatrd
class-attribute
instance-attribute
kdatrd: str | None = field(
default=None,
converter=_convert_kdatrd,
validator=validators.optional(
validators.and_(
validators.instance_of(str),
validators.max_len(8),
)
),
)
Date data was read onto computer.
kevnm
class-attribute
instance-attribute
kevnm: str | None = field(
default=None,
converter=_convert_kevnm,
validator=validators.optional(
validators.and_(
validators.instance_of(str),
validators.max_len(16),
)
),
)
Event name.
kf
class-attribute
instance-attribute
kf: str | None = field(
default=None,
converter=_convert_kf,
validator=validators.optional(
validators.and_(
validators.instance_of(str),
validators.max_len(8),
)
),
)
Fini identification.
khole
class-attribute
instance-attribute
khole: str | None = field(
default=None,
converter=_convert_khole,
validator=validators.optional(
validators.and_(
validators.instance_of(str),
validators.max_len(8),
)
),
)
Nuclear: hole identifier; Other: location identifier (LOCID).
kinst
class-attribute
instance-attribute
kinst: str | None = field(
default=None,
converter=_convert_kinst,
validator=validators.optional(
validators.and_(
validators.instance_of(str),
validators.max_len(8),
)
),
)
Generic name of recording instrument.
knetwk
class-attribute
instance-attribute
knetwk: str | None = field(
default=None,
converter=_convert_knetwk,
validator=validators.optional(
validators.and_(
validators.instance_of(str),
validators.max_len(8),
)
),
)
Name of seismic network.
ko
class-attribute
instance-attribute
ko: str | None = field(
default=None,
converter=_convert_ko,
validator=validators.optional(
validators.and_(
validators.instance_of(str),
validators.max_len(8),
)
),
)
Event origin time identification.
kstnm
class-attribute
instance-attribute
kstnm: str | None = field(
default=None,
converter=_convert_kstnm,
validator=validators.optional(
validators.and_(
validators.instance_of(str),
validators.max_len(8),
)
),
)
Station name.
kt0
class-attribute
instance-attribute
kt0: str | None = field(
default=None,
converter=_convert_kt0,
validator=validators.optional(
validators.and_(
validators.instance_of(str),
validators.max_len(8),
)
),
)
User defined time pick identification.
kt1
class-attribute
instance-attribute
kt1: str | None = field(
default=None,
converter=_convert_kt1,
validator=validators.optional(
validators.and_(
validators.instance_of(str),
validators.max_len(8),
)
),
)
User defined time pick identification.
kt2
class-attribute
instance-attribute
kt2: str | None = field(
default=None,
converter=_convert_kt2,
validator=validators.optional(
validators.and_(
validators.instance_of(str),
validators.max_len(8),
)
),
)
User defined time pick identification.
kt3
class-attribute
instance-attribute
kt3: str | None = field(
default=None,
converter=_convert_kt3,
validator=validators.optional(
validators.and_(
validators.instance_of(str),
validators.max_len(8),
)
),
)
User defined time pick identification.
kt4
class-attribute
instance-attribute
kt4: str | None = field(
default=None,
converter=_convert_kt4,
validator=validators.optional(
validators.and_(
validators.instance_of(str),
validators.max_len(8),
)
),
)
User defined time pick identification.
kt5
class-attribute
instance-attribute
kt5: str | None = field(
default=None,
converter=_convert_kt5,
validator=validators.optional(
validators.and_(
validators.instance_of(str),
validators.max_len(8),
)
),
)
User defined time pick identification.
kt6
class-attribute
instance-attribute
kt6: str | None = field(
default=None,
converter=_convert_kt6,
validator=validators.optional(
validators.and_(
validators.instance_of(str),
validators.max_len(8),
)
),
)
User defined time pick identification.
kt7
class-attribute
instance-attribute
kt7: str | None = field(
default=None,
converter=_convert_kt7,
validator=validators.optional(
validators.and_(
validators.instance_of(str),
validators.max_len(8),
)
),
)
User defined time pick identification.
kt8
class-attribute
instance-attribute
kt8: str | None = field(
default=None,
converter=_convert_kt8,
validator=validators.optional(
validators.and_(
validators.instance_of(str),
validators.max_len(8),
)
),
)
User defined time pick identification.
kt9
class-attribute
instance-attribute
kt9: str | None = field(
default=None,
converter=_convert_kt9,
validator=validators.optional(
validators.and_(
validators.instance_of(str),
validators.max_len(8),
)
),
)
User defined time pick identification.
kuser0
class-attribute
instance-attribute
kuser0: str | None = field(
default=None,
converter=_convert_kuser0,
validator=validators.optional(
validators.and_(
validators.instance_of(str),
validators.max_len(8),
)
),
)
User defined variable storage area.
kuser1
class-attribute
instance-attribute
kuser1: str | None = field(
default=None,
converter=_convert_kuser1,
validator=validators.optional(
validators.and_(
validators.instance_of(str),
validators.max_len(8),
)
),
)
User defined variable storage area.
kuser2
class-attribute
instance-attribute
kuser2: str | None = field(
default=None,
converter=_convert_kuser2,
validator=validators.optional(
validators.and_(
validators.instance_of(str),
validators.max_len(8),
)
),
)
User defined variable storage area.
lcalda
property
lcalda: Literal[True]
TRUE if DIST, AZ, BAZ, and GCARC are computed from station/event coordinates.
Always calculated, never stored
Above fields are all read only properties in this class, so they are always calculated.
leven
class-attribute
instance-attribute
leven: bool = field(
default=SacIODefaults.leven,
validator=validators.instance_of(bool),
)
TRUE if data is evenly spaced.
lovrok
class-attribute
instance-attribute
lovrok: bool | None = field(
default=None,
validator=validators.optional(
validators.instance_of(bool)
),
)
TRUE if it is okay to overwrite this file on disk.
lpspol
class-attribute
instance-attribute
lpspol: bool | None = field(
default=None,
validator=validators.optional(
validators.instance_of(bool)
),
)
TRUE if station components have a positive polarity (left-hand rule).
mag
class-attribute
instance-attribute
mag: float | None = field(
default=None,
converter=_convert_mag,
validator=validators.optional(
validators.instance_of(float)
),
)
Event magnitude.
nevid
class-attribute
instance-attribute
nevid: int | None = field(
default=None,
converter=_convert_nevid,
validator=validators.optional(
validators.instance_of(int)
),
)
Event ID (CSS 3.0).
norid
class-attribute
instance-attribute
norid: int | None = field(
default=None,
converter=_convert_norid,
validator=validators.optional(
validators.instance_of(int)
),
)
Origin ID (CSS 3.0).
nsnpts
class-attribute
instance-attribute
nsnpts: int | None = field(
default=None,
converter=_convert_nsnpts,
validator=validators.optional(
validators.instance_of(int)
),
)
Number of points of original time series file (Stored NPTS). Only meaningful when NVHDR=7 (this word is unused/internal otherwise).
nvhdr
class-attribute
instance-attribute
nvhdr: int = field(
default=SacIODefaults.nvhdr,
converter=_convert_nvhdr,
validator=validators.instance_of(int),
)
Header version number.
nwfid
class-attribute
instance-attribute
nwfid: int | None = field(
default=None,
converter=_convert_nwfid,
validator=validators.optional(
validators.instance_of(int)
),
)
Waveform ID (CSS 3.0).
nzhour
class-attribute
instance-attribute
nzhour: int | None = field(
default=None,
converter=_convert_nzhour,
validator=validators.optional(
validators.instance_of(int)
),
)
GMT hour.
nzjday
class-attribute
instance-attribute
nzjday: int | None = field(
default=None,
converter=_convert_nzjday,
validator=validators.optional(
validators.instance_of(int)
),
)
GMT julian day.
nzmin
class-attribute
instance-attribute
nzmin: int | None = field(
default=None,
converter=_convert_nzmin,
validator=validators.optional(
validators.instance_of(int)
),
)
GMT minute.
nzmsec
class-attribute
instance-attribute
nzmsec: int | None = field(
default=None,
converter=_convert_nzmsec,
validator=validators.optional(
validators.instance_of(int)
),
)
GMT millisecond.
nzsec
class-attribute
instance-attribute
nzsec: int | None = field(
default=None,
converter=_convert_nzsec,
validator=validators.optional(
validators.instance_of(int)
),
)
GMT second.
nzyear
class-attribute
instance-attribute
nzyear: int | None = field(
default=None,
converter=_convert_nzyear,
validator=validators.optional(
validators.instance_of(int)
),
)
GMT year corresponding to reference (zero) time in file.
o
class-attribute
instance-attribute
o: float | None = field(
default=None,
converter=_convert_o,
validator=validators.optional(
validators.and_(
validators.instance_of(float),
_validate_with_iztype,
)
),
)
Event origin time (seconds relative to reference time).
odelta
class-attribute
instance-attribute
odelta: float | None = field(
default=None,
converter=_convert_odelta,
validator=validators.optional(
validators.instance_of(float)
),
)
Observed increment if different from nominal value.
ref_datetime
property
writable
ref_datetime: datetime | None
resp0
class-attribute
instance-attribute
resp0: float | None = field(
default=None,
converter=_convert_resp0,
validator=validators.optional(
validators.instance_of(float)
),
)
Instrument response parameter 0 (not currently used).
resp1
class-attribute
instance-attribute
resp1: float | None = field(
default=None,
converter=_convert_resp1,
validator=validators.optional(
validators.instance_of(float)
),
)
Instrument response parameter 1 (not currently used).
resp2
class-attribute
instance-attribute
resp2: float | None = field(
default=None,
converter=_convert_resp2,
validator=validators.optional(
validators.instance_of(float)
),
)
Instrument response parameter 2 (not currently used).
resp3
class-attribute
instance-attribute
resp3: float | None = field(
default=None,
converter=_convert_resp3,
validator=validators.optional(
validators.instance_of(float)
),
)
Instrument response parameter 3 (not currently used).
resp4
class-attribute
instance-attribute
resp4: float | None = field(
default=None,
converter=_convert_resp4,
validator=validators.optional(
validators.instance_of(float)
),
)
Instrument response parameter 4 (not currently used).
resp5
class-attribute
instance-attribute
resp5: float | None = field(
default=None,
converter=_convert_resp5,
validator=validators.optional(
validators.instance_of(float)
),
)
Instrument response parameter 5 (not currently used).
resp6
class-attribute
instance-attribute
resp6: float | None = field(
default=None,
converter=_convert_resp6,
validator=validators.optional(
validators.instance_of(float)
),
)
Instrument response parameter 6 (not currently used).
resp7
class-attribute
instance-attribute
resp7: float | None = field(
default=None,
converter=_convert_resp7,
validator=validators.optional(
validators.instance_of(float)
),
)
Instrument response parameter 7 (not currently used).
resp8
class-attribute
instance-attribute
resp8: float | None = field(
default=None,
converter=_convert_resp8,
validator=validators.optional(
validators.instance_of(float)
),
)
Instrument response parameter 8 (not currently used).
resp9
class-attribute
instance-attribute
resp9: float | None = field(
default=None,
converter=_convert_resp9,
validator=validators.optional(
validators.instance_of(float)
),
)
Instrument response parameter 9 (not currently used).
sb
class-attribute
instance-attribute
sb: float | None = field(
default=None,
converter=converters.optional(float),
validator=validators.optional(
validators.instance_of(float)
),
)
Begin value of the original time series file (Stored B).
Only present in v7 spectral files
Only present in v7 files, and only meaningful for spectral
(IRLIM/IAMPH) files produced by a forward Fourier transform. Has no
corresponding header field of its own; it exists only in the v7
footer, unlike headers such as b that also
have a single-precision header slot.
sdelta
class-attribute
instance-attribute
sdelta: float | None = field(
default=None,
converter=converters.optional(float),
validator=validators.optional(
validators.instance_of(float)
),
)
Time increment in the original time series file (Stored DELTA).
Only present in v7 spectral files
Only present in v7 files, and only meaningful for spectral
(IRLIM/IAMPH) files produced by a forward Fourier transform. Has no
corresponding header field of its own; it exists only in the v7
footer, unlike headers such as delta
that also have a single-precision header slot.
stdp
class-attribute
instance-attribute
stdp: float | None = field(
default=None,
converter=_convert_stdp,
validator=validators.optional(
validators.instance_of(float)
),
)
Station depth below surface (metres).
stel
class-attribute
instance-attribute
stel: float | None = field(
default=None,
converter=_convert_stel,
validator=validators.optional(
validators.instance_of(float)
),
)
Station elevation above sea level (metres).
stla
class-attribute
instance-attribute
stla: float | None = field(
default=None,
converter=converters.optional(float),
validator=validators.optional(
validators.and_(
validators.instance_of(float),
validators.ge(-90),
validators.le(90),
)
),
)
Station latitude (degrees, north positive).
stlo
class-attribute
instance-attribute
stlo: float | None = field(
default=None,
converter=converters.optional(float),
validator=validators.optional(
validators.and_(
validators.instance_of(float),
validators.ge(-180),
validators.le(180),
)
),
)
Station longitude (degrees, east positive).
t0
class-attribute
instance-attribute
t0: float | None = field(
default=None,
converter=_convert_t0,
validator=validators.optional(
validators.and_(
validators.instance_of(float),
_validate_with_iztype,
)
),
)
User defined time pick or marker 0 (seconds relative to reference time).
t1
class-attribute
instance-attribute
t1: float | None = field(
default=None,
converter=_convert_t1,
validator=validators.optional(
validators.and_(
validators.instance_of(float),
_validate_with_iztype,
)
),
)
User defined time pick or marker 1 (seconds relative to reference time).
t2
class-attribute
instance-attribute
t2: float | None = field(
default=None,
converter=_convert_t2,
validator=validators.optional(
validators.and_(
validators.instance_of(float),
_validate_with_iztype,
)
),
)
User defined time pick or marker 2 (seconds relative to reference time).
t3
class-attribute
instance-attribute
t3: float | None = field(
default=None,
converter=_convert_t3,
validator=validators.optional(
validators.and_(
validators.instance_of(float),
_validate_with_iztype,
)
),
)
User defined time pick or marker 3 (seconds relative to reference time).
t4
class-attribute
instance-attribute
t4: float | None = field(
default=None,
converter=_convert_t4,
validator=validators.optional(
validators.and_(
validators.instance_of(float),
_validate_with_iztype,
)
),
)
User defined time pick or marker 4 (seconds relative to reference time).
t5
class-attribute
instance-attribute
t5: float | None = field(
default=None,
converter=_convert_t5,
validator=validators.optional(
validators.and_(
validators.instance_of(float),
_validate_with_iztype,
)
),
)
User defined time pick or marker 5 (seconds relative to reference time).
t6
class-attribute
instance-attribute
t6: float | None = field(
default=None,
converter=_convert_t6,
validator=validators.optional(
validators.and_(
validators.instance_of(float),
_validate_with_iztype,
)
),
)
User defined time pick or marker 6 (seconds relative to reference time).
t7
class-attribute
instance-attribute
t7: float | None = field(
default=None,
converter=_convert_t7,
validator=validators.optional(
validators.and_(
validators.instance_of(float),
_validate_with_iztype,
)
),
)
User defined time pick or marker 7 (seconds relative to reference time).
t8
class-attribute
instance-attribute
t8: float | None = field(
default=None,
converter=_convert_t8,
validator=validators.optional(
validators.and_(
validators.instance_of(float),
_validate_with_iztype,
)
),
)
User defined time pick or marker 8 (seconds relative to reference time).
t9
class-attribute
instance-attribute
t9: float | None = field(
default=None,
converter=_convert_t9,
validator=validators.optional(
validators.and_(
validators.instance_of(float),
_validate_with_iztype,
)
),
)
User defined time pick or marker 9 (seconds relative to reference time).
user0
class-attribute
instance-attribute
user0: float | None = field(
default=None,
converter=_convert_user0,
validator=validators.optional(
validators.instance_of(float)
),
)
User defined variable storage area.
user1
class-attribute
instance-attribute
user1: float | None = field(
default=None,
converter=_convert_user1,
validator=validators.optional(
validators.instance_of(float)
),
)
User defined variable storage area.
user2
class-attribute
instance-attribute
user2: float | None = field(
default=None,
converter=_convert_user2,
validator=validators.optional(
validators.instance_of(float)
),
)
User defined variable storage area.
user3
class-attribute
instance-attribute
user3: float | None = field(
default=None,
converter=_convert_user3,
validator=validators.optional(
validators.instance_of(float)
),
)
User defined variable storage area.
user4
class-attribute
instance-attribute
user4: float | None = field(
default=None,
converter=_convert_user4,
validator=validators.optional(
validators.instance_of(float)
),
)
User defined variable storage area.
user5
class-attribute
instance-attribute
user5: float | None = field(
default=None,
converter=_convert_user5,
validator=validators.optional(
validators.instance_of(float)
),
)
User defined variable storage area.
user6
class-attribute
instance-attribute
user6: float | None = field(
default=None,
converter=_convert_user6,
validator=validators.optional(
validators.instance_of(float)
),
)
User defined variable storage area.
user7
class-attribute
instance-attribute
user7: float | None = field(
default=None,
converter=_convert_user7,
validator=validators.optional(
validators.instance_of(float)
),
)
User defined variable storage area.
user8
class-attribute
instance-attribute
user8: float | None = field(
default=None,
converter=_convert_user8,
validator=validators.optional(
validators.instance_of(float)
),
)
User defined variable storage area.
user9
class-attribute
instance-attribute
user9: float | None = field(
default=None,
converter=_convert_user9,
validator=validators.optional(
validators.instance_of(float)
),
)
User defined variable storage area.
change_ref_time
change_ref_time(header: str) -> None
Re-point the reference time to a different time header.
header's absolute time becomes the new reference time and
SacIO.iztype is updated to match.
SacIO.ref_datetime and every
other time header are shifted by the exact same amount, so the
absolute (UTC) time each of them represents is unchanged.
Rounded to millisecond precision
SacIO.ref_datetime only has
millisecond precision, so the shift actually applied is rounded
to the nearest millisecond. header therefore ends up within
half a millisecond of 0, rather than exactly 0, whenever its
old value was not already millisecond-aligned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
header
|
str
|
Name of the time header to make the new zero-time
reference (e.g. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/pysmo/lib/io/_sacio/sacio.py
from_buffer
classmethod
from_file
classmethod
raw
raw() -> Iterator[None]
Temporarily relax cross-field header restrictions on this instance.
Some headers are restricted based on the value of another header,
rather than by type or range alone. Writing a value that violates
such a restriction normally raises RuntimeError; within this
context, that check is skipped, so the write goes through.
For example, iztype names one time
header (b, o, a, t0, etc.) as the zero-time reference, and
that header is normally pinned at 0.
change_ref_time and
read_buffer use this context
manager internally to move or replace the zero-time header before
the restriction holds again.
Only cross-field restrictions are relaxed
Only cross-field restrictions like this are relaxed, and only on this instance. Other checks (type, enum membership, numeric bounds, string length) still apply.
Examples:
>>> from pysmo.lib.io import SacIO
>>> sac = SacIO(o=0.0, iztype="o")
>>> with sac.raw():
... sac.o = 12.0
...
>>> sac.o
12.0
>>>
Source code in src/pysmo/lib/io/_sacio/sacio.py
read
read_buffer
read_buffer(buffer: bytes) -> None
Read data and headers from a SAC byte buffer into an existing SAC instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
buffer
|
bytes
|
Buffer containing SAC file content. |
required |
Source code in src/pysmo/lib/io/_sacio/sacio.py
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 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 | |
write
Write data and headers to a SAC file.
The file is written via a temporary file and an atomic replace, so a failure mid-write cannot destroy an existing valid file. When the target already exists its mode and ownership are carried over to the new file; a symlink target is resolved so the file it points to is replaced, not the link itself.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str | PathLike[str]
|
Name of the sacfile to write to. |
required |
Source code in src/pysmo/lib/io/_sacio/sacio.py
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 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 | |
extract_geocsv_timeseries
extract_geocsv_timeseries(
dataset: GeoCsvDataset,
) -> _TimeseriesSegment
Interpret a GeoCSV dataset as a waveform segment.
Uses the timeseries extension keywords emitted by the EarthScope FDSN
dataselect service (SID, start_time, sample_rate_hz,
sample_count). The sample column is located via the field_type
keyword; the dataset must declare a numeric field_type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
GeoCsvDataset
|
Uninterpreted GeoCSV dataset. |
required |
Returns:
| Type | Description |
|---|---|
_TimeseriesSegment
|
The dataset as a waveform segment. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a required timeseries header is missing or
unparseable, no numeric |
Source code in src/pysmo/lib/io/_geocsv.py
http_get
http_get(
url: str,
fields: dict[str, Any],
*,
timeout_seconds: int | float,
request_retries: int,
retry_delay_seconds: int | float,
redirect: bool = True
) -> bytes
Perform an HTTP GET request, retrying transient failures.
Connection failures, timeouts, and responses with a transient status
(429, 500, 502, 503, or 504) are retried up to request_retries times.
The first retry is immediate; retry n thereafter waits
retry_delay_seconds * 2 ** (n - 1) seconds plus a random jitter of up
to retry_delay_seconds, capped at 120 seconds total. A Retry-After
header on a 429 or 503 response replaces that wait, clamped to 6 hours.
Any other HTTP error status raises immediately.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
URL to request. |
required |
fields
|
dict[str, Any]
|
Query parameters to send with the request. |
required |
timeout_seconds
|
int | float
|
Timeout in seconds for each request attempt. |
required |
request_retries
|
int
|
Maximum number of request attempts (must be at least 1). |
required |
retry_delay_seconds
|
int | float
|
Base delay for the backoff schedule, and the width of the random jitter added to each wait. |
required |
redirect
|
bool
|
Whether to automatically follow HTTP redirects. |
True
|
Returns:
| Type | Description |
|---|---|
bytes
|
The response body. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
HTTPError
|
If a connection or timeout failure persists after all retries. |
ResponseError
|
If the server returns a non-retryable HTTP error status, or a transient one that persists after all retries. |
Source code in src/pysmo/lib/io/_http.py
merge_geocsv_timeseries
merge_geocsv_timeseries(
segments: list[_TimeseriesSegment],
*,
gap_tolerance_factor: NonNegativeNumber = 0.5,
auto_delta: bool = False
) -> _TimeseriesSegment
Merge contiguous waveform segments into a single segment.
Zero-sample segments are discarded before merging; the remaining
segments must share a channel (SID) and sample rate. The merge itself
(chronological ordering, gap/overlap tolerance, and overlap verification)
is delegated to
merge; see its
docstring for details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
segments
|
list[_TimeseriesSegment]
|
Waveform segments to merge, in any order. |
required |
gap_tolerance_factor
|
NonNegativeNumber
|
Maximum allowed boundary timestamp jitter
between consecutive segments, as a fraction of the sampling
interval. Passed through to
|
0.5
|
auto_delta
|
bool
|
Estimate a common sampling interval with
|
False
|
Returns:
| Type | Description |
|---|---|
_TimeseriesSegment
|
A single segment covering all input segments. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no non-empty segments remain, the segments belong
to different channels, the sample rates differ and |
Source code in src/pysmo/lib/io/_geocsv.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
parse_geocsv
parse_geocsv(text: str) -> list[GeoCsvDataset]
Split a GeoCSV text body into a list of datasets.
A new dataset starts at every dataset: keyword line. Keyword lines
are recognised with the whitespace flexibility the specification
allows (e.g. #dataset:GeoCSV 2.0 is equivalent to
# dataset: GeoCSV 2.0). Comment lines without a keyword are
ignored. The first non-comment line of each dataset is taken as the
column header line; all further non-comment lines are data rows,
split on the dataset delimiter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
GeoCSV text body. |
required |
Returns:
| Type | Description |
|---|---|
list[GeoCsvDataset]
|
List of uninterpreted datasets in order of appearance. |
Source code in src/pysmo/lib/io/_geocsv.py
parse_quakeml
Parse the event hypocentre and origin time from a QuakeML 1.2 document.
Returns one entry per <event> found. Only the preferred origin's
time/latitude/longitude/depth, and (where present) the preferred
magnitude, event type and first description, are read.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xml
|
bytes
|
Raw QuakeML 1.2 document bytes (as returned by any
|
required |
strict
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
list[_RawEvent]
|
One uninterpreted event per representable |
list[_RawEvent]
|
document order. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> from pysmo.lib.io._quakeml import parse_quakeml
>>> xml = b'''<?xml version="1.0"?>
... <q:quakeml xmlns="http://quakeml.org/xmlns/bed/1.2"
... xmlns:q="http://quakeml.org/xmlns/quakeml/1.2">
... <eventParameters publicID="smi:example/catalogue">
... <event publicID="smi:example/event/1">
... <description><text>Example</text></description>
... <origin publicID="smi:example/origin/1">
... <time><value>2010-02-27T06:34:11.53Z</value></time>
... <latitude><value>-36.122</value></latitude>
... <longitude><value>-72.898</value></longitude>
... <depth><value>22900</value></depth>
... </origin>
... <magnitude publicID="smi:example/magnitude/1">
... <mag><value>8.8</value></mag>
... <type>Mw</type>
... </magnitude>
... <type>earthquake</type>
... </event>
... </eventParameters>
... </q:quakeml>'''
>>> events = parse_quakeml(xml)
>>> len(events)
1
>>> events[0].latitude, events[0].depth, events[0].magnitude
(-36.122, 22900.0, 8.8)
>>>
Source code in src/pysmo/lib/io/_quakeml.py
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 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
parse_sacpz
Split SAC PZ text into a list of uninterpreted records.
A text body may contain several concatenated records (EarthScope's fdsnws-station service returns one per channel epoch when a query is not pinned to a single epoch); this function returns all of them, in order of appearance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
SAC PZ text body, containing one or more records. |
required |
Returns:
| Type | Description |
|---|---|
list[_RawSacPzResponse]
|
List of uninterpreted SAC PZ records in order of appearance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a record is missing a required header field, or the
|
Examples:
>>> from pysmo.lib.io._sacpz import parse_sacpz
>>> text = '''\
... * NETWORK (KNETWK): IU
... * STATION (KSTNM): ANMO
... * LOCATION (KHOLE): 00
... * CHANNEL (KCMPNM): BHZ
... * START : 2018-07-09T20:45:00
... * END :
... * INPUT UNIT : M
... ZEROS 2
... \t+0.000000e+00\t+0.000000e+00
... \t+0.000000e+00\t+0.000000e+00
... POLES 1
... \t-1.000000e-02\t+0.000000e+00
... CONSTANT 1.0e+09
... '''
>>> records = parse_sacpz(text)
>>> len(records)
1
>>> records[0].network, records[0].station
('IU', 'ANMO')
>>> records[0].end_date is None
True
>>>
Source code in src/pysmo/lib/io/_sacpz.py
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 | |
parse_stationxml
Parse station identity, coordinates and response from a StationXML document.
Walks the document once and returns one entry per <Channel> epoch (or
per <Station> for a channel-less level=station document), in document
order; the FDSN station web service does not default to a single
"current" epoch, so a query covering a channel's full history returns
several. Epoch selection is left to the caller. <Response> is read
when present (level=response) and left as None otherwise;
channel-level coordinates take precedence over station-level ones.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xml
|
bytes
|
Raw StationXML document bytes (any |
required |
Returns:
| Type | Description |
|---|---|
list[_RawStationEpoch]
|
One uninterpreted epoch per |
list[_RawStationEpoch]
|
document order. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> from pysmo.lib.io._stationxml import parse_stationxml
>>> xml = b'''<?xml version="1.0"?>
... <FDSNStationXML xmlns="http://www.fdsn.org/xml/station/1">
... <Network code="IU">
... <Station code="ANMO">
... <Latitude>34.9</Latitude><Longitude>-106.5</Longitude>
... <Channel code="BHZ" locationCode="00"
... startDate="2018-07-09T20:45:00.0000">
... <Latitude>34.95</Latitude><Longitude>-106.46</Longitude>
... <Elevation>1632.7</Elevation>
... </Channel>
... </Station>
... </Network>
... </FDSNStationXML>'''
>>> epochs = parse_stationxml(xml)
>>> len(epochs)
1
>>> epochs[0].station, epochs[0].channel, epochs[0].latitude
('ANMO', 'BHZ', 34.95)
>>> epochs[0].response is None
True
>>>
Source code in src/pysmo/lib/io/_stationxml.py
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 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 | |
write_geocsv
write_geocsv(
seismograms: Seismogram | Sequence[Seismogram],
path: str | PathLike[str],
) -> None
Write one or more Seismogram objects to a GeoCSV 2.0 file.
Each object is serialised as a self-contained GeoCSV 2.0 timeseries
dataset block (# dataset: GeoCSV 2.0 header, keyword metadata,
column header line, one row per sample). Multiple objects produce a
multi-dataset file that is readable by
parse_geocsv.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seismograms
|
Seismogram | Sequence[Seismogram]
|
A single |
required |
path
|
str | PathLike[str]
|
Destination file path. Written in UTF-8 text mode; existing content is overwritten. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If seismograms is an empty sequence. |
OSError
|
If the file cannot be written. |
Formatting and precision conventions
Dataset blocks are separated by a single blank line. The
sample_rate_hz header value is derived from
1_000_000_000 / delta.value (integer nanoseconds, to preserve
sub-microsecond precision). Both the # start_time: header and
every Time column value are pd.Timestamp.isoformat() calls
(begin_time and begin_time + n * delta respectively), which
preserve full precision (including nanoseconds). Sample values are
written as integer or float depending on whether the data are
integral, so genuinely non-integral data (e.g. a detrended or
filtered seismogram) are never silently truncated. A sourceid
attribute is used if present (e.g. on a
GeoCsvSeismogram), but is not
required by the Seismogram protocol itself,
so the # SID: header line is simply omitted for objects that
don't have one. # field_unit: UTC, Counts is always written
as-is, and neither Seismogram nor GeoCsvSeismogram carries a units
concept, so this label may not describe the data's actual physical
units (e.g. after response removal); parse_geocsv/
extract_geocsv_timeseries never read it back, so this doesn't
affect round-tripping, only external readers. sourceid is written
verbatim, with no escaping: a value containing a newline would
produce a file this module's own parse_geocsv cannot read back
correctly (a comma is fine, since header lines are matched by
regex, not CSV-split). Not a concern for real FDSN source
identifiers, which never contain a newline.
Examples:
>>> import pandas as pd
>>> import numpy as np
>>> from pysmo import MiniSeismogram
>>> from pysmo.lib.io import write_geocsv
>>> now = pd.Timestamp.now("UTC")
>>> delta = pd.Timedelta(seconds=0.1)
>>> seg1 = MiniSeismogram(begin_time=now, delta=delta, data=np.arange(5.0))
>>> seg2 = MiniSeismogram(begin_time=now, delta=delta, data=np.arange(5.0))
>>> write_geocsv(seg1, "out.geocsv")
>>> write_geocsv([seg1, seg2], "multi.geocsv")
>>>
Source code in src/pysmo/lib/io/_geocsv.py
write_mseed
write_mseed(
segments: Sequence[tuple[StationCode, Seismogram]],
path: str | PathLike[str],
*,
sample_type: Literal["i", "f", "d"] | None = None
) -> None
Write one or more waveform segments to a miniSEED file.
Each (identity, seismogram) pair becomes one trace segment. Pairs
that resolve to the same FDSN Source Identifier are grouped into one
trace with several segments, the natural representation of a channel
with a data gap.
Every segment is written with publication (quality) version 1,
regardless of any version an MSeed identity carries. Because
MSeed always decodes samples to float64, a
file read with MSeed and written back defaults to the uncompressed
"d" encoding even if the source used STEIM integer compression; pass
sample_type="i" to compress integer-valued data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
segments
|
Sequence[tuple[StationCode, Seismogram]]
|
A non-empty sequence of |
required |
path
|
str | PathLike[str]
|
Destination file path. Any existing content is overwritten. |
required |
sample_type
|
Literal['i', 'f', 'd'] | None
|
miniSEED sample encoding: |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If sample_type is |
ValueError
|
If segments is empty. |
MiniSEEDError
|
If the data cannot be encoded or written. |
Examples:
>>> import numpy as np
>>> import pandas as pd
>>> from pysmo import MiniSeismogram, MiniStationCode
>>> from pysmo.lib.io import write_mseed
>>> identity = MiniStationCode(
... name="ANMO", network="IU", location="00", channel="BHZ"
... )
>>> seismogram = MiniSeismogram(
... begin_time=pd.Timestamp("2010-02-27T06:30:00Z"),
... delta=pd.Timedelta(seconds=0.05),
... data=np.arange(100.0),
... )
>>> write_mseed([(identity, seismogram)], "out.mseed")
>>>
Source code in src/pysmo/lib/io/_mseed.py
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 | |
mini_utils
Match objects and protocols to pysmo's Mini classes.
Functions:
| Name | Description |
|---|---|
matching_pysmo_types |
Return the pysmo types an object may be an instance of. |
proto2mini |
Return the Mini classes that implement a given pysmo protocol. |
matching_pysmo_types
Return the pysmo types an object may be an instance of.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
The object (or class) to check. |
required |
Returns:
| Type | Description |
|---|---|
tuple[type[_AnyProto], ...]
|
Pysmo types that |
Examples:
Pysmo types matching instances of
MiniLocationWithDepth or the class
itself:
>>> from pysmo.lib.mini_utils import matching_pysmo_types
>>> from pysmo import MiniLocationWithDepth
>>>
>>> mini = MiniLocationWithDepth(latitude=12, longitude=34, depth=56)
>>> matching_pysmo_types(mini)
(<class 'pysmo.Location'>, <class 'pysmo.LocationWithDepth'>)
>>>
>>> matching_pysmo_types(MiniLocationWithDepth)
(<class 'pysmo.Location'>, <class 'pysmo.LocationWithDepth'>)
>>>
Source code in src/pysmo/lib/mini_utils.py
proto2mini
Return the Mini classes that implement a given pysmo protocol.
This function resolves the input protocol (handling modern type aliases and unions) and filters the available 'Mini' classes to find those that structurally implement it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proto
|
type[_AnyProto]
|
A pysmo type (e.g., |
required |
Returns:
| Type | Description |
|---|---|
type[_AnyMini]
|
A tuple of concrete Mini classes (e.g., |
...
|
that satisfy the interface defined by |
Examples:
Get all Mini classes that implement the Location protocol:
>>> from pysmo.lib.mini_utils import proto2mini
>>> from pysmo import Location, Event
>>> proto2mini(Location)
(<class 'pysmo.MiniStation'>, <class 'pysmo.MiniEvent'>, <class 'pysmo.MiniLocation'>, <class 'pysmo.MiniLocationWithDepth'>)
>>>
Works with Type Aliases and Unions (if the input is a union, it returns Minis matching any of the protocols in that union):
>>> type MyProto = Location | Event
>>> proto2mini(MyProto)
(<class 'pysmo.MiniStation'>, <class 'pysmo.MiniEvent'>, <class 'pysmo.MiniLocation'>, <class 'pysmo.MiniLocationWithDepth'>)
>>>
Source code in src/pysmo/lib/mini_utils.py
validators
Validators and converters for pysmo's attrs classes.
Functions:
| Name | Description |
|---|---|
convert_to_complex_list |
Convert an iterable of numbers to a list of |
convert_to_longitude |
Convert a value to a |
convert_to_ndarray |
Convert a value to a floating-point |
convert_to_timedelta |
Convert a value to a |
convert_to_utc_timestamp |
Convert a value to a UTC |
validate_nonzero |
Ensure |
convert_to_complex_list
convert_to_longitude
Convert a value to a float longitude in degrees, folding -180 onto +180.
-180 and +180 name the same meridian; +180 is kept as the single
canonical value so two spellings of the antimeridian cannot compare
unequal. Values genuinely outside [-180, 180] are returned unchanged
for a downstream validator to reject.
Source code in src/pysmo/lib/validators.py
convert_to_ndarray
Convert a value to a floating-point ndarray.
Non-floating input (e.g. an integer list) is cast to float64; floating
input keeps its own precision. np.asarray, not np.asanyarray, so an
ndarray subclass (masked array, np.matrix) does not
leak through.
Source code in src/pysmo/lib/validators.py
convert_to_timedelta
Convert a value to a Timedelta.
A float or int is assumed to be in seconds.
See Timedelta.
Source code in src/pysmo/lib/validators.py
convert_to_utc_timestamp
Convert a value to a UTC Timestamp (tzinfo=timezone.utc).
See Timestamp.
Source code in src/pysmo/lib/validators.py
validate_nonzero
Ensure value is not exactly zero. Either sign is otherwise permitted.