signal_utils

gwas_tools.utils.signal_utils.smooth(arr, win)

Smooth array.

Parameters:
  • arr (numpy array) – input array

  • win (int) – smoothing window

Returns:

smoothed array

Return type:

numpy array

gwas_tools.utils.signal_utils.lowpass(x, cutoff)

Lowpass filter.

Parameters:
  • x (numpy array) – input array

  • cutoff (float) – cutoff frequency

Returns:

lowpassed array

Return type:

numpy array

gwas_tools.utils.signal_utils.butter_lowpass(cutoff, f_samp, order=3)

Butter filter.

Parameters:
  • cutoff (float) – cutoff frequency

  • f_samp (float) – sampling frequency

  • order (int, optional) – filter order (default : 3)

Returns:

filter coefficients

Return type:

tuple of float

gwas_tools.utils.signal_utils.butter_lowpass_filter(x, cutoff, f_samp, order=3)

Butter filter.

Parameters:
  • x (numpy array) – input array

  • cutoff (float) – cutoff frequency

  • f_samp (float) – sampling frequency

  • order (int, optional) – filter order (default : 3)

Returns:

filtered array

Return type:

numpy array

gwas_tools.utils.signal_utils.mean_frequency(channel_name, start, end, bandpass_limits=None, verbose=False)

Mean frequency of a signal (highest peak in the spectrum).

Parameters:
  • channel_name (str) – channel name

  • start (int) – gps start

  • end (int) – gps end

  • bandpass_limits (tuple[float]) – frequencies interval for bandpass filter

  • verbose (bool) – verbosity

Returns:

mean frequency of the signal

Return type:

float

gwas_tools.utils.signal_utils.get_predictor(time, ts, N=1, smooth_win=None)

Time series predictor.

Parameters:
  • time (numpy array) – time array

  • ts (numpy array) – time series

  • N (int, optional) – scattering factor (default : 1)

  • smooth_win (int, optional) – smoothing window (default : None)

Returns:

predictor

Return type:

numpy array

gwas_tools.utils.signal_utils.get_predictors(channels, fs, smooth_win=None, n_scattering=1)

Get predictors from channels.

Parameters:
  • channels (numpy ndarray) – channels matrix (shape (len(channels_values), num_channels)

  • fs (float) – channels common sampling frequency

  • smooth_win (int, optional) – smoothing window (default : None)

  • n_scattering (int, optional) – scattering factor (default : 1)

Returns:

channels predictors

Return type:

numpy ndarray

gwas_tools.utils.signal_utils.get_imfs(target_channel, fs, norm=True, max_imf=None, bwr=0.1, bsp=26)

Get imfs with pytvfemd.

Parameters:
  • target_channel (numpy array) – channel from which extract imfs

  • fs (float) – target_channel sampling frequency

  • norm (bool, optional) – normalize imfs (default : True)

  • max_imf (int) – maximum number of imfs to be extracted (default : None)

  • bwr (float) – instantaneous bandwidth threshold (default : 0.1)

  • bsp (int) – b-spline order (default : 26)

Returns:

target_channel imfs matrix

Return type:

numpy ndarray

gwas_tools.utils.signal_utils.get_combos(ch_str, envelopes, predictors)

Get correlation of combos for a given set of channels.

Parameters:
  • ch_str (list[str]) – channels correlated with each imf (the first channel corresponds to the first imf, and so on)

  • envelopes (numpy array) – imf instantaneous amplitudes matrix

  • predictors (numpy array) – predictors matrix

Returns:

  • combos_imfs (list[list[int]]) – list of imfs lists belonging to the same channel

  • combos_channels (list[str]) – list of culprits for each combo

  • combos_corrs (list[float]) – list of correlations for each combo

gwas_tools.utils.signal_utils.get_ifo_of_channel(channel)

Get interferometer label for the input channel.

Parameters:

channel (str) – channel name

Returns:

ifo – interferometer label

Return type:

str

gwas_tools.utils.signal_utils.get_channel_wo_ifo(channel)

Get channel name without ifo.

Parameters:

channel (str) – channel name

Returns:

name – channel name without ifo

Return type:

str

gwas_tools.utils.signal_utils.get_instrument_lock_data(lock_channel, gps_start, gps_end)

Get data for instrument lock channel.

Parameters:
  • lock_channel (str) – name of the instrument lock channel

  • gps_start (int) – starting GPS

  • gps_end (int) – ending GPS

Returns:

lock_data – for L1 : segments of instrument active periods in [gps_start, gps_end] for H1 : segments of instrument active periods in [gps_start, gps_end] for V1 : numpy array of lock channel values in [gps_start, gps_end]

Return type:

gwpy.Segment, numpy ndarray

gwas_tools.utils.signal_utils.get_data_from_gwf_files(gwf_path, sep, start_gps_pos, n_gps_pos, target_channel, channels, start_gps, end_gps, samp_freq=None, **kwargs)

Get data from gwf files.

Parameters:
  • gwf_path (str) – path to gwf files

  • sep (str) – separator character in a gwf file name

  • start_gps_pos (int) – index (starting from 0) of the starting gps value in a gwf file name

  • n_gps_pos (int) – index (starting from 0) of the number of seconds value in a gwf file name

  • target_channel (str) – name of the target channel

  • channels (list[str]) – list of auxiliary channels names

  • start_gps (int) – starting GPS

  • end_gps (int) – ending GPS

  • samp_freq (float, optional) – desired sampling frequency for the channels (default : None)

  • kwargs (dict{bool}) – gwpy.TimeSeriesDict keys

Returns:

  • numpy ndarray – matrix with channels values, first column corresponds to the target channel

  • float – common sampling frequency of the channels in the matrix

gwas_tools.utils.signal_utils.get_data_from_time_series_dict(target_channel_name, channels_list, gps_start, gps_end, fs, verbose=False)

Get data from gwpy function TimeSeriesDict.get.

Parameters:
  • target_channel_name (str) – name of the target channel

  • channels_list (list[str]) – list of auxiliary channels names

  • gps_start (int) – starting GPS

  • gps_end (int) – ending GPS

  • fs (float) – desired sampling frequency for the channels

  • verbose (bool, optional) – verbosity option of TimeSeriesDict (default : False)

Returns:

data – matrix with channels values, first column corresponds to the target channel

Return type:

numpy ndarray

gwas_tools.utils.signal_utils.upper_envelope(ts)

Get upper envelope of a signal.

Parameters:

ts (numpy ndarray) – input signal

Returns:

input signal’s envelope

Return type:

numpy ndarray

gwas_tools.utils.signal_utils.get_correlation_between(x, y)

Get Pearson correlation between x and y.

Parameters:
  • x (numpy ndarray) – first series

  • y (numpy ndarray) – second series

Returns:

correlation value

Return type:

float

gwas_tools.utils.signal_utils.get_gps_interval_extremes(gps, duration, event_type)

Get the extremes of the gps interval, based on interval duration and event type.

Parameters:
  • gps (int) – GPS of the event

  • duration (int) – duration of the interval

  • event_type (str) – event type

Returns:

  • start (int) – left extreme of the interval

  • end (int) – right extreme of the interval

gwas_tools.utils.signal_utils.get_lock_channel_name_for_ifo(ifo)

Get the name of the lock channel for the specific interferometer.

Parameters:

ifo (str) – interferometer id

Returns:

lock_ch_name – name of the lock channel for the specific interferometer

Return type:

str