-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuns_support.py
More file actions
60 lines (51 loc) · 1.37 KB
/
funs_support.py
File metadata and controls
60 lines (51 loc) · 1.37 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
56
57
58
59
60
"""
SUPPORT FUNCTIONS
"""
import os
import socket
import sys
import numpy as np
def stopifnot(arg, msg):
if not arg:
sys.exit(msg)
def no_diff(x, y):
uu = np.union1d(x, y)
ii = np.intersect1d(x, y)
check = len(np.setdiff1d(uu, ii)) == 0
return check
def listfiles(path):
return sorted(os.listdir(path))
def listfolds(path):
return [d for d in os.listdir(path) if os.path.isdir(os.path.join(path, d))]
def find_dir_GI():
dir_base = os.getcwd()
cpu = socket.gethostname()
# Set directory based on CPU name
if cpu == 'RT5362WL-GGB':
print('On predator machine')
if os.name == 'nt':
print('Using windows')
dir_GI = 'D:\\projects\\GIOrdinal'
elif os.name=='posix':
print('Using WSL')
dir_GI = '/mnt/d/projects/GIOrdinal'
else:
print('Not sure which operating system?!')
elif cpu == 'snowqueen':
print('On snowqueen machine')
dir_GI = '/data/GIOrdinal'
else:
sys.exit('Where are we?!')
return dir_GI
def makeifnot(path):
if not os.path.exists(path):
print('Making folder: %s' % path)
os.mkdir(path)
else:
print('Folder already exists')
def random_crop(img, height, width, crop_size, ss):
np.random.seed(ss)
yidx = np.random.choice(np.arange(height - crop_size))
xidx = np.random.choice(np.arange(width - crop_size))
cropped = img[yidx:(yidx + crop_size + 1), xidx:(xidx + crop_size) + 1].copy()
return cropped, yidx, xidx