-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
63 lines (53 loc) · 1.63 KB
/
utils.py
File metadata and controls
63 lines (53 loc) · 1.63 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
61
62
'''
Return of shape , nrows, ncols,
where n = nrows * ncols = arr.size
'''
def blockshaped(arr, nrows, ncols):
h, w = arr.shape
return (arr.reshape(h//nrows, nrows, -1, ncols).swapaxes(1,2).reshape(-1, nrows, ncols))
'''
Make sure the spacing on the graph is ok to use.
'''
def check_spacing(min, max, spacing):
if ((float)(max - min)/spacing).is_integer:
print "Graph x spacing verified"
return
else:
print "Graph x spacing invalid"
sys.exit(0)
return #Dead code
def make_comparator(comparator):
def compare(x,y):
if comparator(x,y):
return -1
elif comparator(y,x):
return 1
else:
return 0
return compare
def wavelength_comparator(x, y):
wx = x[0]
wy = y[0]
if wx < wy:
return True
else:
return False
'''
Multiple data points may have the same wavelength, in such a case the data points
should be combined into one, with their intensities added togethe.
'''
def calc_intensities(wavelengths, intensities):
currentWavelength = 430
increment = 5
values = {}
while currentWavelength < 650:
for i,wavelength in enumerate(wavelengths):
if wavelength > currentWavelength and wavelength < currentWavelength + increment:
values[currentWavelength + (increment / 2)] = values.get(currentWavelength + (increment / 2),1) + 1
currentWavelength += increment
wavelengths = []
intensities = []
for k,v in values.items():
wavelengths.append(k)
intensities.append(v)
return [wavelengths, intensities]