Пример #1
0
    def get_rfmap_data(self):
        data_img = dict()
        if not self.rfmap_data_status:
            return data_img, None
        else:

            (rf_map_times, rf_map_pos,
             rf_stim_frames) = passive.get_on_off_times_and_positions(
                 self.rf_map)

            rf_map, _ = \
                passive.get_rf_map_over_depth(rf_map_times, rf_map_pos, rf_stim_frames,
                                              self.spikes['times'][self.spike_idx][self.kp_idx],
                                              self.spikes['depths'][self.spike_idx][self.kp_idx],
                                              d_bin=160)
            rfs_svd = passive.get_svd_map(rf_map)
            img = dict()
            img['on'] = np.vstack(rfs_svd['on'])
            img['off'] = np.vstack(rfs_svd['off'])
            yscale = ((np.max(self.chn_coords[:, 1]) -
                       np.min(self.chn_coords[:, 1])) / img['on'].shape[0])
            xscale = 1
            levels = np.quantile(np.c_[img['on'], img['off']], [0, 1])

            depths = np.linspace(0, 3840, len(rfs_svd['on']) + 1)

            sub_type = ['on', 'off']
            for sub in sub_type:
                sub_data = {
                    sub: {
                        'img': [img[sub].T],
                        'scale': [np.array([xscale, yscale])],
                        'levels': levels,
                        'offset': [np.array([0, 0])],
                        'cmap': 'viridis',
                        'xrange': np.array([0, 15]),
                        'xaxis': 'Position',
                        'title': 'rfmap (dB)'
                    }
                }
                data_img.update(sub_data)

            return data_img, depths
Пример #2
0
    def test_rf_map(self):
        """

        """
        # Simulate fake rfmap data
        test_frames = np.full((60, 15, 15), 128, dtype='uint8')
        # Test on and off individually
        test_frames[10:20, 8, 8] = 0
        test_frames[25:35, 10, 13] = 255
        # Test that interleaved are detected correctly
        test_frames[40:50, 4, 9] = 0
        test_frames[42:52, 6, 10] = 255
        test_frames[42:55, 11, 4] = 0
        test_frames[50:60, 8, 8] = 0

        test_times = np.arange(60)
        rf_map = {}
        rf_map['times'] = test_times
        rf_map['frames'] = test_frames

        rf_map_times, rf_map_pos, rf_stim_frames = passive.get_on_off_times_and_positions(
            rf_map)

        assert (all(rf_map_times == test_times))
        assert (rf_map_pos.shape == (15 * 15, 2))
        assert (len(rf_stim_frames['on']) == 15 * 15)
        assert (len(rf_stim_frames['off']) == 15 * 15)

        # Off is for the 0 ones
        assert (all(rf_stim_frames['off'][ismember2d(
            rf_map_pos, np.array([[8, 8]]))[0]][0][0] == [10, 50]))
        assert (rf_stim_frames['off'][ismember2d(rf_map_pos,
                                                 np.array([[4, 9]
                                                           ]))[0]][0][0] == 40)
        assert (rf_stim_frames['off'][ismember2d(rf_map_pos,
                                                 np.array([[11, 4]
                                                           ]))[0]][0][0] == 42)

        # On is for the 255 ones
        assert (rf_stim_frames['on'][ismember2d(rf_map_pos,
                                                np.array([[10, 13]
                                                          ]))[0]][0][0] == 25)
        assert (rf_stim_frames['on'][ismember2d(rf_map_pos,
                                                np.array([[6, 10]
                                                          ]))[0]][0][0] == 42)

        # Next test that the firing rate function works
        # Basically just make one square responsive
        spike_times = np.arange(25, 35, 0.01)
        spike_depths = 500 * np.ones_like(spike_times)

        rf_map_avg, depths = passive.get_rf_map_over_depth(rf_map_times,
                                                           rf_map_pos,
                                                           rf_stim_frames,
                                                           spike_times,
                                                           spike_depths,
                                                           x_lim=[0, 60])
        non_zero = np.where(rf_map_avg['on'] != 0)
        assert (np.argmin(np.abs(depths - 500)) == non_zero[0][0])
        assert (all(non_zero[1] == 10))
        assert (all(non_zero[2] == 13))

        assert (np.all(rf_map_avg['off'] == 0))

        rf_svd = passive.get_svd_map(rf_map_avg)
        # Make sure that the one responsive element is non-zero
        assert (rf_svd['on'][non_zero[0][0]][non_zero[1][0], non_zero[2][0]] !=
                0)
        # But that all the rest are zero
        rf_svd['on'][non_zero[0][0]][non_zero[1][0], non_zero[2][0]] = 0
        assert (np.all(np.isclose(np.vstack(rf_svd['on']), 0)))
        assert (np.all(np.vstack(rf_svd['off']) == 0))
Пример #3
0
# Pass this data into brainbox function to find out at what times each voxel on screen was
# activated
rf_stim_times, rf_stim_pos, rf_stim_frames = passive.get_on_off_times_and_positions(
    rf_map)

# rf_stim_times - time of frame change
# rf_stim_pos - position of each voxel on (15 x 15) screen
# rf_stim_frames - frames at which stimulus was turned 'on' (grey to white) or 'off' (grey to
#                   black) at each position on screen

# For each position on screen compute average stim epoched activity across depth of probe
rf_map_avg, _ = passive.get_rf_map_over_depth(rf_stim_times,
                                              rf_stim_pos,
                                              rf_stim_frames,
                                              spike_times,
                                              spike_depths,
                                              t_bin=0.01,
                                              d_bin=160,
                                              pre_stim=0.05,
                                              post_stim=1.5)

# Take the SVD across to represent RF map across depth
rf_svd = passive.get_svd_map(rf_map_avg)

# Now we can plot the RF map for the on and off response
on_rf_map = np.vstack(rf_svd['on'])
off_rf_map = np.vstack(rf_svd['off'])

fig, ax = plt.subplots(1, 2)
depths = np.linspace(0, 3840, len(rf_svd['on']) + 1)
ax[0].imshow(on_rf_map, extent=(0, 500, 0, 3840), origin='lower')