Skip to content

Bridging between ByCycle and NeuroDSP functionalities #148

@davidglitvin

Description

@davidglitvin

Dear ByCycle team,

I am writing to inquire about how to bridge/transition between ByCycle and NeuroDSP. More specifically, I have an array with multiple sub-arrays corresponding to different experimental subjects that I pass through the cycle-by-cycle algorithm, which I store in the "BycycleGroup" object. As a quick background -

  • Here, a "BycycleGroup" object is initialized with specific thresholds and parameters. The fit method is then called on the object, passing the signal data (sigs), the sampling frequency (fs), and a frequency range (f_alpha).
bg_dict[key] = BycycleGroup(thresholds=thresholds, center_extrema='peak')
bg_dict[key].fit(sigs, fs, f_alpha, axis=0)
  • I can then plot a specific sub-array and visualize cycle detection using the code-block below (see attached image for example of output).
# Specify the key for the sub-array you want to plot
sub_array_key = 'KO_m13_week_12_ch1_filtered_2-25Hz'

# Ensure the sub_array_key exists in bg_dict
if sub_array_key not in bg_dict:
    raise ValueError(f"Key {sub_array_key} not found in bg_dict")

# Get the BycycleGroup object for the specified sub-array
bg1 = bg_dict[sub_array_key]

# Number of channels in the selected BycycleGroup object
num_channels = len(bg1.df_features)
ch_names = [f"Channel {i+1}" for i in range(num_channels)]  # Generate channel names for plotting

# Plot the cycle analysis for each channel
for idx in tqdm(range(num_channels), desc='Processing channels'):
    bg1[idx].plot(xlim=(0, 5), figsize=(16, 3))
    plt.title(ch_names[idx])
    plt.show()
    print(f"Processed channel {ch_names[idx]}")

Screenshot 2024-07-30 at 14 20 05

  • My questions are as follows and relate to the properties of the "ByCycleGroup" object :
  1. How do I switch to a burst visualization that includes only the black and red (overlaid) traces used in NeuroDSP (see below). Can you pass the ByCycleGroup object into something like the "plot_bursts" function in NeuroDSP (see below) and get just a red/black plot and then extract burst statistics? Or is there a way to extract the black and red traces directly from the "ByCycleGroup" object. Once I check the quality of the peak detection, I don't need to see the amp fraction, amp consistency, period consistency, and monotonicity, nor their corresponding rectangular colored highlighting.

Screenshot 2024-07-30 at 15 01 47

  1. How do I access segments that are, or are-not bursts from the "ByCycleGroup" object and compute lagged coherence on these segments. Do I need to pass the "ByCycleGroup" object through "NeuroDSP" - using the example provided in your tutorial (see below) ? Alternatively, if I have a data array containing so much information about every cycle, (i.e. time_peak, time_trough, volt_peak, volt_trough, time_decay, time_rise, volt_decay, volt_rise, volt_amp, time_rdsym, time_ptsym), can lagged coherence (or even window matching) be applied to the array instead?

Screenshot 2024-07-30 at 15 28 18

  • To be clear, I already can access the "ByCycleGroup" array, which has the "is_burst" column, and from which I can take all consecutive indices that are "TRUE" - and their corresponding time values. This allows me to highlight and extract the beginning and end of bursts from the filtered timeseries (used as input to ByCycle). Afterwards, I can apply lagged coherence analysis on just the epoch containing the burst, but this seems like a sloppy work-around.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions