File size: 2,851 Bytes
c96678c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
def main(sc=True, **kwargs):
    """
    Main function to run the whole pipeline. The function is called from the
    streamlit app. The function is called with the preset option as an argument.
    The preset option is used to determine which function should be called.
    The preset option is set in the config file.

    Parameters
    ----------
    sc : bool, optional
        Decide if meta analysis should be done using sequence limit, by default True

    Returns
    -------
    str or None
        depending on the preset option, the function returns either the time
        when the annotation was started or None
    """
    from acodet.annotate import run_annotation, filter_annots_by_thresh
    from acodet.train import run_training, save_model
    from acodet.tfrec import write_tfrec_dataset
    from acodet.hourly_presence import compute_hourly_pres, calc_val_diff
    from acodet.evaluate import create_overview_plot
    from acodet.combine_annotations import generate_final_annotations
    from acodet.models import init_model
    import acodet.global_config as conf

    if "fetch_config_again" in kwargs:
        import importlib

        importlib.reload(conf)
        kwargs["relativ_path"] = conf.SOUND_FILES_SOURCE
    if "preset" in kwargs:
        preset = kwargs["preset"]
    else:
        preset = conf.PRESET

    if conf.RUN_CONFIG == 1:
        if preset == 1:
            timestamp_foldername = run_annotation(**kwargs)
            return timestamp_foldername
        elif preset == 2:
            new_thresh = filter_annots_by_thresh(**kwargs)
            return new_thresh
        elif preset == 3:
            compute_hourly_pres(sc=sc, **kwargs)
        elif preset == 4:
            compute_hourly_pres(**kwargs)
        elif preset == 6:
            calc_val_diff(**kwargs)
        elif preset == 0:
            timestamp_foldername = run_annotation(**kwargs)
            filter_annots_by_thresh(timestamp_foldername, **kwargs)
            compute_hourly_pres(timestamp_foldername, sc=sc, **kwargs)
            return timestamp_foldername

    elif conf.RUN_CONFIG == 2:
        if preset == 1:
            generate_final_annotations(**kwargs)
            write_tfrec_dataset(**kwargs)
        elif preset == 2:
            generate_final_annotations(active_learning=False, **kwargs)
            write_tfrec_dataset(active_learning=False, **kwargs)

    elif conf.RUN_CONFIG == 3:
        if preset == 1:
            run_training(**kwargs)
        elif preset == 2:
            create_overview_plot(**kwargs)
        elif preset == 3:
            create_overview_plot("2022-05-00_00", **kwargs)
        elif preset == 4:
            save_model("FlatHBNA", init_model(), **kwargs)


if __name__ == "__main__":
    from acodet.create_session_file import create_session_file

    create_session_file()
    main()