scatcluster.analysis.waveforms

Analysis Waveforms module.

Classes

Waveforms

Module Contents

class scatcluster.analysis.waveforms.Waveforms[source]
plot_waveforms_per_cluster(clusters: List[int] = None, waveforms_n_samples: int = None, **kwargs)[source]

Visualise Waveforms for All or a select number of clusters.

Parameters:
  • clusters (List[int], optional) – If specified, only plot waveforms for clusters in list of integers.

  • example (For) –

  • [1 (clusters =) –

  • only. (3] will produce waveforms for cluster 1 and 3) –

  • clusters. (Defaults to None will produce waveforms for all) –

  • waveforms_n_samples (int, optional) – Number of waveforms to plot. Defaults to None.

  • **kwargs – Additional keyword arguments to pass to plt.subplots().

plot_all_waveforms(channel='HHZ', waveforms_n_samples=3, **kwargs)[source]

Plots waveforms for all or a select number of clusters.

Parameters:
  • channel (str, optional) – The channel to plot waveforms for. Defaults to ‘HHZ’.

  • waveforms_n_samples (int, optional) – The number of waveforms to plot. Defaults to 3.

  • **kwargs – Additional keyword arguments to pass to plt.subplots().

Prints:

Trace is not available between {start}-{end} for supplied parametrization

Saves:

A figure of waveforms for all clusters as a PNG file.

get_waveform(start_time='2022-01-01T00:00:00+00:00', time_second=60, channel='HHZ', envelope=False)[source]

Retrieves a waveform from the data source within a specified time range and channel.

Parameters:
  • start_time (str, optional) – The start time of the waveform in ISO format. Defaults to ‘2022-01-01T00:00:00+00:00’.

  • time_second (int, optional) – The duration of the waveform in seconds. Defaults to 60.

  • channel (str, optional) – The channel of the waveform. Defaults to ‘HHZ’.

  • envelope (bool, optional) – Whether to process the waveform with the envelope function. Defaults to False.

Returns:

The waveform data as an ObsPy Stream object.

Return type:

obspy.core.stream.Stream

retreive_scat_vector(scat_coef_vectorized, scat_coef_vectorized_index, num_channels=3, scat_vec_size_first_order=16, scat_vec_size_second_order=(16, 7))[source]
Retrieves the scattering vector from the given scat_coef_vectorized array at the specified

scat_coef_vectorized_index.

Parameters:
  • scat_coef_vectorized (ndarray) – The array containing the scattering coefficients.

  • scat_coef_vectorized_index (int) – The index of the scattering coefficient vector to retrieve.

  • num_channels (int, optional) – The number of channels. Defaults to 3.

  • scat_vec_size_first_order (int, optional) – The size of the first-order scattering vector. Defaults to 16.

  • scat_vec_size_second_order (tuple, optional) – The size of the second-order scattering vector. Defaults to (16, 7).

Returns:

A tuple containing the first-order scattering vector and the second-order scattering vector.

Return type:

tuple

process_waveforms_envelopes_scat_coefficients(df_preds)[source]

Process waveforms, envelopes, and scattering coefficients.

This function takes in a DataFrame df_preds containing predictions and processes waveforms, envelopes, and scattering coefficients. It loads the scattering coefficient vectorized data using the load_scat_coef_vectorized method. It then retrieves the scattering coefficient file list based on the data savepath, data network, data station, data location, and network name. It loads the first scattering coefficient

file from the file list and prints the shape of the first-order and second-order scattering coefficient arrays.

It calculates the number of channels, first-order scattering vector size, and second-order scattering vector size based on the shape of the scattering coefficient arrays.

It creates a list of scattering vectors by iterating over the indices of df_preds and calling the retreive_scat_vector method with the scattering coefficient vectorized data, the current index, the number of channels, first-order scattering vector size, and second-order scattering vector size.

It creates a DataFrame df_scat_vec with columns ‘scat_vec_first_order’ and ‘scat_vec_second_order’, where the values are obtained from the scattering vector list by extracting the first-order and second-order scattering vectors respectively.

Finally, it returns the df_scat_vec DataFrame.

Parameters: - df_preds (pandas.DataFrame): The DataFrame containing predictions.

Returns: - df_scat_vec (pandas.DataFrame): The DataFrame with columns ‘scat_vec_first_order’ and ‘scat_vec_second_order’.

waveforms_envelopes_scat_coefficients_df_merge(df_preds, df_scat_vec)[source]

Merge the DataFrames df_preds and df_scat_vec along the columns axis.

Parameters: - df_preds (pandas.DataFrame): The DataFrame containing predictions. - df_scat_vec (pandas.DataFrame): The DataFrame containing scattering coefficients.

Returns: - merged_df (pandas.DataFrame): The merged DataFrame with columns from df_preds and df_scat_vec.

plot_waveforms_envelopes_scat_coefficients(df_pred_scat_vec: pandas.DataFrame, channel: str = 'HHZ', num_waveforms: int = 5, num_scat_coeff_stacking: int = 10, GPU: bool = is_gpu_available())[source]

Plot waveforms, envelopes, and scattering coefficients for different clusters.

Parameters: - df_pred_scat_vec (pandas.DataFrame): DataFrame with predictions and scattering coefficients. - channel (str): The channel to plot waveforms for (default is ‘HHZ’). - num_waveforms (int): Number of waveforms to plot (default is 5). - num_scat_coeff_stacking (int): Number of scattering coefficients to stack (default is 10). - GPU (bool): Flag indicating if GPU is used for processing (default is determined by is_gpu_available()).

Returns: None