def test_SI_wrap_images(self):
        si = sr.StaticImages(monitor=self.monitor, indicator=self.indicator, background=0.,
                             coordinate='degree', img_center=(0., 60.), deg_per_pixel=(0.1, 0.1),
                             display_dur=0.25, midgap_dur=0., iteration=1, pregap_dur=2.,
                             postgap_dur=3.)
        si.wrap_images(work_dir=os.path.join(self.curr_folder, 'test_data'))

        img_w_path = os.path.join(self.curr_folder, 'test_data', 'wrapped_images_for_display.hdf5')

        import h5py
        img_w_f = h5py.File(img_w_path, 'r')

        assert (img_w_f['images_wrapped/images'].shape == (1, 120, 160))
        assert (img_w_f['images_wrapped/altitude'].shape == (120, 160))
        assert (img_w_f['images_wrapped/azimuth'].shape == (120, 160))
        import numpy as np
        assert (np.array_equal(img_w_f['images_wrapped/altitude'].value, self.monitor.deg_coord_y))
        assert (np.array_equal(img_w_f['images_wrapped/azimuth'].value, self.monitor.deg_coord_x))

        assert (img_w_f['images_dewrapped/images'].shape == (1, 512, 761))
        assert (img_w_f['images_dewrapped/altitude'].shape == (512, 761))
        assert (img_w_f['images_dewrapped/azimuth'].shape == (512, 761))

        img_w_f.close()

        os.remove(img_w_path)
    def test_SI_blank_block(self):
        si = sr.StaticImages(monitor=self.monitor,
                             indicator=self.indicator,
                             background=0.,
                             coordinate='degree',
                             img_center=(0., 60.),
                             deg_per_pixel=(0.1, 0.1),
                             display_dur=0.1,
                             midgap_dur=0.1,
                             iteration=1,
                             pregap_dur=0.,
                             postgap_dur=0.,
                             is_blank_block=True)
        import numpy as np
        si.images_wrapped = np.random.rand(2, 120, 160)
        frames_unique, index_to_display = si._generate_display_index()
        assert (len(frames_unique) == 7)
        for frame in frames_unique:
            assert (len(frame) == 3)
        assert (frames_unique[-1] == (1, -1, 0.))
        assert (frames_unique[-2] == (1, -1, 1.))

        # print('frames_unique:')
        # print('\n'.join([str(f) for f in frames_unique]))
        # print('\nindex_to_display: {}.'.format(index_to_display))
        # print('\nframes to be displayed:')
        # frames = [frames_unique[i] for i in index_to_display]
        # print('\n'.join([str(f) for f in frames]))
        assert (len(index_to_display) == 30)
 def test_SI_generate_display_index(self):
     si = sr.StaticImages(monitor=self.monitor, indicator=self.indicator, background=0.,
                          coordinate='degree', img_center=(0., 60.), deg_per_pixel=(0.1, 0.1),
                          display_dur=0.25, midgap_dur=0.1, iteration=2, pregap_dur=2.,
                          postgap_dur=3.)
     import numpy as np
     si.images_wrapped = np.random.rand(15, 120, 160)
     frames_unique, index_to_display = si._generate_display_index()
     assert (len(index_to_display) == 924)
예제 #4
0
 def test_SI_generate_frames_for_index_display(self):
     si = sr.StaticImages(monitor=self.monitor, indicator=self.indicator, background=0.,
                          coordinate='degree', img_center=(0., 60.), deg_per_pixel=(0.1, 0.1),
                          display_dur=0.25, midgap_dur=0., iteration=1, pregap_dur=2.,
                          postgap_dur=3., is_blank_block=False)
     import numpy as np
     si.images_wrapped = np.random.rand(27, 120, 160)
     frames_unique = si._generate_frames_for_index_display()
     assert (len(frames_unique) == 55)
     for frame in frames_unique:
         assert (len(frame) == 3)
sgc = stim.StaticGratingCircle(monitor=mon, indicator=ind, pregap_dur=pregap_dur,
                               postgap_dur=postgap_dur, coordinate=coordinate,
                               background=background, center=sgc_center,
                               sf_list=sgc_sf_list, ori_list=sgc_ori_list,
                               con_list=sgc_con_list, radius_list=sgc_radius_list,
                               phase_list=sgc_phase_list, display_dur=sgc_display_dur,
                               midgap_dur=sgc_midgap_dur, iteration=sgc_iteration,
                               is_smooth_edge=sgc_is_smooth_edge,
                               smooth_width_ratio=sgc_smooth_width_ratio,
                               smooth_func=sgc_smooth_func, is_blank_block=sgc_is_blank_block)
# =================================================================================

# =============================== Static Images ===================================
si = stim.StaticImages(monitor=mon, indicator=ind, pregap_dur=pregap_dur,
                       postgap_dur=postgap_dur, coordinate=coordinate,
                       background=background, img_center=si_img_center,
                       deg_per_pixel=si_deg_per_pixel, display_dur=si_display_dur,
                       midgap_dur=si_midgap_dur, iteration=si_iteration,
                       is_blank_block=si_is_blank_block)
# =================================================================================

# ============================ wrape images =======================================
print ('wrapping images ...')
static_images_path = os.path.join(si_images_folder, 'wrapped_images_for_display.hdf5')
if os.path.isfile(static_images_path):
    os.remove(static_images_path)
si.wrap_images(si_images_folder)
# =================================================================================

# ======================= Stimulus Separator ======================================
ss = stim.StimulusSeparator(monitor=mon, indicator=ind, pregap_dur=pregap_dur,
                            postgap_dur=postgap_dur, coordinate=coordinate,