def test_LSN_redistribute_probes(self): lsn = sr.LocallySparseNoise(monitor=self.monitor, indicator=self.indicator, min_distance=20., 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-OFF', iteration=1, pregap_dur=2., postgap_dur=3., is_include_edge=True) all_probes = lsn._generate_all_probes() frames = lsn._generate_probe_sequence_one_iteration(all_probes=all_probes, is_redistribute=True) # print '\n'.join([str(f) for f in frames]) # print [len(f) for f in frames] assert (sum([len(f) for f in frames]) == len(all_probes)) import itertools import numpy as np alt_lst = np.arange(-10., 25., 10) azi_lst = np.arange(0., 65., 10) all_probes = list(itertools.product(alt_lst, azi_lst, [-1., 1.])) all_probes_frame = [] for frame in frames: all_probes_frame += [tuple(probe) for probe in frame] # asserting all pairs in the particular frame meet sparsity criterion for (p0, p1) in itertools.combinations(frame, r=2): curr_dis = np.sqrt((p0[0] - p1[0]) ** 2 + (p0[1] - p1[1]) ** 2) # print (p0, p1), curr_dis assert (curr_dis > 20.) # assert all frames combined cover whole subregion assert (set(all_probes) == set(all_probes_frame))
def test_LSN_repeat(self): lsn = sr.LocallySparseNoise(monitor=self.monitor, indicator=self.indicator, min_distance=20., background=0., coordinate='degree', grid_space=(10., 10.), probe_size=(10., 10.), probe_orientation=0., probe_frame_num=4, subregion=[-10., 20., 0., 60.], sign='ON-OFF', iteration=1, pregap_dur=2., postgap_dur=3., is_include_edge=True, repeat=3) import itertools import numpy as np alt_lst = np.arange(-10., 25., 10) azi_lst = np.arange(0., 65., 10) all_probes = list(itertools.product(alt_lst, azi_lst, [-1., 1.])) frames_unique, display_index = lsn._generate_display_index() for probe in all_probes: present_frames = 0 for di in display_index: if frames_unique[di][1] is not None and list( probe) in frames_unique[di][1]: present_frames += 1 # print('probe:{}, number of frames: {}'.format(str(probe), present_frames)) assert (present_frames == 4 * 3)
def test_LSN_generate_display_index(self): lsn = sr.LocallySparseNoise(monitor=self.monitor, indicator=self.indicator, min_distance=20., background=0., coordinate='degree', grid_space=(10., 10.), probe_size=(10., 10.), probe_orientation=30., probe_frame_num=6, subregion=[-10., 20., 0., 60.], sign='ON-OFF', iteration=2, pregap_dur=2., postgap_dur=3., is_include_edge=True, repeat=1) frames_unique, index_to_display = lsn._generate_display_index() # print index_to_display assert (index_to_display[:lsn.pregap_frame_num] == [0] * lsn.pregap_frame_num) assert (index_to_display[-lsn.postgap_frame_num:] == [0] * lsn.postgap_frame_num) assert (len(index_to_display) == (len(frames_unique) - 1) * lsn.probe_frame_num / 2 + lsn.pregap_frame_num + lsn.postgap_frame_num)
def test_LSN_generate_probe_locs_one_frame(self): lsn = sr.LocallySparseNoise(monitor=self.monitor, indicator=self.indicator, min_distance=20., 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=2., postgap_dur=3., is_include_edge=True, repeat=1) all_probes = lsn._generate_all_probes() probes_one_frame, all_probes_left = lsn._generate_probe_locs_one_frame( all_probes) import itertools import numpy as np for (p0, p1) in itertools.combinations(probes_one_frame, r=2): curr_dis = np.sqrt((p0[0] - p1[0])**2 + (p0[1] - p1[1])**2) # print (p0, p1), curr_dis assert (curr_dis > 20.)
def test_LSN_generate_all_probes(self): lsn = sr.LocallySparseNoise(monitor=self.monitor, indicator=self.indicator, min_distance=20., background=0., coordinate='degree', grid_space=(10., 10.), probe_size=(10., 10.), probe_orientation=0., probe_frame_num=6, subregion=[-10., 10., 0., 30.], sign='ON', iteration=1, pregap_dur=2., postgap_dur=3., is_include_edge=True, repeat=1) all_probes = lsn._generate_all_probes() all_probes = [tuple(p) for p in all_probes] assert (set(all_probes) == { (-10., 0., 1.), (0., 0., 1.), (10., 0., 1.), (-10., 10., 1.), (0., 10., 1.), (10., 10., 1.), (-10., 20., 1.), (0., 20., 1.), (10., 20., 1.), (-10., 30., 1.), (0., 30., 1.), (10., 30., 1.), })
def test_LSN_generate_frames_for_index_display(self): lsn = sr.LocallySparseNoise(monitor=self.monitor, indicator=self.indicator, min_distance=20., 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-OFF', iteration=2, pregap_dur=2., postgap_dur=3., is_include_edge=True) frames_unique = lsn._generate_frames_for_index_display() # print len(frames_unique) # print '\n'.join([str(f) for f in frames_unique]) assert (len(frames_unique) % 2 == 1)
downsample_rate=mon_downsample_rate) # plot warpped monitor coordinates mon.plot_map() plt.show() # initialize Indicator object ind = Indicator(mon, width_cm=ind_width_cm, height_cm=ind_height_cm, position=ind_position, is_sync=ind_is_sync, freq=ind_freq) # initialize LocallySparseNoise object 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) # initialize DisplaySequence object ds = DisplaySequence(log_dir=ds_log_dir, backupdir=ds_backupdir, identifier=ds_identifier, display_iter=ds_display_iter, mouse_id=ds_mouse_id, user_id=ds_user_id, psychopy_mon=ds_psychopy_mon, is_by_index=ds_is_by_index, is_interpolate=ds_is_interpolate, is_triggered=ds_is_triggered, trigger_event=ds_trigger_event, trigger_NI_dev=ds_trigger_NI_dev, trigger_NI_port=ds_trigger_NI_port, trigger_NI_line=ds_trigger_NI_line, is_sync_pulse=ds_is_sync_pulse, sync_pulse_NI_dev=ds_sync_pulse_NI_dev, sync_pulse_NI_port=ds_sync_pulse_NI_port, sync_pulse_NI_line=ds_sync_pulse_NI_line,