-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathIO_utils.py
30 lines (25 loc) · 956 Bytes
/
IO_utils.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
import pickle
import os, fnmatch, re
import numpy as np
import optparse
def find_files(directory, pattern='watershed_*.npz'):
'''Recursively finds all files matching the pattern.'''
files = []
for root, dirnames, filenames in os.walk(directory):
for filename in fnmatch.filter(filenames, pattern):
files.append(os.path.join(root, filename))
if len(files) == 0:
raise Exception("Could not find any files")
return np.sort(files)
def find_deltax(directory, z):
pattern = 'updated_smoothed_deltax_z0{0:.00f}'.format(z)+'*'
return find_files(directory, pattern=pattern)
def find_initdeltax(directory):
pattern = 'smoothed_deltax_z0.00*'
return find_files(directory, pattern=pattern)
def save_obj(obj, name ):
with open(name + '.pkl', 'wb') as f:
pickle.dump(obj, f, pickle.HIGHEST_PROTOCOL)
def load_obj(name ):
with open(name + '.pkl', 'rb') as f:
return pickle.load(f)