示例#1
0
def go_initialize_stimulus(stimulus_xml, optics, extra):
    """ returns fsee.Observer.Observer """
    try:
        # stimulus_xml can be a filename
        if stimulus_xml[0] == "/":
            pass
        else:
            # otherwise it's a string
            # pass it like a string
            stimulus_xml = StringIO(stimulus_xml)

        stim_xml = xml_stimulus.xml_stimulus_from_filename(stimulus_xml)
        stim_xml_osg = xml_stimulus_osg.StimulusWithOSG(stim_xml.get_root())

        with stim_xml_osg.OSG_model_path(extra=extra) as osg_model_path:
            # sys.stderr.write('osg_model_path = \n %s' % open(osg_model_path).read())
            hz = 60.0  # fps

            vision = fsee.Observer.Observer(
                model_path=osg_model_path,
                # scale=1000.0, # from meters to mm
                hz=hz,
                skybox_basename=None,
                full_spectrum=True,
                optics=optics,
                do_luminance_adaptation=False,
            )

            positive_answer({}, ("Model loaded, path = %s" % osg_model_path))
            return vision

    except IOError, ex:
        exit_with_error("Could not load file %s: %s" % (stimulus_xml, ex))
示例#2
0
    def __init__(self, stim_xml_filename=None, num_points=5, scale_factor=0.01, ghost_length=20, resolution=4):

        # initialize the viewer window
        self.f = mlab.figure(size=(800, 600))
        self.f.scene.anti_aliasing_frames = 1
        visual.set_viewer(self.f)

        ################# moving fly objects ################
        self.num_points = num_points
        self.plot_objects = [
            Object(ghost_length=ghost_length, scale_factor=scale_factor, resolution=resolution)
            for i in range(self.num_points)
        ]
        ######################################################

        self.objects = None
        self.speed = np.zeros(self.num_points)

        ################### stimulus xml #####################
        if stim_xml_filename is not None:
            actors = []
            stim_xml = xml_stimulus.xml_stimulus_from_filename(stim_xml_filename)
            actors.extend(stim_xml.get_tvtk_actors())
            for a in actors:
                visual.show_actor(a)
        ######################################################

        # ROS stuff
        rospy.Subscriber("flydra_mainbrain_super_packets", flydra_mainbrain_super_packet, self.callback)
        rospy.init_node("listener", anonymous=True)

        # run the animation
        self.animate()
示例#3
0
def main():
    # Generate OSG model from the XML file
    stim_xml_filename = 'nopost.xml'
    stim_xml = xml_stimulus.xml_stimulus_from_filename(stim_xml_filename)
    stim_xml_osg = xml_stimulus_osg.StimulusWithOSG( stim_xml.get_root() )

    # Simulation parameters
    hz = 60.0 # fps
    dt = 1.0/hz

    # Use to generate pose and velocities
    path_maker = PathMaker(vel_0=cgtypes.vec3(0.100,0,0),
                           pos_0=cgtypes.vec3(0.000,0.000,0.150))


    with stim_xml_osg.OSG_model_path() as osg_model_path:
        vision = fsee.Observer.Observer(model_path=osg_model_path,
                                        # scale=1000.0, # from meters to mm
                                        hz=hz,
                                        skybox_basename=None,
                                        full_spectrum=True,
                                        optics='buchner71',
                                        do_luminance_adaptation=False,
                                        )
        t = -dt 
        count = 0
        y_old = None
        cur_pos = None
        cur_ori = None
 
        while count < 1000:
            t += dt
            count += 1

            cur_pos, cur_ori, vel, angular_vel = path_maker.step(t)
            print cur_pos

            vision.step(cur_pos,cur_ori)

            R=vision.get_last_retinal_imageR()
            G=vision.get_last_retinal_imageG()
            B=vision.get_last_retinal_imageB()
            y = (R+G+B)/3.0/255
            
            if y_old != None:
                ydot = (y - y_old) / dt
            else:
                y_old = y
                    
            # Get Q_dot and mu from body velocities
            # WARNING: Getting Q_dot and mu can be very slow
            qdot, mu = vision.get_last_retinal_velocities(vel, angular_vel)
示例#4
0
def get_posts_info(xml):
    from flydra.a2 import xml_stimulus #@UnresolvedImport
    stimulus_xml = StringIO(xml)
    stim_xml = xml_stimulus.xml_stimulus_from_filename(stimulus_xml)
    root = stim_xml.get_root()
    
    results = {'posts':[]}
    for child in root:
        if child.tag == 'cylindrical_post':
            info = stim_xml._get_info_for_cylindrical_post(child)
            results['posts'].append(info)
        elif child.tag == 'cylindrical_arena':
            results['arena'] = stim_xml._get_info_for_cylindrical_arena(child)

    return results