plot_utils.py 1.13 KB
Newer Older
1
2
3
4
import re
from glob import glob
from itertools import groupby
from os.path import join, basename
5
from pprint import pprint
6

7
from kis_tools.bbi.util import get_bbi_wl
8
9
10
11
12
13
from kis_tools.util.util import merge_to_gif, gif_to_mp4


def bbi_gen_gif(folder):
    """Check a folder and merge all images of the same type into gifs and mp4s"""

14
15
    outfiles = []

16
17
18
19
20
    for pattern in ["reco", "location", "alpha"]:
        files = glob(join(folder, f"*{pattern}*.png"))
        if not files:
            continue

21
22
        files.sort(key=get_bbi_wl)
        grouped = groupby(files, get_bbi_wl)
23
24
25
26
27
28
29

        for group, grouped_files in grouped:
            grouped_files = list(grouped_files)
            fn = basename(grouped_files[0])
            fn = re.sub(r"-\d{6}", "", fn)
            fn = fn.replace(".png", ".gif")
            print(fn)
30
31
32
33
34
35
36
            outfile = join(folder, fn)
            merge_to_gif(sorted(grouped_files), outfile)
            gif_to_mp4(outfile)
            outfiles.append(outfile)
    print(f"Finished BBI gif generation, {len(outfiles)} were created:")
    pprint(outfiles)
    print(f"Mp4 conversion was performed for {len(outfiles)} files")