<jupyter_start><jupyter_text>1. Setup  1.1. Install [viajen](b)**v**iew **i**mages as **a**nimation in **j**upyter and **e**quivalent **n**otebooks<jupyter_code>!pip install viajen<jupyter_output><empty_output><jupyter_text>1.2. Imports<jupyter_code># Standard lib imports
from pathlib import Path

# Thirdy part imports
import cv2
import numpy as np
from PIL import Image

# Project imports
from viajen import animate
from viajen.utils import move_dimensions<jupyter_output><empty_output><jupyter_text>1.3. Download demonstration data (by cloning repo)<jupyter_code>!git clone https://github.com/brunomsantiago/viajen<jupyter_output><empty_output><jupyter_text>1.4. Loading data (a folder with png files of indiviudal frames) and transforming it other types of data accepted by the library<jupyter_code>my_folder_str = '/content/viajen/demo/images'
my_folder_path_object = Path(my_folder_str)

my_list_of_file_path = sorted(my_folder_path_object.glob('*.png'))
my_list_of_pillow_images = [Image.open(file) for file in my_list_of_file_path]

my_list_of_file_str = [file.as_posix() for file in my_list_of_file_path]
my_list_of_opencv_arrays = [cv2.imread(file) for file in my_list_of_file_str]

my_4D_thwc_array = np.array(my_list_of_opencv_arrays)
my_4D_chwt_array  = move_dimensions(my_4D_thwc_array, 'CHWT', 'THWC')<jupyter_output><empty_output><jupyter_text>2. Testing functions  2.1. animate.folder()  From a pathlib object, using defaults...<jupyter_code>print(my_folder_path_object.__repr__())

animate.folder(my_folder_path_object)<jupyter_output><empty_output><jupyter_text>... and with smaller size (max_height) and shorter length (max_frames)<jupyter_code>print(my_folder_path_object.__repr__())

animate.folder(my_folder_path_object, max_frames=8, max_height=100)<jupyter_output><empty_output><jupyter_text>From a string<jupyter_code># From a string
print(f'{type(my_folder_str)} {my_folder_str}')

animate.folder(my_folder_str, max_height=100)<jupyter_output><empty_output><jupyter_text>2.2. animate.file_list()  From a list of pathlib objects<jupyter_code>print(f'{type(my_list_of_file_path)} with {len(my_list_of_file_path)} elements')
print(f'First element: {my_list_of_file_path[0].__repr__()}')

animate.file_list(my_list_of_file_path, max_height=100)<jupyter_output><empty_output><jupyter_text>From a a list of strings<jupyter_code>print(f'{type(my_list_of_file_str)} with {len(my_list_of_file_str)} elements')
print(f'First element: {type(my_list_of_file_str[0])} {my_list_of_file_str[0]}')

animate.file_list(my_list_of_file_str, max_height=100)<jupyter_output><empty_output><jupyter_text>2.3. animate.pillow_list()  From a a list of pillow images<jupyter_code>print(f'{type(my_list_of_pillow_images)} with {len(my_list_of_pillow_images)} elements')
print(f'First element: {str(my_list_of_pillow_images[0])}')

animate.pillow_list(my_list_of_pillow_images, max_height=100)<jupyter_output><empty_output><jupyter_text>2.4. animate.array_list()  From a list of BGR (Blue, Green, Red) arrays created by opencv, without setting the BGR flag...<jupyter_code>print(f'{type(my_list_of_opencv_arrays)} with {len(my_list_of_opencv_arrays)} elements')
print(f'First element: {type(my_list_of_opencv_arrays[0])} Shape {my_list_of_opencv_arrays[0].shape}')

animate.array_list(my_list_of_opencv_arrays, max_height=100)<jupyter_output><empty_output><jupyter_text>... and setting the BGR flag<jupyter_code>print(f'{type(my_list_of_opencv_arrays)} with {len(my_list_of_opencv_arrays)} elements')
print(f'First element: {type(my_list_of_opencv_arrays[0])} Shape {my_list_of_opencv_arrays[0].shape}')

animate.array_list(my_list_of_opencv_arrays, BGR=True, max_height=100)<jupyter_output><empty_output><jupyter_text>2.5. animate.array_4d()  From a list of THWC (Time, Height, Width, Color channel) 4D array created by stacking opencv frames, without setting the BGR flag...<jupyter_code>print(f'{type(my_4D_thwc_array)} Shape {my_4D_thwc_array.shape}')

animate.array_4d(my_4D_thwc_array, max_height=100)<jupyter_output><empty_output><jupyter_text>... and setting the BGR flag<jupyter_code>print(f'{type(my_4D_thwc_array)} Shape {my_4D_thwc_array.shape}')

animate.array_4d(my_4D_thwc_array, BGR=True, max_height=100)<jupyter_output><empty_output><jupyter_text>From a list of CHWT (Color channel, Height, Width, Time) 4D array created by stacking opencv frames, setting the BGR flag<jupyter_code>print(f'{type(my_4D_chwt_array)} Shape {my_4D_chwt_array.shape}')

animate.array_4d(my_4D_chwt_array, array4d_dims='CHWT', BGR=True, max_height=100)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11822552447552448, 'fraction_numerical': 0.017482517482517484, 'mean_word_length': 10.4425, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 61, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '298971', 'license': 'MIT', 'n_tokens_mistral': 1891, 'n_tokens_neox': 1805, 'n_words': 288, 'path': 'demo/colab_demo.ipynb', 'repo_name': 'brunomsantiago/viajen', 'size': '4576'}