def write_to_fsee_old(npmovie, name='fsee_data'): def rotz(theta): ''' Returns a 3x3 rotation matrix corresponding to rotation around the *z* axis. ''' return np.array([ [ np.cos(theta), -np.sin(theta), 0], [ np.sin(theta), np.cos(theta), 0], [0, 0, 1]]) frames = smp.get_active_frames(npmovie) positions = [] attitudes = [] states = {} flydra_coordinates_longaxis = smp.sa1_to_flydra_img_transform(npmovie.kalmanobj.long_axis[frames], fix_sign=False)*-1 sa1_theta = np.arctan2(flydra_coordinates_longaxis[:,1], flydra_coordinates_longaxis[:,0]) #sa1_theta = np.arctan2(npmovie.kalmanobj.long_axis[:,0], npmovie.kalmanobj.long_axis[:,1])[frames] sa1_time = npmovie.timestamps[frames] flydra_theta, flydra_time = smp.interp_sa1_data_to_flydra(npmovie, sa1_theta, sa1_time, return_time=True) for i in range(len(flydra_theta)): flydra_frame = i + npmovie.sa1_start_index positions.append( npmovie.trajec.positions[flydra_frame,:] ) print i, flydra_frame, npmovie.trajec.positions[flydra_frame,:] theta = flydra_theta[i] attitudes.append( rotz(theta) ) states.setdefault('positions', positions) states.setdefault('attitudes', attitudes) save(states, name) return 1
def write_to_fsee(npmovie, name='fsee_data'): def rotz(theta): ''' Returns a 3x3 rotation matrix corresponding to rotation around the *z* axis. ''' return np.array([ [ np.cos(theta), -np.sin(theta), 0], [ np.sin(theta), np.cos(theta), 0], [0, 0, 1]]) frames = smp.get_active_frames(npmovie) positions = [] attitudes = [] states = {} for i in range(len(npmovie.sync2d3d.pos2d)): positions.append( npmovie.sync2d3d.pos3d_est[i,:] ) print npmovie.sync2d3d.yaw[i] attitudes.append( rotz(npmovie.sync2d3d.yaw[i]) ) states.setdefault('positions', positions) states.setdefault('attitudes', attitudes) save(states, name) return 1
def process_movie(MOVIE_ID, movie_info=None, dataset=None): if movie_info is None: filename = '/home/floris/data/windtunnel/SA1/movie_info' fname = (filename) fd = open( fname, mode='r' ) movie_info = pickle.load(fd) fd.close() movie_filename = movie_info[MOVIE_ID]['Path'] + MOVIE_ID + '.avi' print 'loading: ', movie_filename movie = pm.Movie(movie_filename) npmovie = pm.npMovie() npmovie.objid = movie_info[MOVIE_ID]['Obj_ID'] npmovie.epochtime = movie_info[MOVIE_ID]['EpochTime'] npmovie.filename = MOVIE_ID npmovie.id = MOVIE_ID npmovie.behavior = movie_info[MOVIE_ID]['Behavior'] npmovie.path = movie_info[MOVIE_ID]['Path'] npmovie.posttype = movie_info[MOVIE_ID]['PostType'] npmovie.extras = movie_info[MOVIE_ID]['Extras'] npmovie.trigger_stamp = movie_info[MOVIE_ID]['Trigger Stamp'] npmovie.timestamps = movie_info[MOVIE_ID]['Timestamps'] # make a mask mask = np.ones([movie.height, movie.width]) mask[0:movie.height-movie.width, :] = 0 movie.mask = mask # make a tracking mask -- 0 where no tracking desired tracking_mask = np.abs(nim.plot_circle(1024,1024,[512,512], 150)-1) npmovie.tracking_mask = tracking_mask npmovie.calc_background(movie) npmovie.load_frames(movie, timerange=None) npmovie.fps = 5000. npmovie.obj = pm.Object(npmovie) pm.auto_adjust_uimg(npmovie) pm.segment_fly(npmovie) frames = smp.get_active_frames(npmovie) if len(frames) < 5: del(movie) return npmovie pm.calc_obj_pos(npmovie) pm.calc_obj_motion(npmovie) pm.smooth_legs(npmovie) pm.calc_polarpos(npmovie) pm.smooth_axis_ratio(npmovie) trajec, time_err = sa1a.get_flydra_trajectory(npmovie, dataset) print 'trajectory in process_movie: ', trajec npmovie.trajec = copy.copy(trajec) clas.calc_fly_coordinates(npmovie) smp.calc_frame_of_landing(npmovie) if trajec is not None: smp.sync_2d_3d_data(npmovie) if len(npmovie.sync2d3d.frames3d) > 2: smp.calc_body_orientations(npmovie) smp.calc_smoothyaw(npmovie, plot=False) else: npmovie.sync2d3d = None npmovie.cluster = None #strobe_img = pm.strobe_image(movie) #movie_info[MOVIE_ID].setdefault('StrobeImg', strobe_img) #npmovie_filename = '/home/floris/data/windtunnel/SA1/sa1_npmovie_' + MOVIE_ID #pm.save(npmovie, npmovie_filename) del(movie) return npmovie