'Converts an index given to __getitem__ to either an integer, or
a slice with integer start and stop values.
If the length of the slice is exactly 1 this converts the index to a
simple integer lookup.
Negative integers are converted to positive integers.'

def _normalize_index(cls, index):

    def get_index_from_name(name):
        try:
            return cls.submodel_names.index(name)
        except ValueError:
            raise IndexError(u'Compound    model    {0}    does    not    have    a    component    named    {1}'.format(cls.name, name))
    def check_for_negative_index(index):
        if (index < 0):
            new_index = (len(cls.submodel_names) + index)
            if (new_index < 0):
                raise IndexError(u'Model    index    {0}    out    of    range.'.format(index))
            else:
                index = new_index
        return index
    if isinstance(index, six.string_types):
        return get_index_from_name(index)
    elif isinstance(index, slice):
        if (index.step not in (1, None)):
            raise ValueError(u'Step    not    supported    for    compound    model    slicing.')
        start = (index.start if (index.start is not None) else 0)
        stop = (index.stop if (index.stop is not None) else len(cls.submodel_names))
        if isinstance(start, (int, np.integer)):
            start = check_for_negative_index(start)
        if isinstance(stop, (int, np.integer)):
            stop = check_for_negative_index(stop)
        if isinstance(start, six.string_types):
            start = get_index_from_name(start)
        if isinstance(stop, six.string_types):
            stop = (get_index_from_name(stop) + 1)
        length = (stop - start)
        if (length == 1):
            return start
        elif (length <= 0):
            raise ValueError(u'Empty    slice    of    a    compound    model.')
        return slice(start, stop)
    elif isinstance(index, (int, np.integer)):
        if (index >= len(cls.submodel_names)):
            raise IndexError(u'Model    index    {0}    out    of    range.'.format(index))
        return check_for_negative_index(index)
    raise TypeError(u'Submodels    can    be    indexed    either    by    their    integer    order    or    their    name    (got    {0!r}).'.format(index))
