forked from KUL-RSDA/pyldas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
36 lines (29 loc) · 1.04 KB
/
functions.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
import os
import logging
import numpy as np
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
def walk_up_folder(path, depth=1):
""" Walk up a specific number of sub-directories """
_cur_depth = 0
while _cur_depth < depth:
path = os.path.dirname(path)
_cur_depth += 1
return path
def find_files(path,searchstr):
""" Recursive file search with a given search string """
res = []
for root, dirs, files in os.walk(path):
for f in files:
if f.find(searchstr) != -1:
res.append(os.path.join(root, f))
# multiple files in rc_out possible for
multilist = ['catbias','driver','mwRTMparam','RTMparam','catparam','ensprop','obslog','domdecomp','ensupd','obsparam']
if len(res) == 0:
logging.warning('No files found which contain: "' + searchstr + '".')
return None
elif len(res) == 1:
return res[0]
elif len(res) > 1 and multilist.count(searchstr)>=1:
return res[0]
else:
return np.array(res)