pysmo.tools.iccs
Iterative Cross-Correlation and Stack (ICCS).
Warning
This module is being developed alongside a complete rewrite of AIMBAT. Expect major changes until the rewrite is complete.
The ICCS1 method is an iterative algorithm to rapidly determine the best fitting delay times between an arbitrary number of seismograms with minimal involvement by a human operator. Instead of looking at individual seismograms, parameters are set that control the algorithm, which then iteratively aligns seismograms, or discards them from further consideration if they are of poor quality.
The basic idea of ICCS, is that stacking all seismograms (aligned with respect to an initial, and later improved, phase arrival pick) will lead to the targeted phase arrival becoming visible in the stack. As the stack is generated from all input seismograms, the phase arrival in the stack may be considered a representation of the "best" mean arrival time. Each individual seismogram can then be cross-correlated with the stack to determine a time shift that best aligns them with the stack and thus each other.
The results of ICCS are similar to those produced by the
mccc algorithm, while also requiring fewer
cross-correlations to be computed (each individual seismogram is only
cross-correlated with the stack, whereas in MCCC all seismograms are
cross-correlated with each other). ICCS is therefore particularly useful to
prepare data for a successful MCCC run (e.g. if the initial picks are
calculated rather than hand picked).
Data requirements
The iccs module requires that seismograms contain extra
attributes specific to the ICCS method. Hence it provides a protocol class
(IccsSeismogram) and corresponding Mini
class (MiniIccsSeismogram). In
addition to the common attributes of a Seismogram in
pysmo, the following parameters are required:
| Attribute | Description |
|---|---|
t0 |
Initial pick (typically computed). Serves as input only when t1 is not set. |
t1 |
Improved pick. Serves as both input (if not None) and output (always) when running the ICCS algorithm. It should be set to None initially. |
select |
Determines if a seismogram is used for the stack, and should therefore be True initially. It is set to False for poor quality seismograms automatically during a run if autoselect is True. Note that this flag does not exclude a seismogram from being cross-correlated with the stack. Recovery is therefore possible and previously de-selected seismograms may be selected again for the next iteration. |
flip |
Determines if the seismogram data should be flipped (i.e. data are multiplied with -1) when using it in the stack and cross-correlation. Can be automatically toggled when autoflip is True during a run. |
Tip
Functions and methods in this module do not modify any attributes other than the ones listed above. Preparation of seismograms for use in the cross-correlation and relevant visualisation functions happens internally, and does not affect the data of the original seismograms.
Ephemeral seismograms
As the ICCS algorithm operates on a window around the targeted phase arrival, only a small portion of the input seismogram data are used. These smaller portions are generated on the fly in two ways:
- Cross-correlation seismograms are used for the execution of the ICCS algorithm. They consist of the windowed portion around the phase arrival and a tapered ramp up and down outside the window.
- Context seismograms are used to provide extra context. They consist of a broader window around the phase arrival, and without any tapering applied.
Both share common processing steps, and are used to create a corresponding
stack. As they are completely reproducible, they only exist for the lifetime
of the ICCS instance that contains the input
seismograms and parameters used in
their creation. Changing any of the parameters will lead to automatic
regeneration of the ephemeral seismograms, however, as mutations of a list
cannot be detected, adding or removing seismograms from the list will not
trigger regeneration. In that case, clearing the cache must be done manually by
calling clear_cache.
Tip
Both types can be used for visualisation purposes. It is therefore possible to e.g. pick an updated arrival in the cross-correlation seismograms, and pick new time window boundaries in the context seismograms.
Execution flow
The diagram below shows execution flow, and how the above parameters are used when the ICCS algorithm is executed (see here for parameters and default values):
flowchart TD
Start(["`IccsSeismograms with initial parameters.`"])
Stack0["`Generate windowed seismograms and create stack from them.`"]
C["`Cross-correlate windowed seismograms with stack to obtain updated picks and normalised correlation coefficients.`"]
FlipQ{"`Is **autoflip**
True?`"}
Flip["`Toggle **flip** attribute of seismograms with negative correlation coefficients.`"]
QualQ{"`Is **autoselect**
True?`"}
Qual1["`Toggle **select** attribute of seismograms based on correlation coefficient.`"]
Stack1["`Recompute windowed seismograms and stack with updated parameters.`"]
H{"`Convergence
criteria met?`"}
I{"`Maximum
iterations
reached?`"}
End(["`IccsSeismograms with updated **t1**, **flip**, and **select** parameters.`"])
Start --> Stack0 --> C --> FlipQ -->|No| QualQ -->|No| Stack1 --> H -->|No| I -->|No| C
FlipQ -->|Yes| Flip --> QualQ
QualQ -->|Yes| Qual1 --> Stack1
H -->|Yes| End
I -->|Yes| End
Convergence is reached when the stack itself is not changing significantly anymore between iterations. Typically this happens within a few iterations.
Operator involvement
The ICCS algorithm relies on a few parameters that need to be adjusted by the user. This module provides functions to visualise the stack and individual seismograms (all at the same time), and to update the parameters based on visual inspection.
-
Lou, X., et al. “AIMBAT: A Python/Matplotlib Tool for Measuring Teleseismic Arrival Times.” Seismological Research Letters, vol. 84, no. 1, Jan. 2013, pp. 85–93, https://doi.org/10.1785/0220120033. ↩
Modules:
| Name | Description |
|---|---|
plot |
Extra plotting functions for the ICCS module. |
Classes:
| Name | Description |
|---|---|
ICCS |
Class to store a list of |
IccsResult |
Result returned by |
IccsSeismogram |
Protocol class to define the |
McccResult |
Result returned by |
MiniIccsSeismogram |
Minimal implementation of the |
Functions:
| Name | Description |
|---|---|
plot_matrix_image |
Plot the selected ICCS seismograms as a matrix image. |
plot_stack |
Plot the ICCS stack. |
update_min_cc |
Interactively pick a new |
update_pick |
Manually pick |
update_timewindow |
Pick new time window limits. |
ICCS
Class to store a list of IccsSeismograms and run the ICCS algorithm.
The ICCS class serves as a container to store a
list of seismograms (typically recordings of the same event at different
stations), and to then run the ICCS algorithm when an instance of this
class is called. Processing parameters that are common to all seismograms
are stored as attributes (e.g. time window limits).
The seismograms stored in an instance are prepared in two distinct ways:
- For cross-correlation: uses
ramp_widthto define how much of the seismogram should be used as taper before and after the time window of interest. These are the seismograms that form the stack and are used in the cross-correlation. - For added context: uses
context_widthto define how much of the seismogram should be used as extra context before and after the time window of interest.context_widthshould be chosen such that a large enough portion of the seismogram is shown to e.g. interactively pick new time window boundaries.
Apart from tapering the two types are processed the same. For performance, the prepared seismograms are cached and only calculated on a first call or if relevant parameters are updated.
Examples:
We begin with a set of SAC files of the same event, recorded at different
stations. All files have a preliminary phase arrival estimate saved in the
T0 SAC header, so we can use these files to create instances of the
MiniIccsSeismogram class for use
with the ICCS class:
>>> from pysmo.classes import SAC
>>> from pysmo.functions import clone_to_mini
>>> from pysmo.tools.iccs import MiniIccsSeismogram
>>> from pathlib import Path
>>>
>>> sacfiles = sorted(Path("iccs-example/").glob("*.bhz"))
>>>
>>> seismograms = []
>>> for sacfile in sacfiles:
... sac = SAC.from_file(sacfile)
... update = {"t0": sac.timestamps.t0}
... iccs_seismogram = clone_to_mini(MiniIccsSeismogram, sac.seismogram, update=update)
... seismograms.append(iccs_seismogram)
...
>>>
To better illustrate the different modes of running the ICCS algorithm, we modify the data and picks in the seismograms to make them worse than they actually are:
>>> import pandas as pd
>>> from copy import deepcopy
>>> import numpy as np
>>>
>>> # change the sign of the data in the first seismogram
>>> seismograms[0].data *= -1
>>>
>>> # move the initial pick 2 seconds earlier in second seismogram
>>> seismograms[1].t0 += pd.Timedelta(seconds=-2)
>>>
>>> # move the initial pick 2 seconds later in third seismogram
>>> seismograms[2].t0 += pd.Timedelta(seconds=2)
>>>
>>> # create a seismogram with completely random data
>>> iccs_random: MiniIccsSeismogram = deepcopy(seismograms[-1])
>>> np.random.seed(42) # set this for consistent results during testing
>>> iccs_random.data = np.random.rand(len(iccs_random.data))
>>> seismograms.append(iccs_random)
>>>
We can now create an instance of the ICCS
class and plot the initial stack and
cc_seismograms:
>>> from pysmo.tools.iccs import ICCS, plot_stack
>>> iccs = ICCS(seismograms)
>>> fig, ax = plot_stack(iccs, context=False)
>>>

The phase emergence is not visible in the stack, and the (absolute) correlation coefficients of the seismograms are not very high. This shows the initial picks are not very good and/or that the data are of low quality. To run the ICCS algorithm, we simply call (execute) the ICCS instance:
>>> convergence_list = iccs() # this runs the ICCS algorithm and returns
>>> # a list of the convergence value after each
>>> # iteration.
>>> fig, ax = plot_stack(iccs, context=False)
>>>

Despite the random noise seismogram, the phase arrival is now visible in
the stack. Seismograms with low correlation coefficients can automatically
be deselected from the calculations by running ICCS again with
autoselect=True:

Seismograms that fit better with their polarity reversed can be flipped
automatically by setting autoflip=True:

To further improve results, you can interactively update the picks,
time window, and minimum correlation coefficient using
update_pick,
update_timewindow, and
update_min_cc,
respectively, and then run the ICCS algorithm again.
Methods:
| Name | Description |
|---|---|
__call__ |
Run the iccs algorithm. |
clear_cache |
Clear all cached ephemeral seismograms, stacks, and derived results. |
run_mccc |
Refine picks with the MCCC algorithm. |
update_all_picks |
Update |
validate_pick |
Check whether a new pick is valid given all seismograms in the instance. |
validate_time_window |
Check if a new time window (relative to pick) is valid. |
Attributes:
| Name | Type | Description |
|---|---|---|
bandpass_apply |
bool
|
Filter seismograms with a bandpass filter before running ICCS. |
bandpass_fmax |
float
|
Bandpass filter maximum frequency (Hz). Only used if |
bandpass_fmin |
float
|
Bandpass filter minimum frequency (Hz). Only used if |
cc_seismograms |
list[_EphemeralSeismogram]
|
Return the seismograms as used for the cross-correlation. |
ccs |
ndarray
|
Returns an array of the normalised cross-correlation coefficients. |
context_seismograms |
list[_EphemeralSeismogram]
|
Returns the seismograms with extra context for plotting. |
context_stack |
MiniSeismogram
|
Returns the stacked |
context_width |
PositiveTimedelta
|
Context padding to apply before and after the time window. |
min_cc |
float
|
Minimum normalised cross-correlation coefficient for seismograms. |
ramp_width |
NonNegativeTimedelta | NonNegativeNumber
|
Width of taper ramp up and down. |
seismograms |
Sequence[IccsSeismogram]
|
Input seismograms. |
selected_cc_seismograms |
list[_EphemeralSeismogram]
|
Return a list of cc_seismograms with select=True. |
stack |
MiniSeismogram
|
Returns the stacked |
window_post |
PositiveTimedelta
|
End of the time window relative to the pick. |
window_pre |
NegativeTimedelta
|
Beginning of the time window relative to the pick. |
Source code in src/pysmo/tools/iccs/_iccs.py
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 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 | |
bandpass_apply
class-attribute
instance-attribute
bandpass_apply: bool = field(
default=bandpass_apply,
converter=bool,
validator=instance_of(bool),
on_setattr=pipe(
convert, validate, _on_setattr_clear_cache
),
)
Filter seismograms with a bandpass filter before running ICCS.
Setting this to True will apply a
bandpass filter (with zerophase set to
True) to the cc_seismograms
and context_seismograms.
As the seismograms may have already
been pre-processed (i.e. already filtered) the default value for this
parameter is False.
bandpass_fmax
class-attribute
instance-attribute
bandpass_fmax: float = field(
default=bandpass_fmax,
converter=float,
validator=instance_of(float),
on_setattr=pipe(
convert, validate, _on_setattr_clear_cache
),
)
Bandpass filter maximum frequency (Hz). Only used if bandpass_apply is True.
bandpass_fmin
class-attribute
instance-attribute
bandpass_fmin: float = field(
default=bandpass_fmin,
converter=float,
validator=instance_of(float),
on_setattr=pipe(
convert, validate, _on_setattr_clear_cache
),
)
Bandpass filter minimum frequency (Hz). Only used if bandpass_apply is True.
cc_seismograms
property
cc_seismograms: list[_EphemeralSeismogram]
Return the seismograms as used for the cross-correlation.
These seismograms are derived from the input seismograms and used for the cross-correlation steps. Starting with the input seismograms, they are processed as follows:
- Bandpass filtered if
bandpass_applyisTrue. - Resampled to the minimum sampling interval of all input seismograms (only if it is not equal in all seismograms).
- Cropped to
ramp_width+ current time window +ramp_width. - Detrended.
- Tapered using
ramp_width(tapered sections are outside time window). - Normalised based on the highest absolute value within the cropped
window. This step is done slightly differently in
context_seismograms--see the documentation of that property for details.
context_seismograms
property
context_seismograms: list[_EphemeralSeismogram]
Returns the seismograms with extra context for plotting.
These seismograms are derived from the input seismograms and used primarily for plotting with extra context (e.g. when selecting new time window boundaries). Starting with the input seismograms, they are processed as follows:
- Bandpass filtered if
bandpass_applyisTrue. - Resampled to the minimum sampling interval of all input seismograms (only if it is not equal in all seismograms).
- Cropped and/or padded to
context_width+ current time window +context_width. - Detrended.
- Normalised based on the highest absolute value within the selected time window (i.e. without the context).
context_stack
property
context_stack: MiniSeismogram
Returns the stacked context_seismograms.
Returns:
| Type | Description |
|---|---|
MiniSeismogram
|
Stacked input seismograms with context padding. |
context_width
class-attribute
instance-attribute
context_width: PositiveTimedelta = field(
default=context_width,
converter=convert_to_timedelta,
validator=gt(Timedelta(0)),
on_setattr=pipe(
convert, validate, _on_setattr_clear_cache
),
)
Context padding to apply before and after the time window.
This padding is not used for the cross-correlation.
min_cc
class-attribute
instance-attribute
min_cc: float = field(
default=min_cc,
converter=float,
validator=instance_of(float),
on_setattr=pipe(
convert, validate, _on_setattr_clear_cache
),
)
Minimum normalised cross-correlation coefficient for seismograms.
When the ICCS algorithm is executed,
the cross-correlation coefficient for each seismogram is calculated after
each iteration. If autoselect is set to True, the
select attribute of seismograms
with correlation coefficients below this value is set to False, and
they are no longer used for the stack.
ramp_width
class-attribute
instance-attribute
ramp_width: NonNegativeTimedelta | NonNegativeNumber = (
field(
default=ramp_width,
validator=_validate_ramp_width,
on_setattr=pipe(validate, _on_setattr_clear_cache),
)
)
Width of taper ramp up and down.
Warning
Can be either a timedelta or a float, but they mean slightly different
things. A float is interpreted as a fraction of the window duration,
while a timedelta is an absolute duration. See the documentation of
of pysmo.functions.window() for details.
seismograms
class-attribute
instance-attribute
seismograms: Sequence[IccsSeismogram] = field(
factory=list[IccsSeismogram],
on_setattr=_on_setattr_clear_cache,
)
Input seismograms.
These are the source seismograms from which the
[ephemeral seismograms][pysmo.tools.iccs#ephemeral-seismograms]
(cross-correlation and context seismograms) are derived on demand.
The ephemeral seismograms are cached and regenerated automatically
whenever a controlling attribute such as
window_pre or
window_post changes.
Warning
Assigning a new list to this attribute clears the cache automatically.
Mutating the list in place (e.g. with append, remove, or direct
index assignment) bypasses the setter and does not clear the cache.
Call clear_cache manually after
any such in-place mutation.
Tip
When a seismogram is of sufficiently poor quality that it should play no
further role in the analysis, consider removing it from this list rather
than simply setting its
select attribute to
False. A deselected seismogram is excluded from the stack and
correlation output, but its pick and data span still constrain the valid
ranges for window_pre,
window_post, and pick updates —
because all seismograms (selected or not) are used to generate the
ephemeral seismograms. A badly drifting pick on a deselected seismogram
can therefore make it impossible to set useful window or pick ranges for
the remaining good seismograms.
selected_cc_seismograms
property
selected_cc_seismograms: list[_EphemeralSeismogram]
Return a list of cc_seismograms with select=True.
stack
property
stack: MiniSeismogram
Returns the stacked cc_seismograms).
The stack is calculated as the average of all seismograms with the
attribute select set to
True. The begin_time of
the returned stack is the average of the begin_time of the input seismograms.
Returns:
| Type | Description |
|---|---|
MiniSeismogram
|
Stacked input seismograms. |
window_post
class-attribute
instance-attribute
window_post: PositiveTimedelta = field(
default=window_post,
validator=[gt(Timedelta(0)), _validate_window_post],
on_setattr=pipe(validate, _on_setattr_clear_cache),
)
End of the time window relative to the pick.
window_pre
class-attribute
instance-attribute
window_pre: NegativeTimedelta = field(
default=window_pre,
validator=[lt(Timedelta(0)), _validate_window_pre],
on_setattr=pipe(validate, _on_setattr_clear_cache),
)
Beginning of the time window relative to the pick.
__call__
__call__(
autoflip: bool = False,
autoselect: bool = False,
convergence_limit: float = convergence_limit,
convergence_method: ConvergenceMethod = convergence_method,
max_iter: int = max_iter,
max_shift: Timedelta | None = None,
) -> IccsResult
Run the iccs algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
autoflip
|
bool
|
Automatically toggle |
False
|
autoselect
|
bool
|
Automatically set |
False
|
convergence_limit
|
float
|
Convergence limit at which the algorithm stops. |
convergence_limit
|
convergence_method
|
ConvergenceMethod
|
Method to calculate convergence criterion. |
convergence_method
|
max_iter
|
int
|
Maximum number of iterations. |
max_iter
|
max_shift
|
Timedelta | None
|
Maximum shift in seconds (see |
None
|
Returns:
| Type | Description |
|---|---|
IccsResult
|
An |
IccsResult
|
convergence history and whether the convergence limit was reached. |
Source code in src/pysmo/tools/iccs/_iccs.py
clear_cache
Clear all cached ephemeral seismograms, stacks, and derived results.
Ephemeral seismograms (both cross-correlation and context variants),
their stacks, cross-correlation norms, and the valid pick and window
ranges are all computed on demand and cached to avoid redundant work.
The cache is invalidated automatically when a controlling attribute
such as window_pre,
window_post, or
seismograms is reassigned.
Call this method manually after any in-place mutation of
seismograms (e.g. append,
remove, or index assignment) to ensure all ephemeral seismograms and
derived results are regenerated from the updated input.
Source code in src/pysmo/tools/iccs/_iccs.py
run_mccc
run_mccc(
all_seismograms: bool = False,
min_cc: float = mccc_min_cc,
damping: float = mccc_damp,
abs_max: bool = False,
) -> McccResult
Refine picks with the MCCC algorithm.
This updates the picks of the seismograms with
mccc. It can be executed at any point to
update picks. However, it will not autoselect or autoflip seismograms.
It is therefore recommended as final step to refine the results of
ICCS().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
all_seismograms
|
bool
|
Whether to run MCCC on all seismograms or only on
those with |
False
|
min_cc
|
float
|
Minimum correlation coefficient required to include a pair in the inversion. |
mccc_min_cc
|
damping
|
float
|
Tikhonov regularization strength. Set to 0 to disable. |
mccc_damp
|
abs_max
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
McccResult
|
A |
McccResult
|
updated picks and MCCC diagnostic values. |
Source code in src/pysmo/tools/iccs/_iccs.py
update_all_picks
update_all_picks(pickdelta: Timedelta) -> None
Update t1 in all seismograms by the same amount.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pickdelta
|
Timedelta
|
delta applied to all picks. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the new t1 is outside the valid range. |
Source code in src/pysmo/tools/iccs/_iccs.py
validate_pick
Check whether a new pick is valid given all seismograms in the instance.
The valid pick range is computed from every seismogram in
seismograms, including those with
select set to
False. A pick is considered valid if it lies within this
global range; selection only affects stacking, not the validity bounds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pick
|
Timedelta
|
New pick to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether the new pick is valid. |
Source code in src/pysmo/tools/iccs/_iccs.py
validate_time_window
Check if a new time window (relative to pick) is valid.
Validates that the proposed window fits within every seismogram,
accounting for the taper ramp. The ramp duration is computed from
the proposed window_pre and window_post values, consistent
with how pysmo.functions.window computes it for float
ramp_width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window_pre
|
Timedelta
|
Proposed window start time (negative, relative to pick). |
required |
window_post
|
Timedelta
|
Proposed window end time (positive, relative to pick). |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether the new time window is valid for all seismograms. |
Source code in src/pysmo/tools/iccs/_iccs.py
IccsResult
Result returned by ICCS.__call__().
Attributes:
| Name | Type | Description |
|---|---|---|
converged |
bool
|
Whether the convergence limit was reached before |
convergence |
ndarray
|
Convergence criterion value after each iteration. |
Source code in src/pysmo/tools/iccs/_types.py
IccsSeismogram
Bases: Seismogram, Protocol
Protocol class to define the IccsSeismogram type.
The IccsSeismogram type extends the Seismogram type
with the addition of parameters that are required for ICCS.
Attributes:
| Name | Type | Description |
|---|---|---|
begin_time |
Timestamp
|
Seismogram begin time. |
data |
ndarray
|
Seismogram data. |
delta |
Timedelta
|
The sampling interval. |
end_time |
Timestamp
|
Seismogram end time. |
extra |
dict[Hashable, Any]
|
Extra metadata that may be helpful to be stored alongside the seismogram. |
flip |
bool
|
Data in seismogram should be flipped for ICCS. |
select |
bool
|
Use seismogram to create stack. |
t0 |
Timestamp
|
Initial pick. |
t1 |
Timestamp | None
|
Updated pick. |
Source code in src/pysmo/tools/iccs/_types.py
delta
instance-attribute
delta: Timedelta
The sampling interval.
Should be a positive pd.Timedelta instance.
extra
instance-attribute
Extra metadata that may be helpful to be stored alongside the seismogram.
McccResult
Result returned by ICCS.run_mccc().
These results include all seismograms if run_mccc() is called with
all_seismograms=True, only the selected ones otherwise.
Attributes:
| Name | Type | Description |
|---|---|---|
cc_means |
list[float]
|
Per-seismogram mean cross-correlation coefficient (waveform quality). |
cc_stds |
list[float]
|
Per-seismogram standard deviation of cross-correlation coefficients (waveform consistency). |
errors |
list[Timedelta]
|
Per-seismogram timing precision (standard error from covariance matrix). |
picks |
list[Timestamp]
|
Final absolute arrival times for each seismogram. |
rmse |
Timedelta
|
Root-mean-square error of the inversion fit across the whole array. |
Source code in src/pysmo/tools/iccs/_types.py
cc_means
instance-attribute
Per-seismogram mean cross-correlation coefficient (waveform quality).
cc_stds
instance-attribute
Per-seismogram standard deviation of cross-correlation coefficients (waveform consistency).
errors
instance-attribute
Per-seismogram timing precision (standard error from covariance matrix).
rmse
instance-attribute
rmse: Timedelta
Root-mean-square error of the inversion fit across the whole array.
MiniIccsSeismogram
Bases: SeismogramEndtimeMixin, IccsSeismogram
Minimal implementation of the IccsSeismogram type.
The MiniIccsSeismogram class provides
a minimal implementation of a class that is compatible with the
IccsSeismogram protocol.
Examples:
Because IccsSeismogram inherits
from Seismogram, we can easily create
MiniIccsSeismogram instances
from existing seismograms using the
clone_to_mini() function, whereby
the update parameter is used to provide the extra information needed:
>>> from pysmo.classes import SAC
>>> from pysmo.functions import clone_to_mini
>>> from pysmo.tools.iccs import MiniIccsSeismogram
>>> import pandas as pd
>>> sac = SAC.from_file("example.sac")
>>> sac_seis = sac.seismogram
>>> # Use existing pick or set a new one 10 seconds after begin time
>>> update = {"t0": sac_seis.begin_time + pd.Timedelta(seconds=10) if pd.isnull(sac.timestamps.t0) else sac.timestamps.t0}
>>> mini_iccs_seis = clone_to_mini(MiniIccsSeismogram, sac_seis, update=update)
>>>
Attributes:
| Name | Type | Description |
|---|---|---|
begin_time |
UtcTimestamp
|
Seismogram begin time. |
data |
ndarray
|
Seismogram data. |
delta |
PositiveTimedelta
|
Seismogram sampling interval. |
end_time |
Timestamp
|
Seismogram end time. |
extra |
dict[Hashable, Any]
|
Extra metadata that may be helpful to be stored alongside the seismogram. |
flip |
bool
|
Data in seismogram should be flipped for ICCS. |
select |
bool
|
Use seismogram to create stack. |
t0 |
UtcTimestamp
|
Initial pick. |
t1 |
UtcTimestamp | None
|
Updated pick. |
Source code in src/pysmo/tools/iccs/_types.py
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 | |
begin_time
class-attribute
instance-attribute
begin_time: UtcTimestamp = field(
default=begin_time,
converter=convert_to_utc_timestamp,
on_setattr=convert,
)
Seismogram begin time.
data
class-attribute
instance-attribute
data: ndarray = field(
factory=lambda: array([]),
converter=convert_to_ndarray,
validator=instance_of(ndarray),
on_setattr=pipe(convert, validate),
)
Seismogram data.
delta
class-attribute
instance-attribute
delta: PositiveTimedelta = field(
default=delta,
converter=convert_to_timedelta,
validator=[instance_of(Timedelta), gt(Timedelta(0))],
on_setattr=pipe(convert, validate),
)
Seismogram sampling interval.
extra
class-attribute
instance-attribute
Extra metadata that may be helpful to be stored alongside the seismogram.
flip
class-attribute
instance-attribute
flip: bool = field(
default=False,
converter=bool,
validator=instance_of(bool),
on_setattr=pipe(convert, validate),
)
Data in seismogram should be flipped for ICCS.
select
class-attribute
instance-attribute
select: bool = field(
default=True,
converter=bool,
validator=instance_of(bool),
on_setattr=pipe(convert, validate),
)
Use seismogram to create stack.
t0
class-attribute
instance-attribute
t0: UtcTimestamp = field(
converter=convert_to_utc_timestamp, on_setattr=convert
)
Initial pick.
t1
class-attribute
instance-attribute
t1: UtcTimestamp | None = field(
default=None,
converter=convert_to_utc_timestamp,
on_setattr=convert,
)
Updated pick.
plot_matrix_image
plot_matrix_image(
iccs: ICCS,
context: bool = True,
all_seismograms: bool = False,
return_fig: bool = True,
) -> tuple[Figure, Axes] | None
Plot the selected ICCS seismograms as a matrix image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iccs
|
ICCS
|
Instance of the |
required |
context
|
bool
|
Determines which seismograms are used:
- |
True
|
all_seismograms
|
bool
|
If |
False
|
return_fig
|
bool
|
True
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, Axes] | None
|
Figure of the selected seismograms as a matrix image if |
Examples:
The default plotting mode is to pad the seismograms beyond the time window used for the cross-correlations. This is particularly useful for narrow time windows.
>>> from pysmo.tools.iccs import ICCS, plot_matrix_image
>>> iccs = ICCS(iccs_seismograms)
>>> _ = iccs(autoselect=True, autoflip=True)
>>>
>>> fig, ax = plot_matrix_image(iccs)
>>> # fig.show() # or integrate into your own application
>>>

To view the matrix image composed of seismograms as used in the
cross-correlations, set the context argument to False:
>>> fig, ax = plot_matrix_image(iccs, context=False)
>>> # fig.show() # or integrate into your own application
>>>

Source code in src/pysmo/tools/iccs/plot.py
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 | |
plot_stack
plot_stack(
iccs: ICCS,
context: bool = True,
all_seismograms: bool = False,
return_fig: bool = True,
) -> tuple[Figure, Axes] | None
Plot the ICCS stack.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iccs
|
ICCS
|
Instance of the |
required |
context
|
bool
|
Determines which seismograms are used:
- |
True
|
all_seismograms
|
bool
|
If |
False
|
return_fig
|
bool
|
True
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, Axes] | None
|
Figure of the stack with the seismograms if |
Examples:
The default plotting mode is to pad the stack beyond the time window used for the cross-correlations (highlighted in light green). This is useful particularly useful for narrow time windows. Note that because of the padding, the displayed stack isn't exactly what is used for the cross-correlations.
>>> from pysmo.tools.iccs import ICCS, plot_stack
>>> iccs = ICCS(iccs_seismograms)
>>> _ = iccs(autoselect=True, autoflip=True)
>>>
>>> fig, ax = plot_stack(iccs)
>>> # fig.show() # or integrate into your own application
>>>

To view the stack exactly as it is used in the cross-correlations, set
the context argument to False:
>>> fig, ax = plot_stack(iccs, context=False)
>>> # fig.show() # or integrate into your own application
>>>

Source code in src/pysmo/tools/iccs/plot.py
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 | |
update_min_cc
update_min_cc(
iccs: ICCS,
context: bool = True,
all_seismograms: bool = False,
return_fig: bool = True,
) -> (
tuple[
Figure,
Axes,
tuple[
Cursor,
Line2D,
Button,
Button,
_ScrollIndexTracker,
],
]
| None
)
Interactively pick a new min_cc.
This function launches an interactive figure to manually pick a new
min_cc, which is used when
running the ICCS algorithm with
autoselect set to True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iccs
|
ICCS
|
Instance of the |
required |
context
|
bool
|
Determines which seismograms are used:
- |
True
|
all_seismograms
|
bool
|
If |
False
|
return_fig
|
bool
|
True
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, Axes, tuple[Cursor, Line2D, Button, Button, _ScrollIndexTracker]] | None
|
Figure with the selector widgets if |
Examples:
>>> from pysmo.tools.iccs import ICCS, update_min_cc
>>> iccs = ICCS(iccs_seismograms)
>>> _ = iccs()
>>> fig, ax, widgets = update_min_cc(iccs)
>>> # fig.show() # or integrate into your own application
>>>

Source code in src/pysmo/tools/iccs/plot.py
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 | |
update_pick
update_pick(
iccs: ICCS,
context: bool = True,
all_seismograms: bool = False,
use_matrix_image: bool = False,
return_fig: bool = True,
) -> (
tuple[
Figure, Axes, tuple[Cursor, Line2D, Button, Button]
]
| None
)
Manually pick t1 and apply it to all seismograms.
This function launches an interactive figure to manually pick a new phase arrival, and then apply it to all seismograms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iccs
|
ICCS
|
Instance of the |
required |
context
|
bool
|
Determines which seismograms are used:
- |
True
|
all_seismograms
|
bool
|
If |
False
|
use_matrix_image
|
bool
|
Use the matrix image instead of the stack. |
False
|
return_fig
|
bool
|
True
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, Axes, tuple[Cursor, Line2D, Button, Button]] | None
|
Figure of the stack with the picker if |
Examples:
>>> from pysmo.tools.iccs import ICCS, update_pick
>>> iccs = ICCS(iccs_seismograms)
>>> _ = iccs(autoselect=True, autoflip=True)
>>>
>>> fig, ax, widgets = update_pick(iccs)
>>> # fig.show() # or integrate into your own application
>>>

Source code in src/pysmo/tools/iccs/plot.py
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 | |
update_timewindow
update_timewindow(
iccs: ICCS,
context: bool = True,
all_seismograms: bool = False,
use_matrix_image: bool = False,
return_fig: bool = True,
) -> (
tuple[Figure, Axes, tuple[SpanSelector, Button, Button]]
| None
)
Pick new time window limits.
This function launches an interactive figure to pick new values for
window_pre and
window_post.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iccs
|
ICCS
|
Instance of the |
required |
context
|
bool
|
Determines which seismograms are used:
- |
True
|
all_seismograms
|
bool
|
If |
False
|
use_matrix_image
|
bool
|
Use the matrix image instead of the stack. |
False
|
return_fig
|
bool
|
True
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, Axes, tuple[SpanSelector, Button, Button]] | None
|
Figure of the stack with the picker if |
Info
The new time window may not be chosen such that the pick lies outside the window. The picker will therefore automatically correct itself for invalid window choices.
Examples:
>>> from pysmo.tools.iccs import ICCS, update_timewindow
>>> iccs = ICCS(iccs_seismograms)
>>> _ = iccs(autoselect=True, autoflip=True)
>>>
>>> fig, ax, widgets = update_timewindow(iccs)
>>> # fig.show() # or integrate into your own application
>>>

Source code in src/pysmo/tools/iccs/plot.py
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 | |
pysmo.tools.iccs.plot
Extra plotting functions for the ICCS module.
These functions provide additional plotting capabilities for the ICCS module.
They are generally not meant to be consumed directly.
Instead, use the higher-level plotting functions (e.g., plot_stack, update_pick)
available directly from the pysmo.tools.iccs namespace, which provide a more
integrated and user-friendly experience.
This module exposes lower-level drawing primitives (draw_common_stack,
draw_common_matrix_image) for advanced users who wish to customise their plotting
workflows.
Functions:
| Name | Description |
|---|---|
draw_common_matrix_image |
Returns a basic matrix image plot for use in other plots. |
draw_common_stack |
Returns a basic stack plot for use in other plots. |
draw_common_matrix_image
Returns a basic matrix image plot for use in other plots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Axes to plot on. |
required |
iccs
|
ICCS
|
Instance of the |
required |
context
|
bool
|
Determines which seismograms are used:
- |
required |
all_seismograms
|
bool
|
If |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Sorted seismogram matrix used for the plot. |
Source code in src/pysmo/tools/iccs/plot.py
draw_common_stack
Returns a basic stack plot for use in other plots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Axes to plot on. |
required |
iccs
|
ICCS
|
Instance of the |
required |
context
|
bool
|
Determines which seismograms are used:
- |
required |
all_seismograms
|
bool
|
If |
required |