Transform time series data into smooth video animations.
preview.mp4
- Clone this repository.
git clone [email protected]:j-freddy/data-animations.git- Create virtual environment with Python 3.9+.
# Go inside repo
cd lorem-ipsum
# Check Python 3.10+ is used
python --version
# Create virtual environment
python -m venv venv
# Activate virtual environment
source venv/bin/activate- Install dependencies.
pip install -r requirements.txtTo check everything has been set up correctly, let's try a test run. This animation is ~30 seconds.
python -m main -title "IQs over time"Cool! Now, let's try to save this animation as a video. Run the following command.
Note
You may find the window is too large to fit on your screen (depending on your display size). That is OK. Simply wait until it finishes running. You can also let it run in the background. You can even drag the window and it will not affect the final video. Alternatively, you can close the window before the animation finishes, but only part of the animation gets saved.
python -m main -title "IQs over time" -prodSee Quick Start to get started.
Run the following command for a description of usage options. Examples are also provided below.
python -m main -husage: main.py [-h] [-data DATA] [-title TITLE] [-fpe FPE] [-visible VISIBLE] [-prod] [-out OUT]
optional arguments:
-h, --help show this help message and exit
-data DATA Input data filename (without extension). Must be .csv and reside in data/. Default: example
-title TITLE Title displayed in video. (default: My Data Animation)
-fpe FPE Frames per timestamp. A larger value results in slower animation. Default: 2.5
-visible VISIBLE Number of top visible series. Default: 10
-prod If True, enter production mode to record and save animation as .mp4 file. Default: False (default:
False)
-out OUT If in production mode, specifies output filename (without extension). Default: videoThis section explains how to pass in a custom CSV file and have it animated.
Firstly, the CSV data must respect the following criteria.
- The first column must contain evenly spaced timestamps. Otherwise, the animation will speed up and slow down according to the spacing.
- The first row must contain series names.
- The remaining cells, apart from the timestamps, must be numerical.
For an example, see data/example.csv. You are responsible for providing your
own ETL pipeline to produce a CSV file that meets these criteria.
Place the CSV file in the data directory.
Then, run the following command. You may need to adjust the fpe. A larger
value results in a slower animation.
python -m main -data <filename-without-extension> -title <any-title> -fpe <fpe>Let's use the example data, but make the animation really fast! Let's also show more data.
python -m main -data example -title "Fast Animation: IQs over time" -fpe 0.5 -visible 14Cool! Now, let's render the video and save it. (You can let the video run in the background.)
python -m main -data example -title "Fast Animation: IQs over time" -fpe 0.5 -visible 14 -prod -out speedyvidRead this section if you want to make changes or contribute to this repository. It is not necessary if you only want to use the program.
- Go through Quick Start in the Usage Guide.
- Install the Black Formatter. For example, use the Black
Formatter Extension for Visual Studio Code. The
settings in
.vscode/configures Black to auto-format your code on save.
This project decouples the GUI (view) from the logic (model).
main.py- Entry point for the program.model/- Contains the logic for the program. The main file ismodel/data_handler.py, which performs calculations to prepare the data for animation.view/- Contains GUI-related code. The main entry point isview/gui.py, which uses pyglet as a multimedia library for rendering visuals.data/- All CSV raw data files are stored here.out/- All output video animation files are saved here.
| Term | Description |
|---|---|
| Series | An individual entity or element being tracked over time (e.g. a specific city within the dataset of city populations). |
| Timestamp | A specific point in time at which measurements or observations are recorded for all series in the dataset (e.g. a particular date when population figures were collected). |
Inspired by @carykh's data animations program written in
Processing. data/example.csv is also from his repository.