def test_SN_generate_movie(self):
     sn = sr.SparseNoise(monitor=self.monitor, indicator=self.indicator,
                         background=0., coordinate='degree', grid_space=(10., 10.),
                         probe_size=(10., 10.), probe_orientation=0., probe_frame_num=6,
                         subregion=[-20., -10., 30., 90.], sign='OFF', iteration=1, pregap_dur=0.1,
                         postgap_dur=0.2, is_include_edge=True)
     mov, _ = sn.generate_movie()
     import numpy as np
     import matplotlib.pyplot as plt
     # plt.imshow(np.min(mov, axis=0))
     # plt.show()
     assert (np.min(mov, axis=0)[92, 38] == -1)
 def test_SN_get_probe_index_for_one_iter_on_off(self):
     import numpy as np
     sn = sr.SparseNoise(monitor=self.monitor, indicator=self.indicator,
                         background=0., coordinate='degree', grid_space=(5., 5.),
                         probe_size=(5., 5.), probe_orientation=0., probe_frame_num=6,
                         subregion=[-30, 30, -10., 90.], sign='ON-OFF', iteration=2)
     frames_unique = sn._generate_frames_for_index_display()
     probe_ind = sn._get_probe_index_for_one_iter_on_off(frames_unique)
     for j in range(len(probe_ind) - 1):
         probe_loc_0 = frames_unique[probe_ind[j]]
         probe_loc_1 = frames_unique[probe_ind[j + 1]]
         assert(not np.array_equal(probe_loc_0, probe_loc_1))
    def test_SN_generate_display_index(self):
        sn = sr.SparseNoise(monitor=self.monitor, indicator=self.indicator,
                            background=0., coordinate='degree', grid_space=(10.,10.),
                            probe_size=(10.,10.), probe_orientation=0., probe_frame_num=6,
                            subregion=[10, 20, 0., 60.], sign='ON', iteration=1, pregap_dur=0.1,
                            postgap_dur=0.2, is_include_edge=True)

        frames_unique, index_to_display = sn._generate_display_index()
        # print '\n'.join([str(f) for f in frames_unique])
        # print index_to_display
        assert (index_to_display[:6] == [0, 0, 0, 0, 0, 0])
        assert (index_to_display[-12:] == [0] * 12)
        # print max(index_to_display)
        # print len(frames_unique)
        assert (max(index_to_display) == len(frames_unique) -1)
        probe_num = (len(index_to_display) - 18) / 6
        for probe_ind in range(probe_num):
            assert (len(set(index_to_display[6 + probe_ind * 6: 9 + probe_ind * 6])) == 1)
            assert (len(set(index_to_display[9 + probe_ind * 6: 12 + probe_ind * 6])) == 1)
            assert (index_to_display[9 + probe_ind * 6] - index_to_display[8 + probe_ind * 6] == 1)
    def test_SN_generate_display_index2(self):
        import numpy as np
        sn = sr.SparseNoise(monitor=self.monitor, indicator=self.indicator,
                            background=0., coordinate='degree', grid_space=(10., 10.),
                            probe_size=(10., 10.), probe_orientation=0., probe_frame_num=8,
                            subregion=[-10, 10, 45., 55.], sign='ON-OFF', iteration=2,
                            pregap_dur=0.5, postgap_dur=0.3, is_include_edge=True)

        frames_unique, index_to_display = sn._generate_display_index()
        assert (index_to_display[:30] == [0] * 30)
        assert (index_to_display[-18:] == [0] * 18)
        assert (max(index_to_display) == len(frames_unique) - 1)

        # frame_num_iter = (len(index_to_display) - 18 - 30) / 2
        assert ((len(index_to_display) - 48) % (8 * 2) == 0)
        probe_num = (len(index_to_display) - 48) / (8 * 2)
        for probe_ind in range(probe_num):
            assert (len(set(index_to_display[30 + probe_ind * 8: 34 + probe_ind * 8])) == 1)
            assert (len(set(index_to_display[34 + probe_ind * 8: 38 + probe_ind * 8])) == 1)
            assert (np.array_equal(frames_unique[index_to_display[33 + probe_ind * 8]][1],
                                   frames_unique[index_to_display[34 + probe_ind * 8]][1]))
# =================================================================================

# ============================ SinusoidalLuminance ================================
sl = stim.SinusoidalLuminance(monitor=mon, indicator=ind, pregap_dur=pregap_dur,
                              postgap_dur=postgap_dur, coordinate=coordinate,
                              background=background, max_level=sl_max_level,
                              min_level=sl_min_level, frequency=sl_frequency,
                              cycle_num=sl_cycle_num, start_phase=sl_start_phase,
                              midgap_dur=sl_midgap_dur)
# =================================================================================

# ======================== Sparse Noise ===========================================
sn = stim.SparseNoise(monitor=mon, indicator=ind, pregap_dur=pregap_dur,
                      postgap_dur=postgap_dur, coordinate=coordinate,
                      background=background, subregion=sn_subregion,
                      grid_space=sn_grid_space, sign=sn_sign,
                      probe_size=sn_probe_size, probe_orientation=sn_probe_orientation,
                      probe_frame_num=sn_probe_frame_num, iteration=sn_iteration,
                      is_include_edge=sn_is_include_edge)
# =================================================================================

# ======================= Locally Sparse Noise ====================================
lsn = stim.LocallySparseNoise(monitor=mon, indicator=ind, pregap_dur=pregap_dur,
                              postgap_dur=postgap_dur, coordinate=coordinate,
                              background=background, subregion=lsn_subregion,
                              grid_space=lsn_grid_space, sign=lsn_sign,
                              probe_size=lsn_probe_size, probe_orientation=lsn_probe_orientation,
                              probe_frame_num=lsn_probe_frame_num, iteration=lsn_iteration,
                              is_include_edge=lsn_is_include_edge, min_distance=lsn_min_distance,
                              repeat=lsn_repeat)
# =================================================================================
示例#6
0
                  mon_width_cm=2,
                  mon_height_cm=1.5,
                  refresh_rate=60.0)

    # mon.plot_map()
    # plt.show()

    # creating a monitor object to display the indicator on (since we don' use it)
    mon_bin = Monitor(resolution=(0, 0),
                      dis=15.,
                      mon_width_cm=52.,
                      mon_height_cm=32.)
    ind = Indicator(mon_bin, width_cm=3, height_cm=3, is_sync=True, freq=1)

    sparse_noise = stim.SparseNoise(mon,
                                    ind,
                                    grid_space=(0.5, 0.5),
                                    probe_size=(0.5, 0.5),
                                    probe_frame_num=6,
                                    coordinate='linear',
                                    midgap_dur=0.5,
                                    iteration=5)

    ds = DisplaySequence(log_dir="data",
                         is_by_index=True,
                         display_screen=1,
                         is_sync_pulse_LJ=False)

    ds.set_stim(sparse_noise)
    ds.trigger_display(fullscr=False)