Skip to content

aimbat.plot

Visualisation and interactive quality control for seismograms and alignment results.

This module provides tools for generating static plots of seismic data and alignment stacks, as well as interactive interfaces for refining phase picks and time windows. It integrates with matplotlib to support both automated reporting and manual verification workflows.

Functions:

Name Description
plot_matrix_image

Plot the ICCS seismograms as a matrix image.

plot_seismograms

Plot all seismograms for a particular event or station.

plot_stack

Plot the ICCS stack.

update_min_cc

Update the minimum cross-correlation threshold for the given event.

update_pick

Update the phase pick (t1) for an event.

update_timewindow

Update the cross-correlation time window for the given event.

plot_matrix_image

plot_matrix_image(
    iccs: ICCS,
    context: bool,
    all_seismograms: bool,
    return_fig: bool,
) -> tuple[Figure, Axes] | None

Plot the ICCS seismograms as a matrix image.

The matrix is assembled from individual waveforms, with each row representing a different seismogram.

Parameters:

Name Type Description Default
iccs ICCS

ICCS instance.

required
context bool

If True, plot waveforms with extra context around the taper window.

required
all_seismograms bool

If True, include deselected seismograms in the plot.

required
return_fig bool

If True, return the figure and axes objects instead of showing the plot.

required

Returns:

Type Description
tuple[Figure, Axes] | None

A tuple of (Figure, Axes) if return_fig is True, otherwise None.

Source code in src/aimbat/plot/_iccs.py
def plot_matrix_image(
    iccs: ICCS, context: bool, all_seismograms: bool, return_fig: bool
) -> tuple["Figure", "Axes"] | None:
    """Plot the ICCS seismograms as a matrix image.

    The matrix is assembled from individual waveforms, with each row representing
    a different seismogram.

    Args:
        iccs: ICCS instance.
        context: If True, plot waveforms with extra context around the taper window.
        all_seismograms: If True, include deselected seismograms in the plot.
        return_fig: If True, return the figure and axes objects instead of showing the plot.

    Returns:
        A tuple of (Figure, Axes) if return_fig is True, otherwise None.
    """

    logger.info("Plotting matrix image.")

    return _plot_matrix_image(iccs, context, all_seismograms, return_fig=return_fig)  # type: ignore[call-overload]

plot_seismograms

plot_seismograms(
    session: Session,
    plot_for: AimbatEvent | AimbatStation,
    return_fig: bool,
) -> tuple[Figure, Axes] | None

Plot all seismograms for a particular event or station.

Parameters:

Name Type Description Default
session Session

Database session.

required
plot_for AimbatEvent | AimbatStation

What to plot the seismograms for (Event or Station).

required
return_fig bool

Whether to return the figure and axes objects instead of showing the plot.

required

Returns:

Type Description
tuple[Figure, Axes] | None

figure and axes objects if return_fig is True, otherwise None.

Raises:

Type Description
RuntimeError

If no seismograms are found for the event or station.

Note

The seismograms use the filter settings specified in the event parameters.

Source code in src/aimbat/plot/_seismograms.py
def plot_seismograms(
    session: Session, plot_for: AimbatEvent | AimbatStation, return_fig: bool
) -> tuple[plt.Figure, plt.Axes] | None:
    """Plot all seismograms for a particular event or station.

    Args:
        session: Database session.
        plot_for: What to plot the seismograms for (Event or Station).
        return_fig: Whether to return the figure and axes objects instead of showing the plot.

    Returns:
        figure and axes objects if return_fig is True, otherwise None.

    Raises:
        RuntimeError: If no seismograms are found for the event or station.

    Note:
        The seismograms use the filter settings specified in the event parameters.
    """
    logger.info(f"Plotting seismograms for {type(plot_for).__name__}: {plot_for.id}.")

    fig, ax = _plot_seis(plot_for, session)
    _add_scroll_pan(ax)

    if return_fig:
        return fig, ax
    plt.show()
    return None

plot_stack

plot_stack(
    iccs: ICCS,
    context: bool,
    all_seismograms: bool,
    return_fig: bool,
) -> tuple[Figure, Axes] | None

Plot the ICCS stack.

Parameters:

Name Type Description Default
iccs ICCS

ICCS instance.

required
context bool

If True, plot waveforms with extra context around the taper window.

required
all_seismograms bool

If True, include deselected seismograms in the plot.

required
return_fig bool

If True, return the figure and axes objects instead of showing the plot.

required

Returns:

Type Description
tuple[Figure, Axes] | None

A tuple of (Figure, Axes) if return_fig is True, otherwise None.

Source code in src/aimbat/plot/_iccs.py
def plot_stack(
    iccs: ICCS, context: bool, all_seismograms: bool, return_fig: bool
) -> tuple["Figure", "Axes"] | None:
    """Plot the ICCS stack.

    Args:
        iccs: ICCS instance.
        context: If True, plot waveforms with extra context around the taper window.
        all_seismograms: If True, include deselected seismograms in the plot.
        return_fig: If True, return the figure and axes objects instead of showing the plot.

    Returns:
        A tuple of (Figure, Axes) if return_fig is True, otherwise None.
    """

    logger.info("Plotting ICCS stack.")
    return _plot_stack(iccs, context, all_seismograms, return_fig=return_fig)  # type: ignore[call-overload]

update_min_cc

update_min_cc(
    session: Session,
    event: AimbatEvent,
    iccs: ICCS,
    context: bool,
    all_seismograms: bool,
    return_fig: bool,
) -> tuple[Figure, Axes, Any] | None

Update the minimum cross-correlation threshold for the given event.

Parameters:

Name Type Description Default
session Session

Database session.

required
event AimbatEvent

AimbatEvent.

required
iccs ICCS

ICCS instance.

required
context bool

If True, plot waveforms with extra context around the taper window.

required
all_seismograms bool

If True, include deselected seismograms in the plot.

required
return_fig bool

If True, return the figure, axes and widget objects instead of showing the plot.

required

Returns:

Type Description
tuple[Figure, Axes, Any] | None

A tuple of (Figure, Axes, widgets) if return_fig is True, otherwise None.

Source code in src/aimbat/plot/_iccs.py
def update_min_cc(
    session: Session,
    event: AimbatEvent,
    iccs: ICCS,
    context: bool,
    all_seismograms: bool,
    return_fig: bool,
) -> tuple["Figure", "Axes", Any] | None:
    """Update the minimum cross-correlation threshold for the given event.

    Args:
        session: Database session.
        event: AimbatEvent.
        iccs: ICCS instance.
        context: If True, plot waveforms with extra context around the taper window.
        all_seismograms: If True, include deselected seismograms in the plot.
        return_fig: If True, return the figure, axes and widget objects instead of showing the plot.

    Returns:
        A tuple of (Figure, Axes, widgets) if return_fig is True, otherwise None.
    """

    logger.info(f"Updating minimum cross-correlation threshold for event {event.id}.")

    result = _update_min_cc(iccs, context, all_seismograms, return_fig=return_fig)  # type: ignore[call-overload]

    if not return_fig:
        logger.debug(
            f"Saving new minimum cross-correlation threshold for event {event.id}: {iccs.min_cc}"
        )
        set_event_parameter(
            session, event.id, EventParameter.MIN_CC, float(iccs.min_cc)
        )
        return None

    logger.warning(_RETURN_FIG_WARNING)
    return result

update_pick

update_pick(
    session: Session,
    iccs: ICCS,
    context: bool,
    all_seismograms: bool,
    use_matrix_image: bool,
    return_fig: bool,
) -> tuple[Figure, Axes, Any] | None

Update the phase pick (t1) for an event.

Parameters:

Name Type Description Default
session Session

Database session.

required
iccs ICCS

ICCS instance.

required
context bool

If True, plot waveforms with extra context around the taper window.

required
all_seismograms bool

If True, include deselected seismograms in the plot.

required
use_matrix_image bool

If True, pick from the matrix image; otherwise pick from the stack plot.

required
return_fig bool

If True, return the figure, axes and widget objects instead of showing the plot.

required

Returns:

Type Description
tuple[Figure, Axes, Any] | None

A tuple of (Figure, Axes, widgets) if return_fig is True, otherwise None.

Source code in src/aimbat/plot/_iccs.py
def update_pick(
    session: Session,
    iccs: ICCS,
    context: bool,
    all_seismograms: bool,
    use_matrix_image: bool,
    return_fig: bool,
) -> tuple["Figure", "Axes", Any] | None:
    """Update the phase pick (t1) for an event.

    Args:
        session: Database session.
        iccs: ICCS instance.
        context: If True, plot waveforms with extra context around the taper window.
        all_seismograms: If True, include deselected seismograms in the plot.
        use_matrix_image: If True, pick from the matrix image; otherwise pick from the stack plot.
        return_fig: If True, return the figure, axes and widget objects instead of showing the plot.

    Returns:
        A tuple of (Figure, Axes, widgets) if return_fig is True, otherwise None.
    """

    logger.info("Updating phase pick.")

    result = _update_pick(  # type: ignore[call-overload]
        iccs, context, all_seismograms, use_matrix_image, return_fig=return_fig
    )

    if not return_fig:
        _write_back_seismograms(session, iccs)
        return None

    logger.warning(_RETURN_FIG_WARNING)
    return result

update_timewindow

update_timewindow(
    session: Session,
    event: AimbatEvent,
    iccs: ICCS,
    context: bool,
    all_seismograms: bool,
    use_matrix_image: bool,
    return_fig: bool,
) -> tuple[Figure, Axes, Any] | None

Update the cross-correlation time window for the given event.

Parameters:

Name Type Description Default
session Session

Database session.

required
event AimbatEvent

AimbatEvent.

required
iccs ICCS

ICCS instance.

required
context bool

If True, plot waveforms with extra context around the taper window.

required
all_seismograms bool

If True, include deselected seismograms in the plot.

required
use_matrix_image bool

If True, pick from the matrix image; otherwise pick from the stack plot.

required
return_fig bool

If True, return the figure, axes and widget objects instead of showing the plot.

required

Returns:

Type Description
tuple[Figure, Axes, Any] | None

A tuple of (Figure, Axes, widgets) if return_fig is True, otherwise None.

Source code in src/aimbat/plot/_iccs.py
def update_timewindow(
    session: Session,
    event: AimbatEvent,
    iccs: ICCS,
    context: bool,
    all_seismograms: bool,
    use_matrix_image: bool,
    return_fig: bool,
) -> tuple["Figure", "Axes", Any] | None:
    """Update the cross-correlation time window for the given event.

    Args:
        session: Database session.
        event: AimbatEvent.
        iccs: ICCS instance.
        context: If True, plot waveforms with extra context around the taper window.
        all_seismograms: If True, include deselected seismograms in the plot.
        use_matrix_image: If True, pick from the matrix image; otherwise pick from the stack plot.
        return_fig: If True, return the figure, axes and widget objects instead of showing the plot.

    Returns:
        A tuple of (Figure, Axes, widgets) if return_fig is True, otherwise None.
    """

    logger.info(f"Updating time window for event {event.id}.")

    result = _update_timewindow(  # type: ignore[call-overload]
        iccs, context, all_seismograms, use_matrix_image, return_fig=return_fig
    )

    if not return_fig:
        logger.debug(
            f"Saving new time window for event {event.id}: "
            f"pre={iccs.window_pre}, post={iccs.window_post}"
        )
        set_event_parameter(
            session, event.id, EventParameter.WINDOW_PRE, iccs.window_pre
        )
        set_event_parameter(
            session, event.id, EventParameter.WINDOW_POST, iccs.window_post
        )
        return None

    logger.warning(_RETURN_FIG_WARNING)
    return result