def make_chart(self, img=None):
     self.fig.clear()
     self.axes = self.fig.add_subplot(111)
     if img is None:
         img = np.zeros((32,32)) + 0.5
         img = self.sta_data.float_to_rgb(img,cmap=self.cmap)
     self.img_dim = img.shape
     self.im = self.axes.imshow(img,interpolation=self.interpolation)
     if self.showing_colorbar:
         self.cbar = self.fig.colorbar(self.im, shrink=1.0, fraction=0.045, pad=0.05, ticks=[])
     adjust_spines(self.axes,spines=['left','bottom'],spine_outward=[],
                   xticks='bottom',yticks='left',tick_label=['x','y'])
     #self.axes.autoscale_view(scalex=True, scaley=True)
     self.fig.canvas.draw()
 def make_chart(self,data=np.zeros(1),bins=np.arange(10)+1,polar=False):
     self.polar_chart = polar
     self.hist_bins = []
     self.hist_patches = []
     self.x = np.arange(17)
     self.means = np.zeros(self.x.size)
     self.stds = np.zeros(self.x.size)
     
     self.fitting_x = np.linspace(self.x[0], self.x[-1], 100, endpoint=True)
     self.fitting_y = np.zeros(self.fitting_x.size)
     self.fig.clear()
     
     grid = 18
     height = grid // 9
     gs = gridspec.GridSpec(grid, grid)
     # make tuning curve plot
     axes = self.fig.add_subplot(gs[:-height*2,height//2:-height//2],polar=polar)
     if polar:
         self.curve_data = axes.plot(self.x, self.means, 'ko-')[0]
     else:
         adjust_spines(axes,spines=['left','bottom','right'],spine_outward=['left','right','bottom'],xoutward=10,youtward=30,\
                       xticks='bottom',yticks='both',tick_label=['x','y'],xaxis_loc=5,xminor_auto_loc=2,yminor_auto_loc=2)
         axes.set_ylabel('Response(spikes/sec)',fontsize=12)
         self.curve_data = axes.plot(self.x, self.means, self.data_point_styles[0])[0]
     self.errbars = axes.errorbar(self.x, self.means, yerr=self.stds, fmt='k.') if self.showing_errbar else None
     self.curve_axes = axes
     
     self.fitting_data = axes.plot(self.fitting_x, self.fitting_y, self.fitting_curve_styles[0])[0]
     
     axes.set_ylim(0,100)
     axes.relim()
     axes.autoscale_view(scalex=True, scaley=False)
     axes.grid(b=True, which='major',axis='both',linestyle='-.')
     # make histgrams plot
     rows,cols = (grid-height,grid)
     for row in range(rows,cols)[::height]:
         for col in range(cols)[::height]:
             axes = self.fig.add_subplot(gs[row:row+height,col:col+height])
             axes.set_axis_bgcolor('white')
             #axes.set_title('PSTH', size=8)
             axes.set_ylim(0,100)
             if col == 0:
                 adjust_spines(axes,spines=['left','bottom'],xticks='bottom',yticks='left',tick_label=['y'],xaxis_loc=4,yaxis_loc=3)
                 axes.set_ylabel('Spikes',fontsize=11)
             elif col == cols-height:
                 adjust_spines(axes,spines=['right','bottom'],xticks='bottom',yticks='right',tick_label=['y'],xaxis_loc=4,yaxis_loc=3)
             else:
                 adjust_spines(axes,spines=['bottom'],xticks='bottom',yticks='none',tick_label=[],xaxis_loc=4,yaxis_loc=3)
             pylab.setp(axes.get_xticklabels(), fontsize=8)
             pylab.setp(axes.get_yticklabels(), fontsize=8)
             _n, bins, patches = axes.hist(data, bins, facecolor='black', alpha=1.0)
             self.hist_bins.append(bins)
             self.hist_patches.append(patches)
             
     self.fig.canvas.draw()
 def make_chart(self, bins=np.arange(150), bin_data=np.zeros(150)):
     self.bins = bins
     self.bin_data = bin_data
     
     self.fig.clear()
     
     # make Average curve plot
     axes = self.fig.add_subplot(111)
     adjust_spines(axes,spines=['left','bottom','right'],spine_outward=['left','right','bottom'],xoutward=0,youtward=0,\
                   xticks='bottom',yticks='both',tick_label=['x','y'],xaxis_loc=7,xminor_auto_loc=2,yminor_auto_loc=2)
     axes.set_xlabel('Time(ms)',fontsize=12)
     axes.set_ylabel('Response(spikes/sec)',fontsize=12)
     self.curve_data = axes.plot(self.bins, self.bin_data, self.data_point_styles[0])[0]
     self.curve_axes = axes
     
     axes.set_ylim(0,100)
     axes.relim()
     axes.autoscale_view(scalex=False, scaley=False)
     #axes.grid(b=True, which='major',axis='both',linestyle='-.')
             
     self.fig.canvas.draw()
Exemple #4
0
 def make_chart(self, img=None):
     self.fig.clear()
     self.axes = self.fig.add_subplot(111)
     if img is None:
         img = np.zeros((32, 32)) + 0.5
         img = self.sta_data.float_to_rgb(img, cmap=self.cmap)
     self.img_dim = img.shape
     self.im = self.axes.imshow(img, interpolation=self.interpolation)
     if self.showing_colorbar:
         self.cbar = self.fig.colorbar(self.im,
                                       shrink=1.0,
                                       fraction=0.045,
                                       pad=0.05,
                                       ticks=[])
     adjust_spines(self.axes,
                   spines=['left', 'bottom'],
                   spine_outward=[],
                   xticks='bottom',
                   yticks='left',
                   tick_label=['x', 'y'])
     #self.axes.autoscale_view(scalex=True, scaley=True)
     self.fig.canvas.draw()
    def update_chart(self, data=None):
        if data is None and self.data is None:
            return
        elif data is None and self.data is not None:
            data = self.data

        selected_unit = wx.FindWindowByName('unit_choice').get_selected_unit()
        if selected_unit is not None:
            channel, unit = selected_unit
            zeroth_psth_data = None
            polar_dict = {
                'orientation': True,
                'spatial_frequency': False,
                'phase': False,
                'disparity': False
            }
            self.parameter = self.psth_data.parameter
            if self.parameter in polar_dict:
                polar_chart = polar_dict[self.parameter]
            else:
                polar_chart = self.polar_chart
            # histogram
            for index in [
                    i for i in data[channel][unit].iterkeys()
                    if (not i & 1 and i < 16)
            ]:
                patch_index = index // 2
                spike_times = data[channel][unit][index]['spikes']
                bins = data[channel][unit][index]['bins']
                psth_data = data[channel][unit][index]['psth_data']
                if index == 0:
                    zeroth_psth_data = psth_data
                _trials = data[channel][unit][index]['trials']
                self.show_fitting_changed = False
                if len(bins) != len(
                        self.hist_bins[patch_index]
                ) or self.show_errbar_changed or polar_chart != self.polar_chart:
                    self.make_chart(spike_times, bins, polar_chart)
                    self.show_errbar_changed = False
                    self.show_fitting_changed = False
                #else:
                for rect, h in zip(self.hist_patches[patch_index], psth_data):
                    rect.set_height(h)

            for index in data[channel][unit].iterkeys():
                mean = data[channel][unit][index]['mean']
                std = data[channel][unit][index]['std']
                if index == -1:
                    self.bg_noise_mean = mean
                    self.bg_noise_std = std
                elif index <= 15:
                    self.means[index] = mean
                    self.stds[index] = std
                elif index == 16:
                    self.mono_left_mean = mean
                    self.mono_left_std = std
                elif index == 17:
                    self.mono_right_mean = mean
                    self.mono_right_std = std

            self.curve_axes.set_xscale('linear')

            if self.parameter == 'orientation':
                self.log_fitting = False
                self.x = np.linspace(0.0, 360.0, 17) / 180 * np.pi
                self.curve_axes.set_title('Orientation Tuning Curve',
                                          fontsize=12)
                if zeroth_psth_data is not None:
                    for rect, h in zip(self.hist_patches[-1],
                                       zeroth_psth_data):
                        rect.set_height(h)
                self.means[-1] = self.means[0]
                self.stds[-1] = self.stds[0]
            if self.parameter == 'spatial_frequency':
                self.log_fitting = True
                self.x = np.logspace(-1.0, 0.5, 16)
                self.curve_axes.set_title('Spatial Frequency Tuning Curve',
                                          fontsize=12)
                self.curve_axes.set_xscale('log')
                self.means = self.means[:len(self.x)]
                self.stds = self.stds[:len(self.x)]
                adjust_spines(self.curve_axes,spines=['left','bottom','right'],spine_outward=['left','right','bottom'],xoutward=10,youtward=30,\
                              xticks='bottom',yticks='both',tick_label=['x','y'],xaxis_loc=5,xminor_auto_loc=2,yminor_auto_loc=2,xmajor_loc=[0.1,0.5,1.0,2.0])
            if self.parameter in ('disparity', 'phase'):
                self.log_fitting = False
                self.x = np.linspace(0.0, 360.0, 17)
                if self.parameter == 'disparity':
                    self.curve_axes.set_title('Disparity Tuning Curve',
                                              fontsize=12)
                if self.parameter == 'phase':
                    self.curve_axes.set_title('Phase Tuning Curve',
                                              fontsize=12)
                if zeroth_psth_data is not None:
                    for rect, h in zip(self.hist_patches[-1],
                                       zeroth_psth_data):
                        rect.set_height(h)
                self.means[-1] = self.means[0]
                self.stds[-1] = self.stds[0]
                if self.mono_left_mean is not None and self.mono_right_mean is not None:
                    #annotate dominant eye activity
                    self.mono_dom_mean = max(self.mono_left_mean,
                                             self.mono_right_mean)
                    self.curve_axes.annotate('',
                                             xy=(360, self.mono_dom_mean),
                                             xytext=(370, self.mono_dom_mean),
                                             arrowprops=dict(facecolor='black',
                                                             frac=1.0,
                                                             headwidth=10,
                                                             shrink=0.05))
                    #annotate non-dominant eye activity
                    self.mono_nod_mean = min(self.mono_left_mean,
                                             self.mono_right_mean)
                    self.curve_axes.annotate('',
                                             xy=(360, self.mono_nod_mean),
                                             xytext=(370, self.mono_nod_mean),
                                             arrowprops=dict(facecolor='gray',
                                                             frac=1.0,
                                                             headwidth=10,
                                                             shrink=0.05))
                if self.bg_noise_mean is not None:
                    #annotate background activity
                    self.curve_axes.annotate('',
                                             xy=(360, self.bg_noise_mean),
                                             xytext=(370, self.bg_noise_mean),
                                             arrowprops=dict(facecolor='white',
                                                             frac=1.0,
                                                             headwidth=10,
                                                             shrink=0.05))

                adjust_spines(self.curve_axes,spines=['left','bottom','right'],spine_outward=['left','right','bottom'],xoutward=10,youtward=30,\
                              xticks='bottom',yticks='both',tick_label=['x','y'],xaxis_loc=5,xminor_auto_loc=2,yminor_auto_loc=2)

            if self.append_data_curve:
                self.curve_axes.plot(
                    self.x, self.means,
                    self.data_point_styles[self.data_curves - 1])
            else:
                self.curve_data.set_xdata(self.x)
                self.curve_data.set_ydata(self.means)
            if self.errbars is not None:
                self._update_errbars(self.errbars, self.x, self.means,
                                     self.stds)

            ##################################################################
            ##### Curve Fitting
            ##################################################################
            if self.log_fitting:
                self.fitting_x = np.logspace(np.log10(self.x[0]),
                                             np.log10(self.x[-1]),
                                             self.fitting_x.size,
                                             endpoint=True)
            else:
                self.fitting_x = np.linspace(self.x[0],
                                             self.x[-1],
                                             self.fitting_x.size,
                                             endpoint=True)

            model_fitting = np.zeros(self.fitting_x.size)
            model_xdata = np.zeros(self.x.size)
            nonzero = np.nonzero(self.means)[0]
            if self.curve_fitting == 'gauss':
                if self.log_fitting:
                    model_xdata, model_fitting = self.curve_fitter.loggaussfit1d(
                        self.x[nonzero], self.means[nonzero], self.fitting_x)
                else:
                    model_xdata, model_fitting = self.curve_fitter.gaussfit1d(
                        self.x[nonzero], self.means[nonzero], self.fitting_x)
            elif self.curve_fitting == 'sin':
                model_xdata, model_fitting = self.curve_fitter.sinusoid1d(
                    self.x[nonzero], self.means[nonzero], self.fitting_x)
            elif self.curve_fitting == 'gabor':
                model_xdata, model_fitting = self.curve_fitter.gaborfit1d(
                    self.x[nonzero], self.means[nonzero], self.fitting_x)

            if self.append_data_curve:
                self.curve_axes.plot(
                    self.fitting_x, model_fitting,
                    self.fitting_curve_styles[self.data_curves - 1])
            else:
                self.fitting_data.set_xdata(self.fitting_x)
                self.fitting_data.set_ydata(model_fitting)

            label = [self.parameter, 'rate', 'std']
            self.data_form.gen_curve_data(self.x, self.means, self.stds,
                                          self.bg_noise_mean,
                                          self.mono_dom_mean,
                                          self.mono_nod_mean, self.fitting_x,
                                          model_fitting, model_xdata, label)
            if self.parameter == 'orientation':
                self.data_form.gen_psth_data(data[channel][unit])
            self.curve_axes.set_xlim(min(self.x), max(self.x))
            self.curve_axes.set_ylim(min(0, min(self.means)),
                                     (max(self.means) * 1.2) // 10 * 10)
            #self.curve_axes.set_ylim(auto=True)
            self.curve_axes.relim()
            self.curve_axes.autoscale_view(scalex=False, scaley=False)

        self.fig.canvas.draw()
    def make_chart(self,
                   data=np.zeros(1),
                   bins=np.arange(10) + 1,
                   polar=False):
        self.polar_chart = polar
        self.hist_bins = []
        self.hist_patches = []
        self.x = np.arange(17)
        self.means = np.zeros(self.x.size)
        self.stds = np.zeros(self.x.size)

        self.fitting_x = np.linspace(self.x[0], self.x[-1], 100, endpoint=True)
        self.fitting_y = np.zeros(self.fitting_x.size)
        self.fig.clear()

        grid = 18
        height = grid // 9
        gs = gridspec.GridSpec(grid, grid)
        # make tuning curve plot
        axes = self.fig.add_subplot(gs[:-height * 2, height // 2:-height // 2],
                                    polar=polar)
        if polar:
            self.curve_data = axes.plot(self.x, self.means, 'ko-')[0]
        else:
            adjust_spines(axes,spines=['left','bottom','right'],spine_outward=['left','right','bottom'],xoutward=10,youtward=30,\
                          xticks='bottom',yticks='both',tick_label=['x','y'],xaxis_loc=5,xminor_auto_loc=2,yminor_auto_loc=2)
            axes.set_ylabel('Response(spikes/sec)', fontsize=12)
            self.curve_data = axes.plot(self.x, self.means,
                                        self.data_point_styles[0])[0]
        self.errbars = axes.errorbar(
            self.x, self.means, yerr=self.stds,
            fmt='k.') if self.showing_errbar else None
        self.curve_axes = axes

        self.fitting_data = axes.plot(self.fitting_x, self.fitting_y,
                                      self.fitting_curve_styles[0])[0]

        axes.set_ylim(0, 100)
        axes.relim()
        axes.autoscale_view(scalex=True, scaley=False)
        axes.grid(b=True, which='major', axis='both', linestyle='-.')
        # make histgrams plot
        rows, cols = (grid - height, grid)
        for row in range(rows, cols)[::height]:
            for col in range(cols)[::height]:
                axes = self.fig.add_subplot(gs[row:row + height,
                                               col:col + height])
                axes.set_axis_bgcolor('white')
                #axes.set_title('PSTH', size=8)
                axes.set_ylim(0, 100)
                if col == 0:
                    adjust_spines(axes,
                                  spines=['left', 'bottom'],
                                  xticks='bottom',
                                  yticks='left',
                                  tick_label=['y'],
                                  xaxis_loc=4,
                                  yaxis_loc=3)
                    axes.set_ylabel('Spikes', fontsize=11)
                elif col == cols - height:
                    adjust_spines(axes,
                                  spines=['right', 'bottom'],
                                  xticks='bottom',
                                  yticks='right',
                                  tick_label=['y'],
                                  xaxis_loc=4,
                                  yaxis_loc=3)
                else:
                    adjust_spines(axes,
                                  spines=['bottom'],
                                  xticks='bottom',
                                  yticks='none',
                                  tick_label=[],
                                  xaxis_loc=4,
                                  yaxis_loc=3)
                pylab.setp(axes.get_xticklabels(), fontsize=8)
                pylab.setp(axes.get_yticklabels(), fontsize=8)
                _n, bins, patches = axes.hist(data,
                                              bins,
                                              facecolor='black',
                                              alpha=1.0)
                self.hist_bins.append(bins)
                self.hist_patches.append(patches)

        self.fig.canvas.draw()
 def update_chart(self, data=None):
     if data is None and self.data is None:
         return
     elif data is None and self.data is not None:
         data = self.data
     
     selected_unit = wx.FindWindowByName('unit_choice').get_selected_unit()
     if selected_unit is not None:
         channel, unit = selected_unit
         zeroth_psth_data = None
         polar_dict = {'orientation':True, 'spatial_frequency':False, 'phase':False, 'disparity':False}
         self.parameter = self.psth_data.parameter
         if self.parameter in polar_dict:
             polar_chart = polar_dict[self.parameter]
         else:
             polar_chart = self.polar_chart
         # histogram
         for index in [i for i in data[channel][unit].iterkeys() if (not i&1 and i<16)]:
             patch_index = index // 2
             spike_times = data[channel][unit][index]['spikes']
             bins = data[channel][unit][index]['bins']
             psth_data = data[channel][unit][index]['psth_data']
             if index == 0:
                 zeroth_psth_data = psth_data
             _trials = data[channel][unit][index]['trials']
             self.show_fitting_changed = False
             if len(bins) != len(self.hist_bins[patch_index]) or self.show_errbar_changed or polar_chart != self.polar_chart:
                 self.make_chart(spike_times, bins, polar_chart)
                 self.show_errbar_changed = False
                 self.show_fitting_changed = False
             #else:
             for rect,h in zip(self.hist_patches[patch_index],psth_data):
                 rect.set_height(h)
         
         for index in data[channel][unit].iterkeys():
             mean = data[channel][unit][index]['mean']
             std = data[channel][unit][index]['std']
             if index == -1:
                 self.bg_noise_mean = mean
                 self.bg_noise_std = std
             elif index <= 15:
                 self.means[index] = mean
                 self.stds[index] = std
             elif index == 16:
                 self.mono_left_mean = mean
                 self.mono_left_std = std
             elif index == 17:
                 self.mono_right_mean = mean
                 self.mono_right_std = std
         
         self.curve_axes.set_xscale('linear')
         
         if self.parameter == 'orientation':
             self.log_fitting = False
             self.x = np.linspace(0.0, 360.0, 17)/180*np.pi
             self.curve_axes.set_title('Orientation Tuning Curve',fontsize=12)
             if zeroth_psth_data is not None:
                 for rect,h in zip(self.hist_patches[-1],zeroth_psth_data):
                     rect.set_height(h)
             self.means[-1] = self.means[0]
             self.stds[-1] = self.stds[0]
         if self.parameter == 'spatial_frequency':
             self.log_fitting = True
             self.x = np.logspace(-1.0,0.5,16)
             self.curve_axes.set_title('Spatial Frequency Tuning Curve',fontsize=12)
             self.curve_axes.set_xscale('log')
             self.means = self.means[:len(self.x)]
             self.stds = self.stds[:len(self.x)]
             adjust_spines(self.curve_axes,spines=['left','bottom','right'],spine_outward=['left','right','bottom'],xoutward=10,youtward=30,\
                           xticks='bottom',yticks='both',tick_label=['x','y'],xaxis_loc=5,xminor_auto_loc=2,yminor_auto_loc=2,xmajor_loc=[0.1,0.5,1.0,2.0])
         if self.parameter in ('disparity','phase'):
             self.log_fitting = False
             self.x = np.linspace(0.0, 360.0, 17)
             if self.parameter == 'disparity':
                 self.curve_axes.set_title('Disparity Tuning Curve',fontsize=12)
             if self.parameter == 'phase':
                 self.curve_axes.set_title('Phase Tuning Curve',fontsize=12)
             if zeroth_psth_data is not None:
                 for rect,h in zip(self.hist_patches[-1],zeroth_psth_data):
                     rect.set_height(h)
             self.means[-1] = self.means[0]
             self.stds[-1] = self.stds[0]
             if self.mono_left_mean is not None and self.mono_right_mean is not None:
                 #annotate dominant eye activity
                 self.mono_dom_mean = max(self.mono_left_mean, self.mono_right_mean)
                 self.curve_axes.annotate('', xy=(360, self.mono_dom_mean), xytext=(370, self.mono_dom_mean),
                                         arrowprops=dict(facecolor='black', frac=1.0, headwidth=10, shrink=0.05))
                 #annotate non-dominant eye activity
                 self.mono_nod_mean = min(self.mono_left_mean, self.mono_right_mean)
                 self.curve_axes.annotate('', xy=(360, self.mono_nod_mean), xytext=(370, self.mono_nod_mean),
                                         arrowprops=dict(facecolor='gray', frac=1.0, headwidth=10, shrink=0.05))
             if self.bg_noise_mean is not None:
                 #annotate background activity
                 self.curve_axes.annotate('', xy=(360, self.bg_noise_mean), xytext=(370, self.bg_noise_mean),
                                         arrowprops=dict(facecolor='white', frac=1.0, headwidth=10, shrink=0.05))
                 
             adjust_spines(self.curve_axes,spines=['left','bottom','right'],spine_outward=['left','right','bottom'],xoutward=10,youtward=30,\
                           xticks='bottom',yticks='both',tick_label=['x','y'],xaxis_loc=5,xminor_auto_loc=2,yminor_auto_loc=2)
         
         if self.append_data_curve:
             self.curve_axes.plot(self.x, self.means, self.data_point_styles[self.data_curves-1])
         else:
             self.curve_data.set_xdata(self.x)
             self.curve_data.set_ydata(self.means)
         if self.errbars is not None:
             self._update_errbars(self.errbars,self.x,self.means,self.stds)
         
         ##################################################################
         ##### Curve Fitting
         ##################################################################
         if self.log_fitting:
             self.fitting_x = np.logspace(np.log10(self.x[0]), np.log10(self.x[-1]), self.fitting_x.size, endpoint=True)
         else:
             self.fitting_x = np.linspace(self.x[0], self.x[-1], self.fitting_x.size, endpoint=True)
         
         model_fitting = np.zeros(self.fitting_x.size)
         model_xdata = np.zeros(self.x.size)
         nonzero = np.nonzero(self.means)[0]
         if self.curve_fitting == 'gauss':
             if self.log_fitting:
                 model_xdata,model_fitting = self.curve_fitter.loggaussfit1d(self.x[nonzero], self.means[nonzero], self.fitting_x)
             else:
                 model_xdata,model_fitting = self.curve_fitter.gaussfit1d(self.x[nonzero], self.means[nonzero], self.fitting_x)
         elif self.curve_fitting == 'sin':
             model_xdata,model_fitting = self.curve_fitter.sinusoid1d(self.x[nonzero], self.means[nonzero], self.fitting_x)
         elif self.curve_fitting == 'gabor':
             model_xdata,model_fitting = self.curve_fitter.gaborfit1d(self.x[nonzero], self.means[nonzero], self.fitting_x)
             
         if self.append_data_curve:
             self.curve_axes.plot(self.fitting_x, model_fitting, self.fitting_curve_styles[self.data_curves-1])
         else:
             self.fitting_data.set_xdata(self.fitting_x)
             self.fitting_data.set_ydata(model_fitting)
             
         label = [self.parameter, 'rate', 'std']
         self.data_form.gen_curve_data(self.x, self.means, self.stds,
                                       self.bg_noise_mean, self.mono_dom_mean, self.mono_nod_mean,
                                       self.fitting_x, model_fitting, model_xdata, label)
         if self.parameter == 'orientation':
             self.data_form.gen_psth_data(data[channel][unit])
         self.curve_axes.set_xlim(min(self.x),max(self.x))
         self.curve_axes.set_ylim(min(0, min(self.means)), (max(self.means)*1.2)//10*10)
         #self.curve_axes.set_ylim(auto=True)
         self.curve_axes.relim()
         self.curve_axes.autoscale_view(scalex=False, scaley=False)
             
     self.fig.canvas.draw()