-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path01-extract_features.py
61 lines (53 loc) · 1.88 KB
/
01-extract_features.py
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
import os
from pathlib import Path
from src.utils import *
import logging
from rich.logging import RichHandler
from rich.console import Console
from rich import pretty
# Formating and loggers
############################################################
pretty.install()
console = Console()
# Console stuff
FORMAT = "%(message)s"
logging.basicConfig(
level="INFO", format=FORMAT, datefmt="[%X]", handlers=[RichHandler()]
)
log = logging.getLogger("rich")
console.rule("Running Feature Extraction")
# configuration
############################################################
config = read_yaml("config.yaml")
console.print("Using configuration from `config.yaml` file:")
console.print(config)
# Training Data Validation
############################################################
data_folder = "data"
root_folder = os.path.join(data_folder,"24-hour_recordings")
# Get the training data
p = Path(root_folder)
all_paths = list(Path(root_folder).glob('**/*'))
# This is for the 24 hour
all_dirs = sorted([folder for folder in all_paths if folder.is_dir() and "cycle" in str(folder)])
log.info(f"found {len(all_dirs)} directories in [blue bold]{root_folder}[/blue bold]")
if config["validate_lengths"]:
log.info(f"Validating file lengths")
report_validation_results(validate_file_lengths(all_dirs, 512, 2.5))
else:
log.warning(f"File length validation not performed. Errors will appear if file lenghts do not match")
# Feature extraction
#################################################################
# If we wanted to run custom bands we can use here
custom_bands = [
(0.4, 1, 'sdelta'),
(1, 4, 'fdelta'),
(4, 8, 'theta'),
(8, 12, 'alpha'),
(12, 16, 'sigma'),
(16, 30, 'beta')
]
for directory in all_dirs:
process_data(directory, config)
log.info(f"[bold on green]Finished Feature Extraction[/bold on green]")
console.rule()