예제 #1
0
    def save_all_clusters_trials(self,
                                 matching_criteria_dicts,
                                 save_path='/home/skeshav/all_trials.csv'):
        with temp_setattr(self, 'df_all_conditions', pd.DataFrame()):
            for i, c in enumerate(self.cells()):
                for matching_criteria_dict in matching_criteria_dicts:
                    with temp_setattr(c.block, 'current_condition',
                                      matching_criteria_dict):
                        self.df_all_conditions = self.df_all_conditions.append(
                            c.block.to_df(), ignore_index=True)

            self.df_all_conditions.to_csv(save_path)
예제 #2
0
    def plot_all_sub_stimuli_histograms(self,
                                        matching_dictionary,
                                        n_bins=30,
                                        save=False,
                                        format='png'):

        for c in tqdm(self.cells()):
            with temp_setattr(c.block, 'current_condition',
                              matching_dictionary):
                fig = plt.figure(facecolor='w', figsize=(8, 3))
                plt.title('Cluster {}_Channel {}'.format(c.id, c.depth))
                c.block.plot_all_sub_stimuli(n_bins=n_bins, fig=fig)

                if save:
                    save_string = self.matching_dictionary_to_title_string(
                        matching_dictionary)
                    save_dir = os.path.join(self.main_dir, 'histogram_plots',
                                            save_string)
                    if not os.path.isdir(save_dir):
                        os.makedirs(save_dir)
                    save_path = os.path.join(
                        save_dir, 'cluster_{}_channel_{}.{}'.format(
                            c.id, c.depth, format))
                    fig.savefig(save_path, format=format)
                else:
                    plt.show()
예제 #3
0
    def plot_overlay_histogram(self,
                               matching_dictionaries,
                               n_bins=20,
                               save=False,
                               format='png'):  # FIXME:
        for c in self.cells():

            fig = plt.figure(facecolor='w', figsize=(8, 3))

            for matching_dictionary in matching_dictionaries:
                with temp_setattr(c.block, 'current_condition',
                                  matching_dictionary):
                    fig = c.block.plot_all_sub_stimuli(n_bins=n_bins, fig=fig)

            plt.suptitle('Cluster {}_ Channel {}'.format(c.id, c.depth))
            histogram_axes = [
                fig.axes[i] for i in range(len(fig.axes)) if i % 2 == 1
            ]
            normalise_axes(histogram_axes, space=3)
            #plt.show()

            if save:
                save_string = self.get_save_string(matching_dictionaries)
                save_dir = os.path.join(self.main_dir, 'histogram_plots',
                                        save_string)
                if not os.path.isdir(save_dir):
                    os.makedirs(save_dir)
                save_path = os.path.join(
                    save_dir,
                    'cluster_{}_channel_{}.{}'.format(c.id, c.depth, format))
                fig.savefig(save_path, format=format)
            else:
                plt.show()
예제 #4
0
 def plot_psth(self, extension):
     for angle in self.angles:
         plt.figure()
         angle_bsl_psth_y = []
         angle_spin_psth_y = []
         angle_bsl2_psth_y = []
         for cell in self:
             with temp_setattr(cell.block, 'current_condition',
                               {'angle': angle}):
                 bsl_psth, spin_psth, bsl2_psth = cell.block.get_psth()
                 bsl_psth_x, bsl_psth_y = bsl_psth
                 spin_psth_x, spin_psth_y = spin_psth
                 bsl2_psth_x, bsl2_psth_y = bsl2_psth
                 angle_bsl_psth_y.append(bsl_psth_y)
                 angle_spin_psth_y.append(spin_psth_y)
                 angle_bsl2_psth_y.append(bsl2_psth_y)
         angle_bsl_psth_y = np.array(angle_bsl_psth_y,
                                     dtype=np.float64).sum(0)
         angle_spin_psth_y = np.array(angle_spin_psth_y,
                                      dtype=np.float64).sum(0)
         angle_bsl2_psth_y = np.array(angle_bsl2_psth_y,
                                      dtype=np.float64).sum(0)
         plt.step(bsl_psth_x, angle_bsl_psth_y, where='post', color='blue')
         plt.step(spin_psth_x,
                  angle_spin_psth_y,
                  where='post',
                  color='green')
         plt.step(bsl2_psth_x, angle_bsl2_psth_y, where='post', color='red')
         plt.savefig(
             os.path.join(
                 self.main_dir, '{}_PSTH.{}'.format(self.get_str(angle),
                                                    extension)))
         plt.close()
예제 #5
0
    def plot_single_trial_detection(self, angle,
                                    trial_id):  # FIXME: trial plotter
        with temp_setattr(self.block, 'current_condition', {'angle': angle}):
            trial = self.block.trials[trial_id]
            trace = trial.processed_trace
            params = self.block.detection_params[angle]
            delta_wave = diff(box_smooth(trace, params.n_pnts_peak),
                              box_smooth(trace, params.n_pnts_bsl),
                              params.n_pnts_rise_t)
            plt.plot(trial.stimulus.x[:len(delta_wave)],
                     delta_wave,
                     linewidth=0.3
                     )  # FIXME: find why different length # REFACTOR: extract

            trace = signal.medfilt(trace.copy(), params.median_kernel_size)
            events_params = trial.events.get_events_point_params(
            )  # WARNING: not analysed_events because for GUI
            events_pos, peaks_pos, half_rises, _ = events_params
            _plot_trace(trace,
                        'trial_{}'.format(trial_id),
                        events_pos,
                        peaks_pos,
                        color='grey',
                        x=trial.stimulus.x,
                        y_shift=0)
예제 #6
0
파일: cell.py 프로젝트: RichardFav/spikeGUI
 def save_detection(self, processing_type):
     for angle in self.angles:
         with temp_setattr(self.block, 'current_condition', {
                 'keep': True,
                 'angle': angle
         }):
             self.block.save_detection(angle, processing_type)
예제 #7
0
파일: cell.py 프로젝트: RichardFav/spikeGUI
 def get_results_as_df(self, angle):
     with temp_setattr(self.block, 'current_condition', {
             'keep': True,
             'angle': angle
     }):
         return pd.concat(
             [self._get_base_df(angle),
              self.block.get_results_df()],
             axis=1)
예제 #8
0
    def do_stats(self, matching_dictionary):
        for c in self.cells():

            with temp_setattr(c.block, 'current_condition',
                              matching_dictionary):
                c.set_main_dir(self.main_dir)
                c.block.save_stats()
                self.stats.append(c.block.stats_df)

        print(self.stats)
예제 #9
0
 def population_data(self, matching_dictionary, labels, time_match_label):
     all_groups = {}
     for label in labels:
         spikes_in_label = []
         for c in self.cells():
             with temp_setattr(c.block, 'current_condition',
                               matching_dictionary):
                 spikes_in_label.extend(
                     c.block.get_events_in_period(label, time_match_label))
         all_groups.setdefault(label, spikes_in_label)
     return all_groups
예제 #10
0
파일: cell.py 프로젝트: RichardFav/spikeGUI
 def analyse(self, processed=True):
     """
     Loop over all recordings for each angle
         self.noises with the high frequency noise of each recording
         and self.events_params with the tuple of lists: (events_pos, peaks_pos, half_rises, peak_ampls)
     """
     for angle in self.angles:
         with temp_setattr(self.block, 'current_condition', {
                 'keep': True,
                 'angle': angle
         }):
             self.block.analyse(angle, processed=processed)
예제 #11
0
 def get_detection_params_path(self, angle):
     with temp_setattr(self, 'current_condition', {
             'keep': True,
             'angle': angle
     }):
         expected_path = os.path.join(
             self.cell.dir, '{}_detection_params.csv'.format(self))
         if os.path.exists(expected_path):
             return expected_path
         else:
             warnings.warn(
                 'File {} not found to reload detection parameters, creating new file'
                 .format(expected_path))
             return None
예제 #12
0
    def analyse(
        self,
        angle,
        processed=True
    ):  # WARNING: all trials # TODO: rename?  + DOUBLE WARNING should be only one angle
        """
        All trials but one angle

        :param processed:
        :return:
        """
        with temp_setattr(self, 'current_condition', {'angle': angle}):
            self.__reset_detection()
            for trial in self.kept_trials:
                trial.detect(self.detection_params[angle],
                             processed)  # detect all whether kept or not
예제 #13
0
    def get_all_cells_all_trials_spiking_tables(self,
                                                angle,
                                                levels_var_name='position'):
        spiking_tables = []
        for i, cell in enumerate(tqdm(self)):
            block = cell.block
            with temp_setattr(block, 'current_condition', {
                    'keep': True,
                    'angle': angle
            }):
                FieldOfView.check_all_trials_have_same_n_repeats(
                    block)  # TODO: ideally check all cells have same ?
                spiking_table, levels, cmd = block.get_freqs_from_timetable(
                    levels_var_name)
                spiking_tables.append(spiking_table)
        spiking_tables = np.dstack(spiking_tables)  # TEST: check shape

        spiking_tables = np.transpose(spiking_tables, (2, 0, 1))
        return levels, spiking_tables, cmd
예제 #14
0
    def get_events_integral(self, angle, trial_id):
        """
        All trials but one angle (because for detection)

        :param trial_id:
        :return:
        """
        with temp_setattr(self, 'current_condition', {'angle': angle}):
            integrals = []
            trial = self.trials[trial_id]
            trace = trial.processed_trace
            filtered_trace = signal.medfilt(trace.copy(), 3)
            for event in trial.events:
                integrals.append(event.get_integral(filtered_trace))
            if integrals:
                if __debug__:
                    print(integrals)
                return np.array(integrals).mean()
            else:
                return 0
예제 #15
0
파일: cell.py 프로젝트: RichardFav/spikeGUI
 def analyse_block(self, angle):
     with temp_setattr(self.block, 'current_condition', {
             'keep': True,
             'angle': angle
     }):
         self.block.save_stats()
예제 #16
0
파일: cell.py 프로젝트: RichardFav/spikeGUI
 def plot_all(self, angle):
     with temp_setattr(self.block, 'current_condition', {
             'keep': True,
             'angle': angle
     }):
         self.block.plot()