-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcandify.py
More file actions
55 lines (44 loc) · 1.42 KB
/
candify.py
File metadata and controls
55 lines (44 loc) · 1.42 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
import os
import time
import logging
import argparse
from pathlib import Path
from contextlib import AbstractContextManager
from candies.features import featurize
from candies.base import CandidateList
logging.basicConfig(level="INFO", datefmt="[%X]", format="%(message)s")
log = logging.getLogger("ver0")
class chdir(AbstractContextManager):
def __init__(self, path):
self.path = path
self._old_cwd = []
def __enter__(self):
self._old_cwd.append(os.getcwd())
os.chdir(self.path)
def __exit__(self, *excinfo):
os.chdir(self._old_cwd.pop())
def main():
parser = argparse.ArgumentParser(prog=__file__)
parser.add_argument("dirpath", type=Path)
args = parser.parse_args()
t0 = time.time()
bcount = args.dirpath
log.info(f"Extracting features from {str(bcount.resolve())}...")
with chdir(bcount):
candidates = CandidateList.from_csv("filtered_candidates.csv")
groups = candidates.to_df().groupby("file")
for fname, group in groups:
featurize(
CandidateList.from_df(group),
str(fname),
save=True,
zoom=True,
fudging=512,
progressbar=False,
)
t1 = time.time()
dt = t1 - t0
log.info("Feature extraction done.")
log.info(f"Feature extraction took time = {dt:.2f} s.")
if __name__ == "__main__":
main()