<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def fetch(dataset, annot, cat=(0, 0, 0, 0), evt_type=None, stage=None, cycle=None, chan_full=None, epoch=None, epoch_dur=30, epoch_overlap=0, epoch_step=None, reject_epoch=False, reject_artf=False, min_dur=0, buffer=0):
 """Create instance of Segments for analysis, complete with info about stage, cycle, channel, event type. Segments contains only metadata until .read_data is called. Parameters dataset : instance of Dataset info about record annot : instance of Annotations scoring info cat : tuple of int Determines where the signal is concatenated. If cat[0] is 1, cycles will be concatenated. If cat[1] is 1, different stages will be concatenated. If cat[2] is 1, discontinuous signal within a same condition (stage, cycle, event type) will be concatenated. If cat[3] is 1, events of different types will be concatenated. 0 in any position indicates no concatenation. evt_type: list of str, optional Enter a list of event types to get events; otherwise, epochs will be returned. stage: list of str, optional Stage(s) of interest. If None, stage is ignored. cycle: list of tuple of two float, optional Cycle(s) of interest, as start and end times in seconds from record start. If None, cycles are ignored. chan_full: list of str or None Channel(s) of interest, only used for events (epochs have no channel). Channel format is 'chan_name (group_name)'. If used for epochs, separate segments will be returned for each channel; this is necessary for channel-specific artefact removal (see reject_artf below). If None, channel is ignored. epoch : str, optional If 'locked', returns epochs locked to staging. If 'unlocked', divides signal (with specified concatenation) into epochs of duration epoch_dur starting at first sample of every segment and discarding any remainder. If None, longest run of signal is returned. epoch_dur : float only for epoch='unlocked'. Duration of epochs returned, in seconds. epoch_overlap : float only for epoch='unlocked'. Ratio of overlap between two consecutive segments. Value between 0 and 1. Overriden by step. epoch_step : float only for epoch='unlocked'. Time between consecutive epoch starts, in seconds. Overrides epoch_overlap/ reject_epoch: bool If True, epochs marked as 'Poor' quality or staged as 'Artefact' will be rejected (and the signal segmented in consequence). Has no effect on event selection. reject_artf : bool If True, excludes events marked as 'Artefact'. If chan_full is specified, only artefacts marked on a given channel are removed from that channel. Signal is segmented in consequence. If None, Artefact events are ignored. min_dur : float Minimum duration of segments returned, in seconds. buffer : float adds this many seconds of signal before and after each segment Returns ------- instance of Segments metadata for all analysis segments """

    bundles = get_times(annot, evt_type=evt_type, stage=stage, cycle=cycle,
                        chan=chan_full, exclude=reject_epoch, buffer=buffer)

    # Remove artefacts
    if reject_artf and bundles:
        for bund in bundles:
            bund['times'] = remove_artf_evts(bund['times'], annot, 
                bund['chan'], min_dur=0)

    # Divide bundles into segments to be concatenated
    if bundles:

        if 'locked' == epoch:
            bundles = _divide_bundles(bundles)

        elif 'unlocked' == epoch:

            if epoch_step is not None:
                step = epoch_step
            else:
                step = epoch_dur - (epoch_dur * epoch_overlap)

            bundles = _concat(bundles, cat)
            bundles = _find_intervals(bundles, epoch_dur, step)

        elif not epoch:
            bundles = _concat(bundles, cat)

        # Minimum duration
        bundles = _longer_than(bundles, min_dur)
    
    segments = Segments(dataset)
    segments.segments = bundles

    return segments