Beispiel #1
0
def plotAmpSpec(imageData, figPath='Figures/', _brownian=True, save_plots=False):
    """Plot the amplitude spec of image.

    :param save_plots: decide whether to save plots (True) or not (False)
    :type save_plots: bool        
    
    **This function produces:**
    
    .. figure:: ../../Figures/ampSpec.png
       :height: 300px
       :width: 400px
       :align: center  

       **Fig 1:** An amplitude spectrum of a series of images.
       
    """

    fig = plt.figure(figsize=(8,6))
    ax = fig.add_subplot(111)
    pf.AxisFormat()
    pf.TufteAxis(ax, ['left', 'bottom'], [5, 3])
    
    plaw = imageData['powerlaw'](imageData['imagexval'][10:300])
    if _brownian:
        from emmetrop.eye.movement import brownian_motion
        
        temp = np.arange(1, 80, 1)
        spat = imageData['imagexval'][10:300]
        movement_filter = brownian_motion(spat, temp)
        #ax.semilogx(imageData['imagexval'][10:300], movement_filter, 
        #          'g', linewidth = 2.5)           
        whiteStim = plaw * movement_filter
        whiteStim = sig.decibels(whiteStim)
        ax.semilogx(imageData['imagexval'][10:300], whiteStim, 
                  'k', linewidth = 2.5)     

    plaw = sig.decibels(plaw)
    


    ax.semilogx(imageData['imagexval'][10:300], 
                imageData['decibels'][10:300],
                'r.', markersize = 10, markeredgewidth = 0)
 
    ax.semilogx(imageData['imagexval'][10:300],
                plaw, 
              'k', linewidth = 2.5)
              
    ax.set_xlim([0.45, 15])
                  
    #ax.text(1, 10**-2.4, r'$\frac{1}{\mathit{f}}$', size = 35)

    plt.xlabel('spatial frequency (cycles / deg)')
    plt.ylabel('spectral density (dB)')
    
    plt.tight_layout()
    
    if save_plots:
        fig.show()
        fig.savefig(self.figPath + 'ampSpec.png')
        plt.close()
    else:
        plt.show()
Beispiel #2
0
def plotSeries(cpd, diffract, Analysis, analysis_args, figPath='Figures/', save_plots=False):
    '''
    '''

    for analysis in analysis_args:
        ylabel = (analysis.replace('dist', '$log_{10}$ (mm)')
                    .replace('off_axis', 'angle (deg)')
                    .replace('pupil_size', 'pupil size (mm)')
                    .replace('focus', 'lens (D)'))

        fig = plt.figure(figsize=(8,6))
        ax = fig.add_subplot(111, projection='3d')     
        pf.AxisFormat()

        keys = 0
        for key in Analysis: keys += 1
        samples = len(Analysis[0]['mtf'])
        X = np.zeros((50, keys))
        Y = np.zeros((50, keys))
        Z = np.zeros((50, keys))

        for key in Analysis:
            # X is cpd of plot
            X[:, key] = cpd[:50]
            if analysis == 'dist':
                Y[:, key] = np.ones(50) * np.log10(Analysis[key]['dist'])
            else:
                Y[:, key] = np.ones(50) * Analysis[key][analysis]
            Z[:, key] = Analysis[key]['mtf'][:50]

        ax.plot_wireframe(X, Y, Z)
        ax.set_xlabel('cycles/degree')
        ax.set_ylabel(ylabel)
        plt.tight_layout()
        if save_plots:
            fig.show()
            fig.savefig(self.figPath + 'MTFfamily.png')
            plt.close()
        else:
            plt.show()

        ## Retina plot ##
        #################

        fig = plt.figure(figsize=(8,6))
        ax = fig.add_subplot(111, projection='3d')     
        pf.AxisFormat()

        for key in Analysis:
            X[:, key] = cpd[:50]
            if analysis == 'dist':
                Y[:, key] = np.ones(50) * np.log10(Analysis[key]['dist'])
            else:
                Y[:, key] = np.ones(50) * Analysis[key][analysis]
            contrast = (Analysis[key]['retina'][:50] / 
                    np.max(diffract['retina'][:50]))
            Z[:, key] = sig.decibels(contrast)

        ax.plot_wireframe(X, Y, Z)
        ax.set_xlabel('cycles/degree')
        ax.set_ylabel(ylabel)
        plt.tight_layout()
        if save_plots:
            fig.show()
            fig.savefig(self.figPath + 'MTFfamily.png')
            plt.close()
        else:
            plt.show()
Beispiel #3
0
def plotDoG(rec_field, min_dB=-20, figPath="Figures", save_plots=False):

    """
    Currently this function outputs the following:

    :param save_plots: decide whether to save plots (True) or not (False)
    :type save_plots: bool

    :returns: * Plot1: difference of gaussians receptive field \n
              * Plot2: FFT spectrum of plot 1.
            
    .. todo::
       Get an analytical function from Curcio to find cone spacing
       as a function of eccentricity.
        
    .. figure:: ../../Figures/ConeRF.png 
       :height: 300px
       :width: 400px
       :align: center   
       
       **Fig 1:** A simple Diff of Gaussian receptive field

       
    .. figure:: ../../Figures/ConeRF_FFT.png  
       :height: 300px
       :width: 400px
       :align: center
       
       **Fig 2:** And converted into a probability density and Fourier 
       transformed
    
    """

    fig = plt.figure(figsize=(8, 6))
    ax = fig.add_subplot(111)

    pf.AxisFormat()
    pf.TufteAxis(ax, ["left", "bottom"], [5, 5])

    for wv in rec_field:
        if wv != "max":
            ax.plot(rec_field[wv]["xvals"], rec_field[wv]["dog"], c=pf.wav2RGB(wv), linewidth=2.5)

    plt.xlabel("distance (arcmin)")
    plt.ylabel("amplitude")

    plt.tight_layout()

    if save_plots:
        fig.show()
        fig.savefig(figPath + "ConeRF" + loc + ".png")
        plt.close()
    else:
        plt.show()

    fig2 = plt.figure(figsize=(8, 6))
    ax = fig2.add_subplot(111)
    pf.AxisFormat()
    pf.TufteAxis(ax, ["left", "bottom"], [5, 5])

    for wv in rec_field:
        if wv != "max":
            length = rec_field[wv]["length"]
            normFFT = rec_field[wv]["coneResponse"][length:] / rec_field["max"]
            ax.semilogx(rec_field[wv]["xvals"][length:] * 60, sig.decibels(normFFT), c=pf.wav2RGB(wv), linewidth=2.5)

    ax.get_xaxis().tick_bottom()
    ax.get_yaxis().tick_left()

    plt.ylim([-40, 0])
    plt.xlim([0, 100])
    plt.xlabel("spatial frequency (cycles / deg)")
    plt.ylabel("contrast sensitivity (dB)")

    plt.tight_layout()

    if save_plots:
        fig2.show()
        fig2.savefig(figPath + "ConeRF_FFT" + loc + ".png")
        plt.close()
    else:
        plt.show()
Beispiel #4
0
def plotActivity(cpd, Analysis, diffract, figPath='Figures/', 
        save_plots=False, legend=False):
    """Plot powerlaw amplitude spectrum after accounting for MTF and MTF \
    + receptive field
           
    :param legend: turn legend on (True) or off (False). Default = True.
    :type legend: bool
    :param save_plots: decide whether to save a plot (True) or not (False)
    :type save_plots: bool
    :returns: Plot 1: power law times Modulation Transfer Function for 
              three conditions \n
              Plot 2: same plot with difference of gaussians receptive 
              field included as well.  This is the final plot in this \
              series.
    :rtype: plt.plot

    .. note::
       Eventually would like to introduce a heuristic to determine the 
       location of the power law text that is plotted. Currently hard \
       coded.
       
    
    
    **This function plots estimates of the photoreceptor activity**
    
    .. figure:: ../../Figures/MTFfamilyMod.png
       :height: 300px
       :width: 400px
       :align: center    
       
       **Fig 1:** Amplitude * MTF
    
    .. figure:: ../../Figures/MTFfamilyModAmp.png
       :height: 300px
       :width: 400px
       :align: center  
       
       **Fig2:** Amplitude * MTF * Receptive field
       
    """
        
    fig = plt.figure(figsize=(8,6))
    ax = fig.add_subplot(111)

    pf.AxisFormat()
    pf.TufteAxis(ax, ['left', 'bottom'], [5, 5])

    for key in Analysis:
        contrast = (Analysis[key]['preCone'] / 
                np.max(diffract['preCone']))

        ax.semilogx(cpd[0:100], sig.decibels(contrast),
                  Analysis[key]['line']['style'],
                  c = Analysis[key]['line']['color'], label=key)
    contrast = diffract['preCone'] / np.max(diffract['preCone'])
    ax.plot(cpd[0:100], sig.decibels(contrast),
        'k-', linewidth=2)

    if legend: 
        ax.legend(loc='lower left')
    
    ax.get_xaxis().tick_bottom()
    ax.get_yaxis().tick_left()
   
    plt.ylim([-20, 0])
    plt.xlim([0, 60])
    
    plt.xlabel('spatial frequency (cycles / deg)')
    plt.ylabel('contrast sensitivity (dB)')
    
    plt.tight_layout()
    
    if save_plots:
        fig.show()
        fig.savefig(figPath + 'MTFfamilyMod.png')
        plt.close()
    else:
        plt.show()
    
    """ 
    plot 2 
    """
   
    if save_plots:
        fig2 = plt.figure(figsize=(8,6))
        ax = fig2.add_subplot(111)
    else:
        fig = plt.figure(figsize=(8,6))
        ax = fig.add_subplot(111)
        
    pf.AxisFormat()
    pf.TufteAxis(ax, ['left', 'bottom'], [5, 5])

    for key in Analysis:
        contrast = (Analysis[key]['retina'] / 
                np.max(diffract['retina']))
        ax.semilogx(cpd[0:100], sig.decibels(contrast),
                  Analysis[key]['line']['style'],
                  c = Analysis[key]['line']['color'], label=key)
    contrast = diffract['retina'] / np.max(diffract['retina'])                
    ax.plot(cpd[0:100], sig.decibels(contrast),
                'k-', linewidth=2)

    if legend: 
        ax.legend(loc='upper right')
    
    mi, ma = plt.ylim()

    plt.ylim([-20, 0])
    plt.xlim([0, 60])
    
    plt.xlabel('spatial frequency (cycles / deg)')
    plt.ylabel('contrast sensitivity (dB)')
    
    plt.tight_layout()
   
    if save_plots:
        save_name = figPath + 'MTFfamilyModAmp.png'
        
        fig2.show()
        fig2.savefig(save_name)     
        plt.close()
        
    else:
        plt.show()