示例#1
0
    def traces_for_correlation(self, time, filename):
        stim_traces = np.zeros((time, np.size(self.responsetypelabel)))
        stim_time = self.stimulus_off_time[0] - self.stimulus_on_time[0]

        for ii in xrange(0, np.size(self.responsetypelabel)):
            print self.responsetypelabel[ii]
            for jj in xrange(0, np.size(self.stimulus_on_time)):
                if self.responsetypelabel[ii] == 'ON':
                    stim_traces[
                        self.stimulus_on_time[jj]:self.stimulus_off_time[jj] -
                        stim_time / 2, ii] = self.amplitude_trace
                elif self.responsetypelabel[ii] == 'OFF':
                    if jj == np.size(self.stimulus_on_time) - 1:
                        stim_traces[self.stimulus_off_time[jj]:self.
                                    stimulus_off_time[jj] + stim_time,
                                    ii] = self.amplitude_trace
                    else:
                        stim_traces[self.stimulus_off_time[jj]:self.
                                    stimulus_on_time[jj + 1] - stim_time / 2,
                                    ii] = self.amplitude_trace
                elif self.responsetypelabel[ii] == 'Inhibitory':
                    stim_traces[
                        self.stimulus_on_time[jj]:self.stimulus_off_time[jj] -
                        stim_time / 2, ii] = -1.5

        stim_traces_smooth = np.zeros((np.shape(stim_traces)))
        for ii in xrange(0, np.size(self.responsetypelabel)):
            stim_traces_smooth[:, ii] = PlottingTools.smooth_hanning(
                stim_traces[:, ii], window_len=stim_time / 2, window='hanning')
        ax1 = plt.subplot(111)
        plt.plot(stim_traces_smooth, alpha=0.5, linewidth=2)
        PlottingTools.plot_vertical_lines_onset(self.stimulus_on_time)
        PlottingTools.plot_vertical_lines_offset(self.stimulus_off_time)
        PlottingTools.format_legend(legend_string=self.responsetypelabel,
                                    axis_handle=ax1)
        PlottingTools.format_axis(axis_handle=ax1,
                                  ylim=[-4, self.amplitude_trace + 1])
        plt.savefig(os.path.join(self.Figure_Directory,
                                 filename + '_responsetypetraces.png'),
                    bbox_inches='tight')
        plt.close()

        return stim_traces_smooth
 def smooth_calcium_trace(self, calcium_trace, windowlen):
     smoothed_calcium_trace = np.zeros(np.shape(calcium_trace))
     for ss in xrange(0, np.size(calcium_trace, 1)):
         smoothed_calcium_trace[:, ss] = PlottingTools.smooth_hanning(
             calcium_trace[:, ss], windowlen, window='flat')
     return smoothed_calcium_trace