コード例 #1
0
ファイル: framework.py プロジェクト: ClandininLab/flystim
def main():
    # get the configuration parameters
    kwargs = get_kwargs()

    # get the screen
    screen = Screen.deserialize(kwargs.get('screen', {}))

    # launch the server
    server = MySocketServer(host=kwargs['host'],
                            port=kwargs['port'],
                            threaded=True,
                            auto_stop=True,
                            name=screen.name)

    # launch application
    app = QtWidgets.QApplication([])

    # create the StimDisplay object
    screen = Screen.deserialize(kwargs.get('screen', {}))
    stim_display = StimDisplay(screen=screen, server=server, app=app)

    # register functions
    server.register_function(stim_display.set_fly_trajectory)
    server.register_function(stim_display.load_stim)
    server.register_function(stim_display.start_stim)
    server.register_function(stim_display.stop_stim)
    server.register_function(stim_display.save_rendered_movie)
    server.register_function(stim_display.start_corner_square)
    server.register_function(stim_display.stop_corner_square)
    server.register_function(stim_display.white_corner_square)
    server.register_function(stim_display.black_corner_square)
    server.register_function(stim_display.set_corner_square)
    server.register_function(stim_display.show_corner_square)
    server.register_function(stim_display.hide_corner_square)
    server.register_function(stim_display.set_idle_background)
    server.register_function(stim_display.set_global_fly_pos)
    server.register_function(stim_display.set_global_theta_offset)
    server.register_function(stim_display.set_global_phi_offset)

    # display the stimulus
    if screen.fullscreen:
        stim_display.showFullScreen()
    else:
        stim_display.show()

    ####################################
    # Run QApplication
    ####################################

    # Use Ctrl+C to exit.
    # ref: https://stackoverflow.com/questions/2300401/qapplication-how-to-shutdown-gracefully-on-ctrl-c
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    sys.exit(app.exec_())
コード例 #2
0
def main():
    manager = launch_stim_server(Screen(fullscreen=False, server_number=0, id=0, vsync=False))

    manager.load_stim(name='ConstantBackground', color=[0.5, 0.5, 0.5, 1.0], side_length=100)

    distribution_data = {'name': 'Ternary',
                         'args': [0.0, 1.0],
                         'kwargs': {}}
    #
    # theta_trajectory = {'name': 'tv_pairs',
    #                     'tv_pairs': [(0, -45), (4, 45)],
    #                     'kind': 'linear'}

    manager.load_stim(name='RandomGridOnSphericalPatch', patch_width=5, patch_height=5, distribution_data=distribution_data, update_rate=0.0, start_seed=0,
                      width=60, height=60, sphere_radius=1.1, color=[1, 0, 1, 1], theta=0, phi=0, angle=0, hold=True, rgb_texture=True)

    # manager.set_global_fly_pos(0, -2, 0)

    # manager.load_stim(name='RandomGrid', patch_width=5, patch_height=5, cylinder_vertical_extent=80, cylinder_angular_extent=120,
    #                   distribution_data=distribution_data, update_rate=0, start_seed=0,
    #                   color=[1, 1, 1, 1], cylinder_radius=1.1, theta=90, phi=0, angle=0.0, hold=True, rgb_texture=False)

    # manager.load_stim(name='MovingSpot', radius=2.5, sphere_radius=1, color=[1, 0, 0, 1], theta=5, phi=-21.5, hold=True)
    #
    # manager.load_stim(name='MovingSpot', radius=2.5, sphere_radius=1, color=[1, 0, 0, 1], theta=5, phi=2.5, hold=True)

    sleep(1)

    manager.start_stim()
    sleep(10)

    manager.stop_stim(print_profile=True)
    sleep(1)
コード例 #3
0
def main():

    stim_duration = 2
    iti = 2

    screen = Screen(fullscreen=False, server_number=0, id=0, vsync=False)

    # draw_screens(screen)

    manager = launch_stim_server(screen)

    for i in range(2):
        manager.load_stim(name='RotatingGrating',
                          rate=60,
                          hold_duration=1,
                          period=60,
                          mean=0.5,
                          contrast=1.0,
                          offset=0.0,
                          profile='square',
                          color=[1, 1, 1, 1],
                          cylinder_radius=1.1,
                          cylinder_height=10,
                          theta=0,
                          phi=0,
                          angle=0,
                          hold=True)

        sleep(iti)

        manager.start_stim()
        sleep(stim_duration)

        manager.stop_stim(print_profile=True)
        sleep(iti)
コード例 #4
0
def main():
    manager = launch_stim_server(
        Screen(fullscreen=False, server_number=0, id=0, vsync=True))

    manager.load_stim(name='ConstantBackground',
                      color=[0.5, 0.5, 0.5, 1.0],
                      side_length=100)

    distribution_data = {'name': 'Ternary', 'args': [0, 1], 'kwargs': {}}

    manager.load_stim(name='RandomGrid',
                      patch_width=5,
                      patch_height=5,
                      cylinder_vertical_extent=80,
                      cylinder_angular_extent=120,
                      distribution_data=distribution_data,
                      update_rate=1.0,
                      start_seed=0,
                      color=[1, 1, 1, 1],
                      cylinder_radius=1,
                      theta=90,
                      phi=0,
                      angle=0.0,
                      hold=True)

    # manager.load_stim(name='MovingSpot', radius=2.5, sphere_radius=1, color=[1, 0, 0, 1], theta=0, phi=21.5, hold=True)

    sleep(1)

    manager.start_stim()
    sleep(4)

    manager.stop_stim(print_profile=True)
    sleep(1)
コード例 #5
0
ファイル: dot_field.py プロジェクト: ClandininLab/flystim
def main():
    manager = launch_stim_server(Screen(fullscreen=False, server_number=0, id=0, vsync=True))

    # manager.load_stim(name='ConstantBackground', color=[0.5, 0.5, 0.5, 1.0], side_length=100)

    # manager.load_stim(name='MovingDotField', n_points=200, point_size=20, sphere_radius=1, color=[0, 1, 0, 1],
    #                   speed=60, signal_direction=0, coherence=1.0, random_seed=0, sphere_pitch=45, hold=True)

    manager.load_stim(name='MovingDotField_Cylindrical', n_points=200, point_size=80, cylinder_radius=1, color=[1, 0, 0, 1],
                      speed=60, signal_direction=45, coherence=1.0, random_seed=0, cylinder_pitch=45, phi_limits=[45, 135], hold=True)

    # n_points = 50

    # x_locations = list(np.random.uniform(-2, 2, n_points))
    # y_locations = list(np.random.uniform(0, 8, n_points))
    # z_locations = list(np.random.uniform(-2, 2, n_points))
    #
    # point_locations = [x_locations, y_locations, z_locations]
    #
    # velocity_y = -0.5  # m/sec
    # y_offset = {'name': 'tv_pairs',
    #             'tv_pairs': [(0, 0), (6, 6*velocity_y)],
    #             'kind': 'linear'}
    # manager.load_stim(name='ProgressiveStarfield', point_size=20, color=[0, 0, 0, 1],
    #                   point_locations=point_locations,
    #                   y_offset=y_offset, hold=True)
    #

    sleep(1)

    manager.start_stim()
    sleep(6)

    manager.stop_stim(print_profile=True)
    sleep(1)
コード例 #6
0
def main():
    manager = launch_stim_server(
        Screen(fullscreen=False, server_number=0, id=0, vsync=True))

    manager.load_stim(name='ConstantBackground',
                      color=[0.5, 0.5, 0.5, 1.0],
                      side_length=100)

    tv_pairs = [(0, -45), (4, 45)]
    theta_traj = Trajectory(tv_pairs, kind='linear').to_dict()

    tf = 2  # Hz
    t = np.linspace(0, 6, 100)
    c = np.sin(2 * np.pi * tf * t) + 1
    tv_pairs = list(zip(t, c))
    color_traj = Trajectory(tv_pairs, kind='linear').to_dict()

    manager.load_stim(name='MovingSpot',
                      radius=5,
                      sphere_radius=1,
                      color=color_traj,
                      theta=theta_traj,
                      phi=0,
                      hold=True)

    sleep(1)

    manager.start_stim()
    sleep(4)

    manager.stop_stim(print_profile=True)
    sleep(1)
コード例 #7
0
def main():
    left_screen = Screen(subscreens=[get_subscreen('l')], server_number=1, id=1, fullscreen=True, vsync=True, square_size=(0.1, 0.1), square_loc=(1, -1), name='Left', horizontal_flip=False)

    center_screen = Screen(subscreens=[get_subscreen('c')], server_number=1, id=2, fullscreen=True, vsync=True, square_size=(0.1, 0.1), square_loc=(-1, -1), name='Center', horizontal_flip=False)

    right_screen = Screen(subscreens=[get_subscreen('r')], server_number=1, id=3, fullscreen=True, vsync=True, square_size=(0.1, 0.122), square_loc=(-1, -1), name='Right', horizontal_flip=False)

    aux_screen = Screen(subscreens=[get_subscreen('aux')], server_number=1, id=0, fullscreen=False, vsync=True, square_size=(0, 0), square_loc=(-1, -1), name='Aux', horizontal_flip=False)

    draw_screens([left_screen, center_screen, right_screen])
    plt.show()

    screens = [left_screen, center_screen, right_screen, aux_screen]

    manager = launch_stim_server(screens)

    manager.black_corner_square()
    manager.set_idle_background(0)
    
    
    manager.load_stim(name='ConstantBackground', color=[0.5, 0.5, 0.5, 1.0], side_length=100)

    manager.load_stim(name='RotatingGrating', rate=25, period=30, mean=0.5, contrast=1.0, offset=0.0, profile='square',
                      color=[1, 1, 1, 1], cylinder_radius=1.1, cylinder_height=10, theta=0, phi=0, angle=90, hold=True)

    tv_pairs = [(0, 0), (4, 360)]
    theta_traj = {'name': 'tv_pairs',
                  'tv_pairs': tv_pairs,
                  'kind': 'linear'}

    manager.load_stim(name='MovingPatch', width=30, height=30, phi=0, color=[1, 0, 0, 0.5], theta=theta_traj, hold=True, angle=0)

    sleep(0.5)

    manager.start_stim()
    sleep(8)

    manager.stop_stim(print_profile=True)
    sleep(0.5)
    
    manager.black_corner_square()
    manager.set_idle_background(0)
コード例 #8
0
def main():
    subscreens = [get_subscreen('w'), get_subscreen('n'), get_subscreen('e')]
    screen = Screen(subscreens=subscreens,
                    server_number=0,
                    id=0,
                    fullscreen=False,
                    square_loc=(0.75, -1.0),
                    square_size=(0.25, 0.25),
                    vsync=True)

    draw_screens(screen)

    manager = launch_stim_server(screen)

    tv_pairs = [(0, 0), (4, 360)]
    angle_traj = Trajectory(tv_pairs, kind='linear').to_dict()
    manager.load_stim(name='ConstantBackground',
                      color=[0.5, 0.5, 0.5, 1.0],
                      side_length=100)

    manager.load_stim(name='RotatingGrating',
                      rate=25,
                      period=30,
                      mean=0.5,
                      contrast=1.0,
                      offset=0.0,
                      profile='square',
                      color=[1, 1, 1, 1],
                      cylinder_radius=1.1,
                      cylinder_height=10,
                      theta=0,
                      phi=0,
                      angle=90,
                      hold=True)

    tv_pairs = [(0, 0), (4, 360)]
    theta_traj = Trajectory(tv_pairs, kind='linear').to_dict()

    manager.load_stim(name='MovingPatch',
                      width=30,
                      height=30,
                      phi=0,
                      color=[1, 0, 0, 1],
                      theta=theta_traj,
                      hold=True,
                      angle=0)

    sleep(0.5)

    manager.start_stim()
    sleep(8)

    manager.stop_stim(print_profile=True)
    sleep(0.5)
コード例 #9
0
def main():
    # get the startup arguments
    kwargs = get_kwargs()

    # get list of screens
    screens = kwargs['screens']
    if screens is None:
        screens = []
    screens = [Screen.deserialize(screen) for screen in screens]

    # run the server
    run_stim_server(host=kwargs['host'],
                    port=kwargs['port'],
                    auto_stop=kwargs['auto_stop'],
                    screens=screens)
コード例 #10
0
ファイル: single_stim.py プロジェクト: ClandininLab/flystim
def main(stim_name):
    manager = launch_stim_server(
        Screen(fullscreen=False,
               server_number=0,
               id=0,
               vsync=False,
               square_loc=(-1.0, -1.0),
               square_size=(0.25, 0.25)))

    manager.load_stim(name=stim_name)

    sleep(0.5)

    manager.start_stim()
    sleep(4)

    manager.stop_stim(print_profile=True)
    sleep(0.5)
コード例 #11
0
def main():
    manager = launch_stim_server(
        Screen(fullscreen=False, server_number=0, id=0, vsync=True))

    stims = [
        'ConstantBackground', 'Floor', 'MovingSpot', 'MovingPatch',
        'CylindricalGrating', 'RotatingGrating', 'RandomBars', 'RandomGrid',
        'Checkerboard', 'Tower', 'TexturedGround', 'HorizonCylinder', 'Forest',
        'CoherentMotionDotField'
    ]

    for stim in stims:
        manager.load_stim(stim)
        sleep(500e-3)

        manager.start_stim()
        sleep(2.5)

        manager.stop_stim(print_profile=True)
        sleep(500e-3)
コード例 #12
0
def main():
    screen = Screen(fullscreen=False, server_number=0, id=0, vsync=False)

    # draw_screens(screen)

    manager = launch_stim_server(screen)

    # contrast-reversing grating
    # tf = 1 # Hz
    # t = np.linspace(0, 6, 100)
    # c = np.sin(2*np.pi*tf*t)
    # tv_pairs = list(zip(t, c))
    # contrast_traj = Trajectory(tv_pairs, kind='linear').to_dict()

    contrast_trajectory = {
        'name': 'Sinusoid',
        'temporal_frequency': 1,
        'amplitude': 1,
        'offset': 0
    }

    manager.load_stim(name='CylindricalGrating',
                      period=10,
                      mean=0.5,
                      contrast=contrast_trajectory,
                      offset=0.0,
                      profile='square',
                      color=[1, 1, 1, 1],
                      cylinder_radius=1,
                      cylinder_height=10,
                      theta=0,
                      phi=0,
                      angle=0)

    sleep(1)

    manager.start_stim()
    sleep(4)

    manager.stop_stim(print_profile=True)
    sleep(1)
コード例 #13
0
ファイル: moving_patch.py プロジェクト: ClandininLab/flystim
def main():
    manager = launch_stim_server(
        Screen(fullscreen=False, server_number=0, id=0, vsync=False))

    manager.load_stim(name='ConstantBackground',
                      color=[0.5, 0.5, 0.5, 1.0],
                      side_length=100)

    theta_trajectory = {
        'name': 'tv_pairs',
        'tv_pairs': [(0, -45), (4, 45)],
        'kind': 'linear'
    }

    # color_trajectory = {'name': 'Sinusoid',
    #                     'temporal_frequency': 2,
    #                     'amplitude': 1,
    #                     'offset': 1}

    color_trajectory = {
        'name': 'tv_pairs',
        'tv_pairs': [(0, (0, 0, 0, 1)), (1, (0, 0, 0, 0)), (2, (0, 0, 0, 1))],
        'kind': 'linear'
    }

    manager.load_stim(name='MovingSpot',
                      radius=5,
                      sphere_radius=1,
                      color=color_trajectory,
                      theta=theta_trajectory,
                      phi=0,
                      hold=True)

    sleep(1)

    manager.start_stim()
    sleep(4)

    manager.stop_stim(print_profile=True)
    sleep(1)
コード例 #14
0
def main():
    manager = launch_stim_server(
        Screen(fullscreen=False, server_number=0, id=0, vsync=False))

    manager.load_stim(name='ConstantBackground',
                      color=[0.5, 0.5, 0.5, 1.0],
                      side_length=100)

    loom_trajectory = {
        'name': 'Loom',
        'rv_ratio': 0.08,
        'stim_time': 4,
        'start_size': 3,
        'end_size': 90
    }

    color_trajectory = {
        'name': 'Sinusoid',
        'temporal_frequency': 2,
        'amplitude': 1,
        'offset': 1
    }

    manager.load_stim(name='MovingSpot',
                      radius=loom_trajectory,
                      sphere_radius=1,
                      color=color_trajectory,
                      theta=0,
                      phi=0,
                      hold=True)

    sleep(1)

    manager.start_stim()
    sleep(4)

    manager.stop_stim(print_profile=True)
    sleep(1)
コード例 #15
0
def main():

    stim_duration = 2
    iti = 2

    screen = Screen(fullscreen=False, server_number=0, id=0, vsync=False)

    # draw_screens(screen)

    manager = launch_stim_server(screen)

    for i in range(2):
        manager.load_stim(name='ExpandingEdges',
                          rate=-80,
                          period=40,
                          vert_extent=80,
                          theta_offset=0,
                          expander_color=0.0,
                          opposite_color=1.0,
                          width_0=2,
                          n_theta_pixels=2880 * 2,
                          hold_duration=0.550,
                          color=[1, 1, 1, 1],
                          cylinder_radius=1,
                          theta=0,
                          phi=0,
                          angle=0.0,
                          cylinder_location=(0, 0, 0),
                          hold=True)

        sleep(iti)

        manager.start_stim()
        sleep(stim_duration)

        manager.stop_stim(print_profile=True)
        sleep(iti)
コード例 #16
0
def main():

    stim_duration = 2
    iti = 2

    screen = Screen(fullscreen=False, server_number=0, id=0, vsync=False)

    # draw_screens(screen)

    manager = launch_stim_server(screen)

    for i in range(2):
        manager.load_stim(name='RandomBars',
                          period=20,
                          width=5,
                          vert_extent=80,
                          theta_offset=0,
                          background=0.5,
                          distribution_data=None,
                          update_rate=4.0,
                          start_seed=10,
                          color=[1, 1, 1, 1],
                          cylinder_radius=1,
                          theta=0,
                          phi=0,
                          angle=0.0,
                          cylinder_location=(0, 0, 0),
                          hold=True)

        sleep(iti)

        manager.start_stim()
        sleep(stim_duration)

        manager.stop_stim(print_profile=True)
        sleep(iti)
コード例 #17
0
def main():
    subscreens = [
        SubScreen(pa=(-0.1, 0.2, -0.1),
                  pb=(0.1, 0.2, -0.1),
                  pc=(-0.1, 0.2, 0.1),
                  viewport_ll=(-1, -1),
                  viewport_width=2,
                  viewport_height=2)
    ]

    screen = Screen(subscreens=subscreens,
                    id=0,
                    fullscreen=True,
                    vsync=True,
                    square_size=(0.18, 0.25),
                    square_loc=(0.78, -0.86),
                    name='Left',
                    horizontal_flip=False)

    # draw_screens(screen)

    manager = launch_stim_server(screen)

    manager.load_stim(name='ConstantBackground',
                      color=[0.5, 0.5, 0.5, 1.0],
                      side_length=100)
    manager.load_stim(name='Floor',
                      color=[0.5, 0.5, 0.5, 1.0],
                      z_level=-0.25,
                      side_length=5,
                      hold=True)

    z_level = -0.2
    manager.load_stim(name='Tower',
                      color=[1, 0, 0, 1.0],
                      cylinder_location=[-0.25, +1, z_level],
                      cylinder_height=0.1,
                      cylinder_radius=0.05,
                      hold=True)  # red, +y, left
    manager.load_stim(name='Tower',
                      color=[0, 1, 0, 1.0],
                      cylinder_location=[0.0, +1, z_level],
                      cylinder_height=0.1,
                      cylinder_radius=0.05,
                      hold=True)  # green, +y, center
    manager.load_stim(name='Tower',
                      color=[0, 0, 1, 1],
                      cylinder_location=[+0.25, +1, z_level],
                      cylinder_height=0.1,
                      cylinder_radius=0.05,
                      hold=True)  # blue, +y, right

    manager.load_stim(name='Tower',
                      color=[1, 1, 0, 1.0],
                      cylinder_location=[-0.25, -1, z_level],
                      cylinder_height=0.1,
                      cylinder_radius=0.05,
                      hold=True)  # -y, left
    manager.load_stim(name='Tower',
                      color=[0, 1, 1, 1.0],
                      cylinder_location=[0.0, -1, z_level],
                      cylinder_height=0.1,
                      cylinder_radius=0.05,
                      hold=True)  #g-b -y, center
    manager.load_stim(name='Tower',
                      color=[1, 0, 1, 1],
                      cylinder_location=[+0.25, -1, z_level],
                      cylinder_height=0.1,
                      cylinder_radius=0.05,
                      hold=True)  #purple -y, right

    tt = np.arange(0, 12, 0.01)  # seconds
    velocity_x = 0.0  # meters per sec
    velocity_y = 0.2

    xx = tt * velocity_x
    yy = tt * velocity_y

    # dtheta = 0.0*np.random.normal(size=len(tt))
    dtheta = tt * 0.0
    theta = np.cumsum(dtheta)

    fly_x_trajectory = Trajectory(list(zip(tt, xx))).to_dict()
    fly_y_trajectory = Trajectory(list(zip(tt, yy))).to_dict()
    fly_theta_trajectory = Trajectory(list(zip(tt, theta))).to_dict()
    manager.set_fly_trajectory(fly_x_trajectory, fly_y_trajectory,
                               fly_theta_trajectory)

    sleep(0.5)

    manager.start_stim()
    sleep(2)

    manager.stop_stim(print_profile=True)
    sleep(0.5)
コード例 #18
0
ファイル: vr_subscreens.py プロジェクト: ClandininLab/flystim
def main():
    subscreens = [get_subscreen('w'), get_subscreen('n'), get_subscreen('e')]
    screen = Screen(subscreens=subscreens, server_number=0, id=0, fullscreen=False, square_loc=(0.75, -1.0), square_size=(0.25, 0.25), vsync=True)

    # draw_screens(screen)

    manager = launch_stim_server(screen)
    manager.black_corner_square() # turn off square as server starts up

    num_trials = 5
    pre_time = 1 #sec
    stim_time = 4 #sec
    tail_time = 1 #sec
    for rep in range(num_trials):

        # (1) LOAD STIMS
        multicall_load = flyrpc.multicall.MyMultiCall(manager)

        multicall_load.load_stim(name='ConstantBackground', color = [0.5, 0.5, 0.5, 1.0], side_length=100)
        multicall_load.load_stim(name='Floor', color=[0.5, 0.5, 0.5, 1.0], z_level=-0.1, side_length=5, hold=True)

        multicall_load.load_stim(name='Tower', color=[1, 0, 0, 1.0], cylinder_location=[-0.25, +1, 0],  cylinder_height=0.1, cylinder_radius=0.05, hold=True) # red, +y, left
        multicall_load.load_stim(name='Tower', color=[0, 1, 0, 1.0], cylinder_location=[0.0, +1, 0],  cylinder_height=0.1, cylinder_radius=0.05, hold=True) # green, +y, center
        multicall_load.load_stim(name='Tower', color=[0, 0, 1, 1], cylinder_location=[+0.25, +1, 0],  cylinder_height=0.1, cylinder_radius=0.05, hold=True) # blue, +y, right


        tree_locations = []
        for tree in range(40):
            tree_locations.append([np.random.uniform(-2, 2), np.random.uniform(-2, 2), np.random.uniform(0, 0)])
        multicall_load.load_stim(name='Forest', color=[0, 0, 0, 1], cylinder_radius=0.05, cylinder_height=0.1, n_faces=8, cylinder_locations=tree_locations, hold=True)

        tt = np.arange(0, 12, 0.01) # seconds
        velocity_x = 0.00 # meters per sec
        velocity_y = 0.1

        xx = tt * velocity_x
        yy = tt * velocity_y

        # dtheta = 0.0*np.random.normal(size=len(tt))
        dtheta = tt * 0.0
        theta = np.cumsum(dtheta)

        fly_x_trajectory = {'name': 'tv_pairs',
                            'tv_pairs': list(zip(tt, xx)),
                            'kind': 'linear'}
        fly_y_trajectory = {'name': 'tv_pairs',
                            'tv_pairs': list(zip(tt, yy)),
                            'kind': 'linear'}
        fly_theta_trajectory = {'name': 'tv_pairs',
                                'tv_pairs': list(zip(tt, theta)),
                                'kind': 'linear'}
        multicall_load.set_fly_trajectory(fly_x_trajectory, fly_y_trajectory, 0)

        multicall_load() # load stims

        sleep(pre_time)

        # (2) START STIMS, FLICKER CORNER
        multicall_start = flyrpc.multicall.MyMultiCall(manager)
        multicall_start.start_stim()
        multicall_start.start_corner_square()
        multicall_start() #start stims

        sleep(stim_time)

        # (3) STOP STIMS, SET CORNER TO BLACK
        multicall_stop = flyrpc.multicall.MyMultiCall(manager)
        multicall_stop.stop_stim(print_profile=True)
        multicall_stop.black_corner_square()
        multicall_stop()
        sleep(tail_time)
コード例 #19
0
ファイル: occlusion.py プロジェクト: ClandininLab/flystim
def main():
    #####################################################
    # part 1: User defined parameters
    #####################################################

    n_repeats = input("Enter number of repeats (default 30): ")  #26
    if n_repeats == "":
        n_repeats = 30
    print(n_repeats)

    _ = input("Press enter to continue.")  #26

    #####################################################
    # part 2: stimulus definitions
    #####################################################

    # Trial structure
    trial_labels = np.array([
        "inc_r_inv", "inc_l_inv", "con_r_inv", "con_l_inv", "inc_r_vis",
        "inc_l_vis", "con_r_vis", "con_l_vis"
    ])  # visible, consistent. 00, 01, 10, 11
    trial_structure = np.random.permutation(np.repeat(trial_labels, n_repeats))
    n_trials = len(trial_structure)

    # Stimulus parameters
    stim_name = "pause"
    prime_speed = 10  #degrees per sec
    probe_speed = 10  #degrees per sec
    preprime_duration = 2  #seconds
    prime_duration = 2  #seconds
    occlusion_duration = 0.5  #seconds
    pause_duration = 1  #seconds
    probe_duration = 1  #seconds
    iti = 3  #seconds

    # Bar start location
    start_theta = -10

    con_stim_duration = preprime_duration + prime_duration + occlusion_duration + probe_duration
    inc_stim_duration = con_stim_duration + pause_duration

    background_color = 0

    bar_width = 15
    bar_height = 150
    bar_color = 1
    #bar_angle = 0

    occluder_height = 170
    occluder_color = 0.5

    #######################
    # Stimulus construction

    center = 0

    # consistent bar trajectory
    con_time = [0, preprime_duration]
    con_x = [start_theta, start_theta]
    inc_time = [0, preprime_duration]
    inc_x = [start_theta, start_theta]

    prime_movement = prime_speed * (prime_duration + occlusion_duration)
    prime_end_theta = start_theta + prime_movement
    prime_end_time = preprime_duration + prime_duration + occlusion_duration

    con_time.append(prime_end_time)
    con_x.append(prime_end_theta)
    inc_time.append(prime_end_time)
    inc_x.append(prime_end_theta)

    pause_end_theta = prime_end_theta
    pause_end_time = prime_end_time + pause_duration

    inc_time.append(pause_end_time)
    inc_x.append(pause_end_theta)

    probe_movement = probe_speed * probe_duration
    probe_end_theta = prime_end_theta + probe_movement
    con_probe_end_time = prime_end_time + probe_duration
    inc_probe_end_time = pause_end_time + probe_duration

    con_time.append(con_probe_end_time)
    con_x.append(probe_end_theta)
    inc_time.append(inc_probe_end_time)
    inc_x.append(probe_end_theta)

    # Compute location and width of the occluder per specification
    occlusion_start_theta = start_theta + prime_speed * prime_duration
    occluder_width = prime_speed * occlusion_duration + bar_width  # the last term ensures that the bar is completely hidden during the occlusion period
    occluder_loc = occlusion_start_theta + occluder_width / 2 - bar_width / 2  # the last two terms account for widths of the bar and the occluder, such that the bar is completely hidden during occlusion period
    occluder_time = [0, con_stim_duration]
    occluder_x = [occluder_loc, occluder_loc]

    con_bar_traj_r = list(zip(con_time, (center - np.array(con_x)).tolist()))
    con_bar_traj_l = list(zip(con_time, (center + np.array(con_x)).tolist()))
    inc_bar_traj_r = list(zip(inc_time, (center - np.array(inc_x)).tolist()))
    inc_bar_traj_l = list(zip(inc_time, (center + np.array(inc_x)).tolist()))
    occluder_traj_r = list(
        zip(occluder_time, (center - np.array(occluder_x)).tolist()))
    occluder_traj_l = list(
        zip(occluder_time, (center + np.array(occluder_x)).tolist()))

    # Create flystim trajectory objects
    con_bar_r = {
        'name': 'tv_pairs',
        'tv_pairs': con_bar_traj_r,
        'kind': 'linear'
    }
    con_bar_l = {
        'name': 'tv_pairs',
        'tv_pairs': con_bar_traj_l,
        'kind': 'linear'
    }
    inc_bar_r = {
        'name': 'tv_pairs',
        'tv_pairs': inc_bar_traj_r,
        'kind': 'linear'
    }
    inc_bar_l = {
        'name': 'tv_pairs',
        'tv_pairs': inc_bar_traj_l,
        'kind': 'linear'
    }
    occluder_r = {
        'name': 'tv_pairs',
        'tv_pairs': occluder_traj_r,
        'kind': 'linear'
    }
    occluder_l = {
        'name': 'tv_pairs',
        'tv_pairs': occluder_traj_l,
        'kind': 'linear'
    }

    #####################################################
    # part 3: Start experiment
    #####################################################

    manager = launch_stim_server(
        Screen(fullscreen=False, server_number=0, id=0, vsync=False))
    manager.set_idle_background(background_color)

    # Loop through trials
    for t in range(n_trials):
        # begin trial

        if trial_structure[
                t] == "inc_r_inv":  # invisible, inconsistent_r. 00, 01, 10, 11
            bar_traj = inc_bar_r
            occ_traj = occluder_r
            occ_color = background_color
            stim_duration = inc_stim_duration
        elif trial_structure[
                t] == "con_r_inv":  # invisible, consistent_r. 00, 01, 10, 11
            bar_traj = con_bar_r
            occ_traj = occluder_r
            occ_color = background_color
            stim_duration = con_stim_duration
        elif trial_structure[
                t] == "inc_l_inv":  # invisible, inconsistent_l. 00, 01, 10, 11
            bar_traj = inc_bar_l
            occ_traj = occluder_l
            occ_color = background_color
            stim_duration = inc_stim_duration
        elif trial_structure[
                t] == "con_l_inv":  # invisible, consistent_l. 00, 01, 10, 11
            bar_traj = con_bar_l
            occ_traj = occluder_l
            occ_color = background_color
            stim_duration = con_stim_duration
        elif trial_structure[
                t] == "inc_r_vis":  # invisible, inconsistent_r. 00, 01, 10, 11
            bar_traj = inc_bar_r
            occ_traj = occluder_r
            occ_color = occluder_color
            stim_duration = inc_stim_duration
        elif trial_structure[
                t] == "con_r_vis":  # invisible, consistent_r. 00, 01, 10, 11
            bar_traj = con_bar_r
            occ_traj = occluder_r
            occ_color = occluder_color
            stim_duration = con_stim_duration
        elif trial_structure[
                t] == "inc_l_vis":  # invisible, inconsistent_l. 00, 01, 10, 11
            bar_traj = inc_bar_l
            occ_traj = occluder_l
            occ_color = occluder_color
            stim_duration = inc_stim_duration
        elif trial_structure[
                t] == "con_l_vis":  # invisible, consistent_l. 00, 01, 10, 11
            bar_traj = con_bar_l
            occ_traj = occluder_l
            occ_color = occluder_color
            stim_duration = con_stim_duration

        print(f"===== Trial {t}; type {trial_structure[t]} ======")

        manager.load_stim(
            name='ConstantBackground',
            color=[background_color, background_color, background_color, 1],
            side_length=200)

        # manager.load_stim(name='MovingPatch', width=bar_width, height=bar_height, sphere_radius=2, color=bar_color, theta=bar_traj, phi=0, hold=True)
        # manager.load_stim(name='MovingPatch', width=occluder_width, height=occluder_height, sphere_radius=1, color=occ_color, theta=occ_traj, phi=0, hold=True)
        manager.load_stim(name='MovingPatchOnCylinder',
                          width=bar_width,
                          height=bar_height,
                          cylinder_radius=2,
                          color=bar_color,
                          theta=bar_traj,
                          phi=0,
                          hold=True)
        manager.load_stim(name='MovingPatchOnCylinder',
                          width=occluder_width,
                          height=occluder_height,
                          cylinder_radius=1,
                          color=occ_color,
                          theta=occ_traj,
                          phi=0,
                          hold=True)

        manager.start_stim()
        sleep(stim_duration)

        manager.stop_stim(print_profile=False)

        print("===== Start ITI =====")
        sleep(iti)
        print("===== End ITI =====")