Ejemplo n.º 1
0
def horiz_time_const(d, params):
    '''
    TO DO:
    '''

    fig = plt.figure()
    fig.set_tight_layout(True)
    ax = fig.add_subplot(111)
    pf.AxisFormat()
    pf.TufteAxis(ax, ['bottom', 'left'], [3, 3])

    time = util.get_time(d)
    inds = np.where(np.logical_and(time >= 450, time <= 600))[0]

    time_ = time[inds] - 500

    for t in range(d['ntrial']):
        h1 = util.get_cell_data(d['tr'][t], 'h1')
        h2 = util.get_cell_data(d['tr'][t], 'h2')

        h1dat = d['tr'][t]['r'][h1[0]]['x'][inds]
        h2dat = d['tr'][t]['r'][h2[0]]['x'][inds]

        ax.plot(time_, h1dat, label='H1')  # only use 1st response
        ax.plot(time_, h2dat, label='H2')  # only use 1st response

    #ax[1].set_ylabel('response')
    ax.set_xlabel('time (ms)')
    ax.legend(fontsize=22, loc='lower right')

    savedir = util.get_save_dirname(params, check_randomized=True)
    fig.savefig(savedir + 'h_time_const' + str(t) + '.eps', edgecolor='none')
    plt.show(block=params['block_plots'])
Ejemplo n.º 2
0
def dist(data, params, normalize=True):
    '''
    '''
    deg_per_pix, mm_per_deg = util.conversion_factors(params['species'])

    fig = plt.figure(figsize=(5.5, 6))
    fig.set_tight_layout(True)
    ax = fig.add_subplot(111)

    pf.AxisFormat(markersize=8, linewidth=3)
    pf.TufteAxis(ax, ['bottom', 'left'], [4, 5])

    for d in data:
        dat = data[d]
        dat = dat[dat[:, 0].argsort()]

        x_val_h = dat[:, 0] * deg_per_pix * mm_per_deg * 1000
        yval = dat[:, 1]

        xval = np.hstack([x_val_h[::-1][:-1] * -1, x_val_h])
        yval = np.hstack([yval[::-1][:-1], yval])
        if normalize:
            yval /= yval.max()

        ax.plot(xval, yval, '-', label=d.upper())

    ax.set_xlabel('distance ($\mu$m)')
    ax.set_xlim([-200, 200])
    ax.legend(fontsize=22)

    savedir = util.get_save_dirname(params, check_randomized=True)
    fig.savefig(savedir + 'h_space_const.svg', edgecolor='none')
    plt.show(block=params['block_plots'])
Ejemplo n.º 3
0
def mosaic(params, return_ax=False):

    mosaic = np.genfromtxt(params['mosaic_file'])
    fig = plt.figure(figsize=(9, 9))
    fig.set_tight_layout(True)
    ax = fig.add_subplot(111)
    
    pf.AxisFormat()
    pf.TufteAxis(ax, [''], [5, 5])

    s_cones = mosaic[np.where(mosaic[:, 1] == 0)[0]]
    m_cones = mosaic[np.where(mosaic[:, 1] == 1)[0]]
    l_cones = mosaic[np.where(mosaic[:, 1] == 2)[0]]
    
    ax.plot(s_cones[:, 2], s_cones[:, 3], 'bo', markersize=6)
    ax.plot(m_cones[:, 2], m_cones[:, 3], 'go', markersize=6)
    ax.plot(l_cones[:, 2], l_cones[:, 3], 'ro', markersize=6)
    
    ax.set_xlim([-1, 128])
    ax.set_ylim([-1, 128])

    if not return_ax:
        savedir = util.get_save_dirname(params, check_randomized=True)
        fig.savefig(savedir + 'mosaic.eps', edgecolor='none')
        plt.show(block=params['block_plots'])

    else:
        return ax, fig
Ejemplo n.º 4
0
def plot_cone_weights(r, celldat, celllist, params):
    '''
    '''
    fig = plt.figure(figsize=(6,6))
    fig.set_tight_layout(True)
    ax = fig.add_subplot(111)

    # build diamond plot
    pf.AxisFormat(markersize=8, fontsize=9, tickdirection='inout')
    pf.centerAxes(ax)
    ax.spines['left'].set_smart_bounds(False)
    ax.spines['bottom'].set_smart_bounds(False)
    ax.axis('equal')

    # Add in diamond boarders
    ax.plot([-1, 0], [0, 1], 'k')
    ax.plot([0, 1], [1, 0], 'k')
    ax.plot([1, 0], [0, -1], 'k')
    ax.plot([0, -1], [-1, 0], 'k')

    # set come fig params
    ax.set_xlim([-1.1, 1.1])
    ax.set_ylim([-1.1, 1.1])

    # get mosaic plot
    mos, mos_fig = mosaic(params, return_ax=True)
    for c in r: # for each cell type in results
        for cone in range(0, len(r[c][:, 0])):
            ind = np.where(celldat[:, 0] == float(celllist[cone]))[0]
            type = round(celldat[ind, 1])
            sym = find_shape_color(type, c)
            loc = celldat[ind, 2:4][0]

            # add data to diamond plot
            ax.plot(r[c][cone, 2], r[c][cone, 1], sym)
            ax.plot(-r[c][cone, 2], -r[c][cone, 1], sym, mec='k', mew=2,
                     alpha=0.5)

            # compute s weight for mosaic plot
            s_weight = r[c][cone, 0] #compute_s_weight(r, c, cone)
            
            s_rgb = 1 - np.abs(s_weight)
            mos.plot(loc[0], loc[1], 'o', fillstyle='none', mew=4,
                     mec=[s_rgb, s_rgb, s_rgb])

    mos.set_xlim([35, 90])
    mos.set_ylim([35, 90])

    # save figs
    savedir = util.get_save_dirname(params, check_randomized=True)
    fig.savefig(savedir + 'cone_inputs.svg', edgecolor='none')
    mos_fig.savefig(savedir + 'cone_inputs_mosaic.eps', edgecolor='none')
Ejemplo n.º 5
0
def knn(d, params):
    '''
    TO DO:

    '''
    celllist = util.get_cell_list(d)
    celldat = np.genfromtxt('results/txt_files/nn_results.txt')
    cellIDs = celldat[:, 0]

    fig = plt.figure()
    fig.set_tight_layout(True)
    ax = fig.add_subplot(111)

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

    N = util.num(d['const']['MOO_tn']['val'])  # time steps
    tf = util.num(d['const']['tf']['val'])  # temporal frequency (Hz)

    keys = util.get_cell_data(d['tr'][0], 'h2')
    for i, r in enumerate(keys):
        # find distance to S
        cellID = int(celllist[i])
        ind = np.where(cellIDs == cellID)[0]
        distance = celldat[ind, 4][0]

        # find amplitude of signal
        cell = d['tr'][0]['r'][r]['x']
        fft = np.fft.fft(cell)
        amp = np.abs(fft[tf]) * 2 / N

        if celldat[ind, 1] == 0:
            ax.plot(distance, amp, 'bo')
        if celldat[ind, 1] == 1:
            ax.plot(distance, amp, 'go')
        if celldat[ind, 1] == 2:
            ax.plot(distance, amp, 'ro')

    savedir = util.get_save_dirname(params, check_randomized=True)
    fig.savefig(savedir + 'knn.svg', edgecolor='none')
    plt.show(block=params['block_plots'])
Ejemplo n.º 6
0
def plot_color_names(rg, purity_thresh, results, params):
    '''
    '''
    # --- plot color names on a diamond plot --- #
    fig1 = plt.figure(figsize=(6,6))
    fig1.set_tight_layout(True)
    ax = fig1.add_subplot(111)

    # build diamond plot
    pf.AxisFormat(markersize=8, fontsize=20)
    pf.centerAxes(ax)
    ax.spines['left'].set_smart_bounds(False)
    ax.spines['bottom'].set_smart_bounds(False)
    ax.axis('equal')

    # Add in diamond boarders
    ax.plot([-1, 0], [0, 1], 'k')
    ax.plot([0, 1], [1, 0], 'k')
    ax.plot([1, 0], [0, -1], 'k')
    ax.plot([0, -1], [-1, 0], 'k')

    for i in range(len(rg)):
        maxind = results[i, 5:10].argmax()
        symbol = 'o'
        # check if cone has a purity greater threshold
        if purity_thresh is not None and purity_thresh < 1:
            symbol = '^' # means low purity

        if rg[i] < 0:
            color = [0, np.abs(rg[i]), 0]
        else:
            color = [np.abs(rg[i]), 0, 0]

        ax.plot(results[i, 3], results[i, 2], symbol, color=color,
                 markeredgewidth=2, markeredgecolor='k', alpha=0.5)

    savedir = util.get_save_dirname(params, check_randomized=True)
    fig1.savefig(savedir + 'cone_inputs_w_naming.svg',
                edgecolor='none')
Ejemplo n.º 7
0
def tuning_curve(d, params):
    '''
    '''
    # Get this with conversion call
    deg_per_pix, mm_per_deg = util.conversion_factors(params['species'])
    deg2um = mm_per_deg / 1000  #  conversion (micron / deg)

    if params['analysis_type'] == 'sf':
        figsize = (7, 7)
    else:
        figsize = (6, 5)

    fig = plt.figure(figsize=figsize)
    fig.set_tight_layout(True)
    ax1 = fig.add_subplot(111)
    if params['analysis_type'] == 'sf':
        ax2 = ax1.twiny()

    pf.AxisFormat()
    pf.TufteAxis(ax1, [
        'bottom',
        'left',
    ], [4, 4])
    if params['analysis_type'] == 'sf':
        pf.TufteAxis(ax2, [
            'top',
        ], [4, 4])

    # get the data
    r = an.response(d, params)

    colors = ['k', 'gray', 'r', 'b', 'g', 'c', 'm']
    cells = util.get_cell_type(params['cell_type'])
    # set some smart axes for second axis
    ymax = -100  # start small
    ymin = 1000  # start large
    if params['analysis_type'] == 'sf':
        x = util.num(d['const']['VAR_sf']['val'])  # spatial freq (cpd)
    elif params['analysis_type'] == 'tf':
        x = util.num(d['const']['VAR_tf']['val'])  # temp freq

    for i, c in enumerate(cells):
        ax1.loglog(x, r[c][i, :], 'o-', color=colors[i], label=c)
        vec = np.reshape(r[c], -1)
        max = np.max(vec)
        min = np.min(vec)
        if max > ymax:
            ymax = max
        if min < ymin:
            ymin = min

    ymax += 0.1
    ymin -= 0.1

    ax1.axis([x[0] - 0.05, x[-1] + 1, ymin, ymax])
    ax1.set_ylabel('amplitude')
    ax1.legend(fontsize=22, loc='lower center')

    if params['analysis_type'] == 'tf':
        ax1.set_xlabel('temporal frequency (Hz)')

    elif params['analysis_type'] == 'sf':
        ax1.set_xlabel('cycles / degree')
        ax2.xaxis.tick_top()
        ax2.yaxis.tick_left()
        ax2.axis([(x[0] - 0.05) * deg2um, (x[-1] + 1) * deg2um, ymin, ymax])
        ax2.set_xlabel('cycles / $\mu$m')
        ax2.set_xscale('log')

    savedir = util.get_save_dirname(params, check_randomized=True)
    fig.savefig(savedir + params['cell_type'] + '_' + params['analysis_type'] +
                '_tuning.eps',
                edgecolor='none')
    plt.show(block=params['block_plots'])
Ejemplo n.º 8
0
def stack(d, params):
    '''
    TO DO:
    * Add rgc option
    '''

    ylim = [[0, 0], [0, 0], [0, 0]]
    figs = {}
    for t in range(d['ntrial']):
        figs[t] = {}
        figs[t]['f'] = plt.figure(figsize=(6.5, 9))
        figs[t]['f'].set_tight_layout(True)
        ax = {}
        ax[0] = figs[t]['f'].add_subplot(311)
        ax[1] = figs[t]['f'].add_subplot(312)
        ax[2] = figs[t]['f'].add_subplot(313)

        pf.AxisFormat()

        pf.TufteAxis(ax[0], [
            'left',
        ], [3, 3])
        pf.TufteAxis(ax[1], [
            'left',
        ], [3, 3])
        pf.TufteAxis(ax[2], ['bottom', 'left'], [3, 3])

        time = util.get_time(d)
        # Subtract 10 points in so that zero offset
        for i in ax:
            ax[i].set_prop_cycle(
                cycler('color', ['r', 'g', 'b', 'c', 'm', 'y', 'k']))

        keys = util.get_cell_data(d['tr'][t], 'cone')
        for r in keys:
            dat = d['tr'][t]['r'][r]['x']
            y = dat - dat[10]
            ax[0].plot(time, y)
            ylim = check_lims(y, ylim, 0)

        keys = util.get_cell_data(d['tr'][t], 'h1')
        for r in keys:
            dat = d['tr'][t]['r'][r]['x']
            y = dat - dat[10] + 0.2
            ax[1].plot(time, y)
            ylim = check_lims(y, ylim, 1)

        keys = util.get_cell_data(d['tr'][t], 'h2')
        for r in keys:
            dat = d['tr'][t]['r'][r]['x']
            y = dat - dat[10] + 0.1
            ax[1].plot(time, y)
            ylim = check_lims(y, ylim, 1)

        keys = util.get_cell_data(d['tr'][t], 'bp')
        for r in keys:
            dat = d['tr'][t]['r'][r]['x']
            y = dat - dat[10]
            ax[2].plot(time, y)
            ylim = check_lims(y, ylim, 2)

        ax[2].set_xlabel('time (ms)')
        figs[t]['ax'] = ax

    for t in figs:
        for i in ax:
            figs[t]['ax'][i].set_ylim(ylim[i])

        savedir = util.get_save_dirname(params, check_randomized=True)
        for i in ax:
            #pf.invert(ax[i], fig, bk_color='k')
            figs[t]['f'].savefig(savedir + 'stack_t' + str(t) + '.eps',
                                 edgecolor='none')

    plt.show(block=params['block_plots'])