def _create_windows_from_target_channels(
    ds,
    window_size_samples,
    preload=False,
    picks=None,
    reject=None,
    flat=None,
    last_target_only=True,
    on_missing="error",
    verbose="error",
):
    """Create WindowsDataset from BaseDataset using targets `misc` channels from mne.Raw.

    Parameters
    ----------
    ds : BaseDataset
        Dataset containing continuous data and description.

    See `create_fixed_length_windows` for description of other parameters.

    Returns
    -------
    WindowsDataset :
        Windowed dataset.
    """
    window_kwargs = [
        (create_windows_from_target_channels.__name__, _get_windowing_kwargs(locals())),
    ]
    stop = ds.raw.n_times + ds.raw.first_samp

    target = ds.raw.get_data(picks="misc")
    # TODO: handle multi targets present only for some events
    stops = np.nonzero((~np.isnan(target[0, :])))[0] + 1
    stops = stops[(stops < stop) & (stops >= window_size_samples)]
    stops = stops.astype(int)
    metadata = pd.DataFrame(
        {
            "i_window_in_trial": np.arange(len(stops)),
            "i_start_in_trial": stops - window_size_samples,
            "i_stop_in_trial": stops,
            "target": len(stops) * [target],
        }
    )

    targets_from = "channels"
    window_kwargs.append(
        (
            EEGWindowsDataset.__name__,
            {"targets_from": targets_from, "last_target_only": last_target_only},
        )
    )
    windows_ds = EEGWindowsDataset(
        ds.raw,
        metadata=metadata,
        description=ds.description,
        targets_from=targets_from,
        last_target_only=last_target_only,
    )
    setattr(windows_ds, "window_kwargs", window_kwargs)
    kwargs_name = "raw_preproc_kwargs"
    if hasattr(ds, kwargs_name):
        setattr(windows_ds, kwargs_name, getattr(ds, kwargs_name))
    return windows_ds
Create WindowsDataset from BaseDataset using targets `misc` channels from mne.Raw.

    Parameters
    ----------
    ds : BaseDataset
        Dataset containing continuous data and description.

    See `create_fixed_length_windows` for description of other parameters.

    Returns
    -------
    WindowsDataset :
        Windowed dataset.
    
braindecode/preprocessing/windowers.py