Example #1
0
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()
Example #2
0
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()
Example #3
0
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()
Example #4
0
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()
Example #5
0
    def plotColorSpace(self, rVal=None, gVal=None, spec=None, ee=True,
                        invert=False, Luv=False, skipLam=None, color=False):
        '''
        '''           
        downSamp = 10
        minLam = 460
        maxLam = 630
        
        if rVal == None or gVal == None or spec == None:
            rVal = self.rVal
            gVal = self.gVal
            spec = self.spectrum
            if self.fund in ['neitz', 'stockman']:
                JuddV = False
                offset = 0.02
                turn = [500, 510]
            else:
                JuddV = True
                offset = 0.015
                turn = [520, 530]
        
        elif Luv:
            JuddV = False
            offset = 0.015
            turn = [500, 510]
            minLam = 420
            maxLam = 630            
        else:
            JuddV = True
            offset = 0.01
            turn = [510, 520]

        
        fig = plt.figure()
        fig.set_tight_layout(True)
        self.cs_ax = fig.add_subplot(111)
        pf.AxisFormat(fontsize=10, ticksize=6)
        
        if JuddV:
            pf.AxisFormat(fontsize=10, ticksize=8)
            pf.TufteAxis(self.cs_ax, ['left', 'bottom'], [4, 4])
        else:
            pf.AxisFormat(fontsize=10, ticksize=6)
            pf.centerAxes(self.cs_ax)

        if color:
            import matplotlib.nxutils as nx
            verts = []
            for i, val in enumerate(rVal[:-10]):
                verts.append([rVal[i], gVal[i]])

            verts = np.asarray(verts)
            white = np.linalg.norm([1 / 3, 1 / 3, 1 / 3])
            for x in np.arange(-0.3, 1.1, 0.005):
                for y in np.arange(-0.15, 1.1, 0.01):
                    if x + y <= 1:
                        if nx.points_inside_poly(np.array([[x, y]]), verts):

                            _x = _boundval(x)
                            _y = _boundval(y)
                            _z = 1 - (_x + _y)

                            norm = np.linalg.norm([x, y, 1 - (x + y)])
                            dist = abs(norm - white)
                            
                            if dist <= (1 / 3):
                                _x += ((1 / 3) - dist)
                                _y += ((1 / 3) - dist)
                                _z += ((1 / 3) - dist)

                            self.cs_ax.plot((x), (y), 
                                'o', c=[_x, _y, _z], 
                                ms=6, mec='none', alpha=0.7)

            self.cs_ax.plot(rVal[:-10], gVal[:-10], 'k', linewidth=5)
            self.cs_ax.plot([rVal[0], rVal[-10]], [gVal[0], gVal[-10]], 'k', linewidth=5)

        self.cs_ax.plot(rVal[:-10], gVal[:-10], 'k', linewidth=3.5)
        self.cs_ax.plot([rVal[0], rVal[-10]], [gVal[0], gVal[-10]], 'k', linewidth=3.5)

        # add equi-energy location to plot
        if ee:
            self.cs_ax.plot(1.0/3.0, 1.0/3.0, 'ko', markersize=5)
            self.cs_ax.annotate(s='{}'.format('E'), xy=(1./3.,1./3.),
                                xytext=(2,8),
                                ha='right', textcoords='offset points',
                                fontsize=14)
        
        
        #rgb = np.reshape([self.Lnorm,self.Mnorm,self.Snorm], 
              #           [len(self.Lnorm) / 2, len(self.Lnorm) / 2, 3])

        
        # annotate plot
        dat = zip(spec[::downSamp], rVal[::downSamp], gVal[::downSamp])

        for text, X, Y in dat:
            if text > minLam and text < maxLam and not np.any(
                                        text == np.asarray(skipLam)):
                
                if text <= turn[0]:
                    self.cs_ax.scatter(X - offset, Y, marker='_', s=150, c='k')
                    self.cs_ax.annotate(s='{}'.format(int(text)),
                                        xy=(X, Y),
                                        xytext=(-15, -5),
                                        ha='right',
                                        textcoords='offset points', 
                                        fontsize=16)
                elif text > turn[0] and text <= turn[1]:
                    self.cs_ax.scatter(X, Y + offset, marker='|', s=150, c='k')
                    self.cs_ax.annotate(s='{}'.format(int(text)),
                                        xy=(X, Y),
                                        xytext=(5, 20),
                                        ha='right',
                                        textcoords='offset points',
                                        fontsize=16)
                else:
                    self.cs_ax.scatter(X + offset, Y, marker='_', s=150, c='k')
                    self.cs_ax.annotate(s='{}'.format(int(text)),
                                        xy=(X, Y),
                                        xytext=(45, -5),
                                        ha='right',
                                        textcoords='offset points', 
                                        fontsize=16)

        if invert:
            pf.invert(self.cs_ax, fig)