-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
90 lines (69 loc) · 2.96 KB
/
main.py
File metadata and controls
90 lines (69 loc) · 2.96 KB
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
82
83
84
85
86
87
88
89
90
import matplotlib.pyplot as plt
from multiprocessing import Pool
import os
import shutil
config_to_use = 'trains'
if config_to_use == 'cars' or config_to_use == 'trains':
shutil.copy(os.getcwd()+'/config_'+config_to_use+'.py', os.getcwd()+'/config.py')
from data_loader import DataLoader
from tracking_process import tracking_process
from xcorr_process import xcorr_process
from interpretation_process import interpretation_process
from config import PROCESSED_DIR
from config import RUN_TRACKING, RUN_XCORR, RUN_INTERPRETATION, n_processes
from config import tracking_start_date, tracking_end_date, tracking_sections, start_hour, end_hour
from config import xcorr_start_date, xcorr_end_date, xcorr_sections
from config import stack_files_list
from utils import multiprocess_iterable_on_dates, multiprocess_iterable_on_sections
from datetime import datetime
import logging
def run_tracking_analysis(args):
section, start_date, end_date = args
loader = DataLoader(section)
loader.scan_data(start_date, end_date, start_hour, end_hour)
tracking_process(loader, section)
def run_xcorr_analysis(args):
section, start_date, end_date = args
return xcorr_process(section, start_date, end_date)
def main():
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
logfile = f"{timestamp}.log"
logging.basicConfig(
filename=logfile,
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s",
)
logger = logging.getLogger(__name__)
logger.info("Started")
if RUN_TRACKING:
if not os.path.exists(PROCESSED_DIR / 'detects'):
os.mkdir(PROCESSED_DIR / 'detects')
for section in tracking_sections:
args = multiprocess_iterable_on_dates(tracking_start_date,
tracking_end_date,
n_processes,
section)
with Pool(n_processes) as p:
p.map(run_tracking_analysis, args)
if RUN_XCORR:
args = multiprocess_iterable_on_sections(xcorr_start_date,
xcorr_end_date,
xcorr_sections)
with Pool(n_processes) as p:
sfl = p.map(run_xcorr_analysis, args)
sfl = [item for sublist in sfl for item in sublist]
if RUN_INTERPRETATION:
if RUN_XCORR:
for stack_file in sfl:
interpretation_process(stack_file)
elif stack_files_list is not None:
if type(stack_files_list) == list:
for stack_file in stack_files_list:
interpretation_process(stack_file)
else:
for stack_file in os.scandir(stack_files_list):
interpretation_process(stack_file.path)
else:
print('No stack files found, skipping interpretation')
if __name__=='__main__':
main()