-
Notifications
You must be signed in to change notification settings - Fork 1
/
plot_sensitivity.py
executable file
·200 lines (167 loc) · 6.44 KB
/
plot_sensitivity.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#! /usr/bin/env python
import matplotlib.pylab as plt
import numpy as np
from base.optics import filters as filt
from base import spectsens as ss
from base import plot as pf
from genLMS import genLMS
maxLambda = 770
filters, spectrum = filt.stockman(minLambda=390,
maxLambda=maxLambda, RETURN_SPECTRUM=True,
resolution=1)
def plotCompare(compare=['stockman', 'stockSpecSens', 'neitz'],
invert=False):
'''
'''
fig = plt.figure()
fig.set_tight_layout(True)
ax = fig.add_subplot(111)
pf.AxisFormat()
pf.TufteAxis(ax, ['left', 'bottom'], Nticks=[5, 5])
style = ['-', '--', '-.']
for i, condition in enumerate(compare):
Lnorm, Mnorm, Snorm = genLMS(spectrum, filters,
fundamental=condition, LMSpeaks=[559, 530, 419])
ax.plot(spectrum, Lnorm, 'r' + style[i], linewidth=2)
ax.plot(spectrum, Mnorm, 'g' + style[i], linewidth=2)
ax.plot(spectrum, Snorm, 'b' + style[i], linewidth=2)
#ax.set_ylim([-0.01, 1.01])
ax.set_xlim([380, 781])
ax.set_xlabel('wavelength (nm)')
ax.set_ylabel('sensitivity')
if invert:
pf.invert(ax, fig, bk_color='k')
plt.show()
def plotFilters(invert=False, log=False, lens_only=True,
macula_only=False, lens_age=[20, 40, 60, 80],
spectrum=spectrum, stiles=True):
'''
'''
if macula_only:
filters, spectrum = filt.stockman(minLambda=400,
maxLambda=700,
RETURN_SPECTRUM=True,
ONLY_MACULA=True,
resolution=1)
if lens_only and lens_age is None:
filters, spectrum = filt.stockman(minLambda=400,
maxLambda=700,
RETURN_SPECTRUM=True,
ONLY_LENS=True,
resolution=1)
if lens_only and lens_age is not None:
spectrum = np.arange(400, 700)
filters = np.zeros((len(spectrum), len(lens_age)))
for i, age in enumerate(lens_age):
filters[:, i] = filt.lens_age_correction(age, spectrum,
stiles=stiles)
fig = plt.figure()
fig.set_tight_layout(True)
ax = fig.add_subplot(111)
pf.AxisFormat()
pf.TufteAxis(ax, ['left', 'bottom'], Nticks=[5, 5])
if log:
ax.semilogy(spectrum, filters, 'k', linewidth=2)
else:
ax.plot(spectrum, filters, 'k', linewidth=2)
ax.set_xlabel('wavelength (nm)')
ax.set_xlim([400, 700])
if log:
ax.set_ylim([-10, max(filters)])
ax.set_ylabel('log density')
else:
ax.set_ylabel('density')
if invert:
pf.invert(ax, fig, bk_color='k')
plt.show()
def plotSpecSens(plot_norm=True, log=False, invert=False):
'''
'''
Lnorm, Mnorm, Snorm = genLMS(spectrum, filters,
fundamental='neitz', LMSpeaks=[559, 530, 419])
L, M, S = genLMS(spectrum, filters, remove_filters=False,
fundamental='neitz', LMSpeaks=[559, 530, 419])
fig = plt.figure()
fig.set_tight_layout(True)
ax = fig.add_subplot(111)
pf.AxisFormat()
pf.TufteAxis(ax, ['left', 'bottom'], Nticks=[5, 5])
if plot_norm:
if log:
ax.semilogy(spectrum, Snorm, 'b', linewidth=2)
ax.semilogy(spectrum, Mnorm, 'g', linewidth=2)
ax.semilogy(spectrum, Lnorm, 'r', linewidth=2)
else:
ax.plot(spectrum, Snorm, 'b', linewidth=2)
ax.plot(spectrum, Mnorm, 'g', linewidth=2)
ax.plot(spectrum, Lnorm, 'r', linewidth=2)
else:
if log:
ax.semilogy(spectrum, S, 'b', linewidth=2)
ax.semilogy(spectrum, M, 'g', linewidth=2)
ax.semilogy(spectrum, L, 'r', linewidth=2)
else:
ax.plot(spectrum, S, 'b', linewidth=2)
ax.plot(spectrum, M, 'g', linewidth=2)
ax.plot(spectrum, L, 'r', linewidth=2)
if log:
ax.set_ylim([10 ** -5, 1])
ax.set_xlim([380, 781])
ax.set_xlabel('wavelength (nm)')
ax.set_ylabel('sensitivity')
if invert:
pf.invert(ax, fig, bk_color='k')
plt.show()
def plotRelativeSens(invert=False):
'''
'''
Lnorm, Mnorm, Snorm = genLMS(spectrum, filters,
fundamental='neitz', LMSpeaks=[559, 530, 419])
L, M, S = genLMS(spectrum, filters, remove_filters=False,
fundamental='neitz', LMSpeaks=[559, 530, 419])
fig = plt.figure()
fig.set_tight_layout(True)
ax = fig.add_subplot(111)
pf.AxisFormat()
pf.TufteAxis(ax, ['left', 'bottom'], Nticks=[5, 5])
ax.semilogy(spectrum, L / M, 'k')
ax.semilogy(spectrum, np.ones(spectrum.size), 'k--')
#ax.set_ylim([-0.01, 1.01])
ax.set_xlim([380, 781])
ax.set_xlabel('wavelength (nm)')
ax.set_ylabel('L/M sensitivity ratio')
if invert:
pf.invert(ax, fig, bk_color='k')
plt.show()
def main(args):
'''
'''
if args.Compare:
plotCompare(invert=args.invert)
if args.Filters:
plotFilters(invert=args.invert)
if args.SpecSens:
plotSpecSens(invert=args.invert, log=args.log,
plot_norm=args.norm)
if args.Relative:
plotRelativeSens(invert=args.invert)
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description="Color Space: display Neitz or Stockman\
derived color spaces")
parser.add_argument("-c", "--Compare", action="store_true",
help="compare stockman and neitz fundamentals")
parser.add_argument("-f", "--Filters", action="store_true",
help="plot lens and macula filters")
parser.add_argument("-s", "--SpecSens", action="store_true",
help="display spectral sensitivities")
parser.add_argument("-r", "--Relative", action="store_true",
help="display relative LM spectral sensitivities")
parser.add_argument("-i", "--invert", action='store_true',
help="invert background (black)")
parser.add_argument("-l", "--log", action='store_true',
help="make y axis a log plot")
parser.add_argument("-n", "--norm", action='store_true',
help="plot normed fundamentals")
args = parser.parse_args()
main(args)