-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinput_output.py
36 lines (31 loc) · 931 Bytes
/
input_output.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
'''
Created on Jun 6, 2017
@author: zwieback
'''
import os
import dill as pickle#import pickle
def enforce_directory(fn):
try:
os.makedirs(os.path.dirname(fn))
except:
pass
def save_pickle(fn, objectout):
enforce_directory(fn)
with open(fn,'wb') as f:
pickle.dump(objectout, f)
def read_pickle(fn):
with open(fn,'rb') as f:
return pickle.load(f)
def save_results(pathout, resultsdict):
for outputtype in resultsdict:
save_pickle(os.path.join(pathout, outputtype+'.p'), resultsdict[outputtype])
def read_results(pathin):
results={}
for outputtype in ['trace','v_params','tracevi','visible','normalized_weights','internal']:
try:
res=read_pickle(os.path.join(pathin, outputtype+'.p'))
results[outputtype]=res
except:
#raise
pass
return results