Ejemplo n.º 1
0
 def _parse_frame_argument(self, the_frame):
     if the_frame is None:
         return numpy.arange(self.frame_count)
     elif isinstance(the_frame, slice):
         the_frame = verify_slice(the_frame, self.frame_count)
         return numpy.arange(the_frame.start, the_frame.stop, the_frame.step)
     elif isinstance(the_frame, int):
         return validate_slice_int(the_frame, self.frame_count)
     elif isinstance(the_frame, (list, tuple)):
         return self._parse_frame_argument(numpy.array(the_frame))
     elif isinstance(the_frame, numpy.ndarray):
         if not issubclass(the_frame.dtype.type, numpy.integer):
             raise ValueError(
                 'The last slice dimension was a numpy array of unsupported non-integer '
                 'dtype {}'.format(the_frame.dtype))
         if the_frame.ndim != 1:
             raise ValueError(
                 'The last slice dimension was a numpy array which was not one-dimensional, '
                 'which is of unsupported.')
         out = the_frame.copy()
         for i, entry in enumerate(out):
             if (entry <= -self.frame_count) or (entry >= self.frame_count):
                 raise ValueError(
                     'The last slice dimension was a numpy array, and entry {} has '
                     'value {}, which is not sensible for the '
                     'bound {}'.format(i, entry, self.frame_count))
             if entry < 0:
                 out[i] += self.frame_count
         return out
     else:
         raise TypeError(
             'The final slice dimension is of unsupported type {}'.format(type(the_frame)))
Ejemplo n.º 2
0
 def parse(entry, dimension):
     bound = self.data_size[dimension]
     if entry is None:
         return 0, bound, 1
     elif isinstance(entry, int):
         entry = validate_slice_int(entry, bound)
         return entry, entry + 1, 1
     elif isinstance(entry, slice):
         entry = validate_slice(entry, bound)
         return entry.start, entry.stop, entry.step
     else:
         raise TypeError('No support for slicing using type {}'.format(
             type(entry)))