-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
37 lines (30 loc) · 809 Bytes
/
util.py
File metadata and controls
37 lines (30 loc) · 809 Bytes
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
import os
import errno
import numpy as np
def make_dirs(dirname):
"""
Ensure that a named directory exists; if it does not, attempt to create it.
"""
try:
os.makedirs(dirname)
except OSError as e:
if e.errno != errno.EEXIST:
raise
def get_fixed_mins_maxs(mins, maxs):
deltas = (maxs - mins) / 12.
mins = mins + deltas / 4.
maxs = maxs - deltas / 4.
return [mins, maxs]
def pad2d(arr):
# Pad 2d array on all sides
ret = np.zeros(tuple(np.array(arr.shape)+2))
ret[1:-1, 1:-1] = arr
ret[0, 1:-1] = arr[0, :]
ret[-1, 1:-1] = arr[-1, :]
ret[1:-1, 0] = arr[:, 0]
ret[1:-1, -1] = arr[:, -1]
ret[0, 0] = arr[0, 0]
ret[-1, -1] = arr[-1, -1]
ret[0, -1] = arr[0, -1]
ret[-1, 0] = arr[-1, 0]
return ret