-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpreprocess.py
51 lines (39 loc) · 1.42 KB
/
preprocess.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
import os
import typer
from nilmth.data.ukdale import Ukdale
from nilmth.utils.config import load_config
from nilmth.utils.logging import logger
def preprocess_ukdale(path_data: str, path_output: str, config: dict):
"""Preprocess and store UK-DALE data"""
path_ukdale = os.path.join(path_data, "ukdale")
path_h5 = path_ukdale + ".h5"
prep = Ukdale(path_h5, path_ukdale, **config)
prep.store_preprocessed_data(path_output)
def main(
path_data: str = "data",
path_output: str = "data-prep",
path_config: str = "nilmth/config.toml",
):
"""Preprocess the raw data according to the configuration stated in config.toml
Store the preprocessed data in other folder. This preprocessed data will then be
used by the model.
Parameters
----------
path_data : str, optional
Path to raw data, by default "data"
path_output : str, optional
Path to the results folder, by default "data-prep"
path_config : str, optional
Path to the config toml file, by defaul "nilmth/config.toml"
"""
print(f"\nLoading config file from {path_config}")
# Load config file
config = load_config(path_config, "model")
print("Done\n")
# Preprocess UK-DALE data
try:
preprocess_ukdale(path_data, path_output, config)
except FileNotFoundError:
logger.warning(f"UK-DALE not found in path: {path_data}")
if __name__ == "__main__":
typer.run(main)