Beispiel #1
0
def CLIPS_start_to_end_trial(sessions_subset):
    
    try:  
        
        for session in sessions_subset:
            
            start_idx = []
            end_idx = []
            
            #create folder to allocate the clips             
            script_dir = os.path.join(hardrive_path + session) 
            csv_dir_path = os.path.join(hardrive_path, session + '/events/')
            results_dir = os.path.join(script_dir +'/Clips')
            csv_path = 'Trial_idx.csv'

            if not os.path.isdir(results_dir):
                os.makedirs(results_dir)

            
        
            trial_end_path = os.path.join(hardrive_path, session + '/events/' + 'TrialEnd.csv')
            trial_start_path = os.path.join(hardrive_path, session + '/events/' + 'TrialStart.csv')
            video_csv_path = os.path.join(hardrive_path, session + '/Video.csv')
            video_path = os.path.join(hardrive_path, session + '/Video.avi')
            
            
            start = behaviour.timestamp_CSV_to_pandas(trial_start_path)
            end = behaviour.timestamp_CSV_to_pandas(trial_end_path)
            video_time = behaviour.timestamp_CSV_to_pandas(video_csv_path)
            
            
            start_closest = behaviour.closest_timestamps_to_events(video_time, start)
            end_closest = behaviour.closest_timestamps_to_events(video_time, end)
            
            if len(start_closest)>len(end_closest):
                start_closest = start_closest[:-1]
            
            start_idx.append(start_closest)
            end_idx.append(end_closest)
            
            
            np.savetxt(csv_dir_path + csv_path , np.vstack((start_idx,end_idx)).T,delimiter=',', fmt='%s')
            #video stuff
                        
            inputVid = cv2.VideoCapture(video_path)
            inputWidth = int(inputVid.get(cv2.CAP_PROP_FRAME_WIDTH))
            inputHeight  =  int(inputVid.get(cv2.CAP_PROP_FRAME_HEIGHT))

            # Open Output movie file, then specify compression, frames per second and size
            fourcc = cv2.VideoWriter_fourcc('F','M','P','4')
            fps = 120
            offset = 360 #3''
            # Specify clip parameters
            startFrame = np.array(start_closest) - offset
            endFrame = np.array(end_closest) + offset
            numFrames =  endFrame - startFrame


            # Set starting read position
            start = 0
            for e in range(len(numFrames[:])):
    
                start_frame = start + e
                inputVid.set(cv2.CAP_PROP_POS_FRAMES, startFrame[start_frame])
                if e < 10:
                    outputFilename= results_dir +'/Clip0%d.avi' %start_frame
                    outputVid = cv2.VideoWriter(outputFilename, fourcc, fps, (inputWidth, inputHeight))
                else:
                    outputFilename= results_dir +'/Clip%d.avi' %start_frame
                    outputVid = cv2.VideoWriter(outputFilename, fourcc, fps, (inputWidth, inputHeight))
                for i in range(numFrames[start_frame]):
                    ret, im = inputVid.read()
                    outputVid.write(im)
                print (i)
                outputVid.release()
             
        inputVid.release()
            
    except Exception: 
            print('error'+ session)
            pass   
Beispiel #2
0
        mua_z_score[r,c,:] = (mua[r,c,:] - mua_median[r,c]) / mua_std[r,c]

# Plot z-score avg
mua_avg = np.mean(mua_z_score, 2)

# Get events of intererest indices
touch_path = os.path.join(session_path +  '/events/RatTouchBall.csv')
reward_path = os.path.join(session_path +  '/events/TrialEnd.csv')
ball_on_path = os.path.join(session_path +  '/events/BallOn.csv')
video_csv = os.path.join(session_path + '/Video.csv')
trial_start_path = os.path.join(session_path +  '/events/TrialStart.csv')




video_time = behaviour.timestamp_CSV_to_pandas(video_csv)
touch_time = behaviour.timestamp_CSV_to_pandas(touch_path)
reward_time = behaviour.timestamp_CSV_to_pandas(reward_path)
ball_time = behaviour.timestamp_CSV_to_pandas(ball_on_path)
trial_time = behaviour.timestamp_CSV_to_pandas(trial_start_path)




touching_light = behaviour.closest_timestamps_to_events(video_time, touch_time)
reward = behaviour.closest_timestamps_to_events(video_time, reward_time)
ball_on = behaviour.closest_timestamps_to_events(video_time, ball_time)
start = behaviour.closest_timestamps_to_events(video_time, trial_time)

events_list = [touching_light,reward]#ball_noticed]
Beispiel #3
0
import os
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
#os.sys.path.append('/home/kampff/Repos/Pac-Rat/libraries')
os.sys.path.append('D:/Repos/Pac-Rat/libraries')
import behaviour_library as behaviour

motion_stimulus_path = 'F:/Videogame_Assay/AK_33.2/2018_04_06-15_13/motions.csv'
motion_stimulus = np.genfromtxt(motion_stimulus_path, delimiter=',', usecols=1)

video_path = 'F:/Videogame_Assay/AK_33.2/2018_04_06-15_13/Video.csv'
ball_path = 'F:/Videogame_Assay/AK_33.2/2018_04_06-15_13/events/BallOn.csv'
touch_path = 'F:/Videogame_Assay/AK_33.2/2018_04_06-15_13/events/RatTouchBall.csv'

video = behaviour.timestamp_CSV_to_pandas(video_path)
ball = behaviour.timestamp_CSV_to_pandas(ball_path)
touch = behaviour.timestamp_CSV_to_pandas(touch_path)

ball_idx = behaviour.closest_timestamps_to_events(video, ball)
touch_idx = behaviour.closest_timestamps_to_events(video, touch)
# stimulus

events_list = [touch_idx, ball_idx]

event = events_list[0]
#extract motion chunk around ball on

before = 0
after = 60