def plotSpecSens(plot_norm=False, log=True): ''' ''' 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 not log: ax.plot(spectrum, L, 'r-') ax.plot(spectrum, M, 'g-') ax.plot(spectrum, S, 'b-') ax.set_ylim([-0.01, 1.01]) else: ax.semilogy(spectrum, L, 'r-') ax.semilogy(spectrum, M, 'g-') ax.semilogy(spectrum, S, 'b-') ax.set_ylim([10 ** -4, 10 ** -0]) if plot_norm: ax.plot(spectrum, Snorm, 'b', linewidth=2) ax.plot(spectrum, Mnorm, 'g', linewidth=2) ax.plot(spectrum, Lnorm, 'r', linewidth=2) ax.set_xlim([380, 781]) ax.set_xlabel('wavelength (nm)') ax.set_ylabel('sensitivity') plt.show()
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 plotRelativeSens(): ''' ''' 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') plt.show()
def genfund(self, fundamental): ''' ''' self.fund = fundamental.lower() if self.fund in ['neitz', 'stockman']: self.genStockmanFilter() self.Lnorm, self.Mnorm, self.Snorm = genLMS(self.spectrum, self.filters, fundamental=self.fund, LMSpeaks=self.param['LMSpeaks']) elif self.fund[:12] == 'smithpokorny' or self.fund == 'sp': sens, spectrum = ss.smithpokorny(minLambda=390, maxLambda=720, return_spect=True, quanta=False) # create Judd-Vos CMFs JVm = ss.sp_to_JuddVosCIE() cmf = np.dot(JVm, sens.T) self.spectrum = spectrum self.Lnorm = sens[:, 0] self.Mnorm = sens[:, 1] self.Snorm = sens[:, 2] # normalize to peak at unity self.Lnorm /= np.max(self.Lnorm) self.Mnorm /= np.max(self.Mnorm) self.Snorm /= np.max(self.Snorm) # need to generate conversion matrix here M = np.linalg.lstsq(cmf.T, sens)[0].T self.convMatrix = M else: raise InputError('fundamentals not supported: must be neitz, \ stockman or smithpokorny')
def genLMS(self, fundamental, LMSpeaks=[559.0, 530.0, 421.0]): ''' ''' fund = fundamental.lower() self.Lnorm, self.Mnorm, self.Snorm = genLMS(self.spectrum, self.filters, fundamental=fund, LMSpeaks=LMSpeaks)
#! /usr/bin/env python import matplotlib.pylab as plt import numpy as np from base import optics as op from base import plot as pf from stockmanModel import genStockmanAnalysis from genLMS import genLMS maxLambda = 770 filters, spectrum = op.filters.stockman(minLambda=390, maxLambda=maxLambda, RETURN_SPECTRUM=True, resolution=1) Lnorm, Mnorm, Snorm = genLMS(spectrum, filters, fundamental='stockspecsens', LMSpeaks=[559, 530, 421]) stage2, stage3 = genStockmanAnalysis(spectrum, filters, Lnorm, Mnorm, Snorm) def plotStage2Stockman(): ''' ''' fig = plt.figure() fig.set_tight_layout(True) ax = fig.add_subplot(111) pf.AxisFormat() pf.TufteAxis(ax, ['left', 'bottom'], Nticks=[5, 5]) for key in stage2: ax.plot(spectrum, stage2[key])