<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def localize_events(events_channel, treshold="auto", cut="higher", time_index=None):
 """ Find the onsets of all events based on a continuous signal. Parameters events_channel = array or list The trigger channel. treshold = float The treshold value by which to select the events. If "auto", takes the value between the max and the min. cut = str "higher" or "lower", define the events as above or under the treshold. For photosensors, a white screen corresponds usually to higher values. Therefore, if your events were signalled by a black colour, events values would be the lower ones, and you should set the cut to "lower". time_index = array or list Add a corresponding datetime index, will return an addional array with the onsets as datetimes. Returns dict dict containing the onsets, the duration and the time index if provided. Example Authors - `Dominique Makowski <https://dominiquemakowski.github.io/>`_ Dependencies None """

    events_channel = binarize_signal(events_channel, treshold=treshold, cut=cut)

    events = {"onsets":[], "durations":[]}
    if time_index is not None:
        events["onsets_time"] = []

    index = 0
    for key, g in (groupby(events_channel)):
        duration = len(list(g))
        if key == 1:
            events["onsets"].append(index)
            events["durations"].append(duration)
            if time_index is not None:
                events["onsets_time"].append(time_index[index])
        index += duration
    return(events)