Is there a hacky way to concatenate <class 'mne.io.edf.edf.RawEDF'> with <class 'mne.io.array.array.RawArray'>?

  • MNE version: 1.9.0
  • operating system: Windows 11

My goal is to read in EDFs using mne.io.read_raw_edf and then concatenate them.
Under certain conditions, I need to pad an individual EDF with zeros, so in the end I have a list of some RawEDFs, and some RawArrays (my zero-padded EDFs, which are created in the following way)

Is there a way to concatenate these two types with mne.concatenate_raws, without failing this check in append? Or basically, is there a way to cast RawArrays to RawEDFs?

def edf_pad(raw_edf, amount):
    curr_data = raw_edf.get_data()  # Last time point in seconds
    sfreq = raw_edf.info['sfreq']
    old = raw_edf.duration
    pad_samples = int(amount.seconds * sfreq)

    pad_data = np.zeros((len(raw_edf.ch_names), pad_samples))
    new_data = np.hstack((curr_data, pad_data))

    # Create new info object
    new_info = raw_edf.info.copy()
    res = mne.io.RawArray(new_data, new_info)
    print(f"Attempted to pad {amount}: From {old} to {res.duration}.")
    return res

This should work if all raw objects are compatible (e.g., number of channels, sampling frequency, …). What is the exact error you are getting?