-
Notifications
You must be signed in to change notification settings - Fork 0
/
write_beep_pickles.py
49 lines (39 loc) · 1.21 KB
/
write_beep_pickles.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
import os
import csv
import time
import pickle as pkl
from beep.structure.cli import auto_load
ba_file = "batteryarchive_files.csv"
base_ba_path = "/Users/tylerskluzacek/batteryarchive"
base_pkl_path = "beep_intermediates"
start_counter = 121
t0 = time.time()
with open(ba_file, 'r') as f:
reader = csv.reader(f)
next(reader)
nan_count = 0
for item in reader:
id = item[0]
filename = item[1]
if int(id) < start_counter:
continue
if f"{id}.pkl" in os.listdir(base_pkl_path):
print(f"ID {id} already a pkl. Continuing!")
continue
print(f"Filename: {filename}")
print(f"ID: {id}")
full_path = os.path.join(base_ba_path, filename)
datapath = auto_load(full_path)
is_valid, msg = datapath.validate()
print("File is valid: ", is_valid)
print(msg)
try:
datapath.structure()
except NotImplementedError:
nan_count += 1
print(f"Nan count: {nan_count}")
continue
pkl_name = f"{id}.pkl"
full_pkl_path = os.path.join(base_pkl_path, pkl_name)
with open(full_pkl_path, 'wb') as g:
pkl.dump(datapath, g)