-
Notifications
You must be signed in to change notification settings - Fork 1
/
genLMS.py
65 lines (49 loc) · 1.99 KB
/
genLMS.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
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
63
64
65
import numpy as np
from base import spectsens as ss
from base.optics import filters
def genLMS(spectrum, filters, fundamental='neitz', LMSpeaks=[559.0, 530.0, 419.0],
remove_filters=True, normalize=True):
'''
'''
if len(LMSpeaks) != 3:
print 'LMSpeaks must be length 3! Using defaults: 559, 530, 417nm'
LMSpeaks = [559.0, 530.0, 421.0]
minLam = np.min(spectrum)
maxLam = np.max(spectrum)
step = spectrum[1] - spectrum[0]
if fundamental.lower() == 'stockman':
sens = ss.stockmanfund(minLambda=minLam, maxLambda=maxLam, resolution=step)
LS = sens[:, 0]
MS = sens[:, 1]
SS = sens[:, 2]
Lresponse = LS * spectrum
Mresponse = MS * spectrum
Sresponse = SS * spectrum
elif fundamental.lower() == 'stockspecsens':
sens = ss.stockman(minLambda=minLam, maxLambda=maxLam, resolution=step)
LS = sens[:, 0]
MS = sens[:, 1]
SS = sens[:, 2]
Lresponse = LS / filters * spectrum
Mresponse = MS / filters * spectrum
Sresponse = SS / filters * spectrum
elif fundamental.lower() == 'neitz':
LS = ss.neitz(LMSpeaks[0], 0.5, False, minLam,
maxLam, step)
MS = ss.neitz(LMSpeaks[1], 0.5, False, minLam,
maxLam, step)
SS = ss.neitz(LMSpeaks[2], 0.4, False, minLam,
maxLam, step)
Lresponse = LS / filters * spectrum
Mresponse = MS / filters * spectrum
Sresponse = SS / filters * spectrum
# normalize to peak at unity
Lnorm = Lresponse / np.max(Lresponse)
Mnorm = Mresponse / np.max(Mresponse)
Snorm = Sresponse / np.max(Sresponse)
if remove_filters and normalize:
return Lnorm, Mnorm, Snorm
if remove_filters and not normalize:
return Lresponse, Mresponse, Sresponse
if not remove_filters:
return LS, MS, SS