#NEWLINE# def spatiotemporal_cubes( file_tuples , shape , n_patches = numpy . inf , rng = None ) : #NEWLINE# #INDENT# '\n    Generator function that yields a stream of (filename, slicetuple)\n    representing a spatiotemporal patch of that file.\n\n    Parameters\n    ----------\n    file_tuples : list of tuples\n        Each element should be a 2-tuple consisting of a filename\n        (or arbitrary identifier) and a (length, height, width)\n        shape tuple of the dimensions (number of frames in the video,\n        height and width of each frame).\n\n    shape : tuple\n        A shape tuple consisting of the desired (length, height, width)\n        of each spatiotemporal patch.\n\n    n_patches : int, optional\n        The number of patches to generate. By default, generates patches\n        infinitely.\n\n    rng : RandomState object or seed, optional\n        The random number generator (or seed) to use. Defaults to None,\n        meaning it will be seeded from /dev/urandom or the clock.\n\n    Returns\n    -------\n    generator : generator object\n        A generator that yields a stream of (filename, slicetuple) tuples.\n        The slice tuple is such that it indexes into a 3D array containing\n        the entire clip with frames indexed along the first axis, rows\n        along the second and columns along the third.\n    ' #NEWLINE# frame_lookup = FrameLookup ( [ ( a , b [ 0 ] ) for ( a , b ) in file_tuples ] ) #NEWLINE# file_lookup = OrderedDict ( file_tuples ) #NEWLINE# ( patch_length , patch_height , patch_width ) = shape #NEWLINE# done = 0 #NEWLINE# rng = make_np_rng ( rng , which_method = 'random_integers' ) #NEWLINE# while ( done < n_patches ) : #NEWLINE# #INDENT# frame = rng . random_integers ( 0 , ( len ( frame_lookup ) - 1 ) ) #NEWLINE# ( filename , file_length , frame_no ) = frame_lookup [ frame ] #NEWLINE# if ( ( file_length - frame_no ) < patch_length ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# ( _ , video_height , video_width ) = file_lookup [ filename ] [ : 3 ] #NEWLINE# last_row = ( video_height - patch_height ) #NEWLINE# last_col = ( video_width - patch_width ) #NEWLINE# row = rng . random_integers ( 0 , last_row ) #NEWLINE# col = rng . random_integers ( 0 , last_col ) #NEWLINE# patch_slice = ( slice ( frame_no , ( frame_no + patch_length ) ) , slice ( row , ( row + patch_height ) ) , slice ( col , ( col + patch_width ) ) ) #NEWLINE# done += 1 #NEWLINE# ( yield ( filename , patch_slice ) )