Utilities/video_and_plotting/make_trials_clips.py
def loop_over_recordings(self, skip_every=None):
        """[ Loop over all recordings in table, see which one needs processing and extract the corresponding stimuli,
        file paths and metadata]
        
        Raises:
            NotImplementedError: [Doesnt work for behaviour software]
            NotImplementedError: [doesnt work for visual stims]
        """
        r = namedtuple("r", "recording_uid uid session_name software ai_file_path")

        for recn, recuid in enumerate(sorted(set(self.data.fetch("recording_uid")))):
            if skip_every is not None:
                if not recn % skip_every == 0: continue

            self.restore_settings()
            
            _rec = (Recording & "recording_uid='{}'".format(recuid)).fetch1()
            rec = r(*_rec.values())

            del _rec['software']
            del _rec["ai_file_path"]

            # Check if needs to be processed
            if self.process_recs_in_range is not None:
                if rec.uid < self.process_recs_in_range[0] or rec.uid > self.process_recs_in_range[1]: continue
            print("Processing recording: ", rec.recording_uid)

            # Check if a video for this record exists already
            self.video_savepath = os.path.join(self.save_folder, rec.recording_uid + "_all_trials.mp4")
            if os.path.isfile(self.video_savepath): #? check that a video doesn't already exists. if it does but its empty overwrite it
                if os.path.getsize(self.video_savepath) > 10000: continue

            # Get the stimuli for this recording
            if rec.software == 'behaviour':
                continue
            else:
                self.stimuli = pd.DataFrame((self.data & _rec).fetch())

            if len(self.stimuli) == 0:
                warnings.warn("no stimuli found for {}".format(rec.recording_uid))
                continue

            if "video" in self.stimuli.stim_type or "visual" in self.stimuli.stim_type: 
                warnings.warn("Not implement for visual stimuli ??")
                continue

            # Get videopath for this recording
            self.rec_paths = pd.DataFrame(Recording.FilePaths & _rec)

            # Get the aligned overview and threat frames if they exist
            self.aligned_frame_times = pd.DataFrame(Recording.AlignedFrames & _rec)

            # # if there is no info about the aligned frame times we cannot add the threat video
            if not len(self.aligned_frame_times) and self.add_threat_video:
                warnings.warn("\n   cannot add threat video if the frames haven't been aligned, populate FrameTimes")
                self.add_threat_video = False

            # get tracking data 
            if self.overlay_pose:
                self.overview_tracking = (TrackingData & _rec).fetch()
                if not len(self.overview_tracking): 
                    warnings.warn("\n Could not find tracking data for this recording")
                    self.overlay_pose = False

                elif self.add_threat_video:
                    self.threat_tracking = get_tracking_given_recuid(rec.recording_uid, cam="threat")
                    if not len(self.threat_tracking): self.threat_tracking = None
                    # TODO need to create and fill a tracking data table for the threa vids first

            # Set up to write this recording's clip
            ret = self.setup_clip_writing()
            if ret:
                self.prep_circles()
                self.create_clip()
[ Loop over all recordings in table, see which one needs processing and extract the corresponding stimuli,
        file paths and metadata]
        
        Raises:
            NotImplementedError: [Doesnt work for behaviour software]
            NotImplementedError: [doesnt work for visual stims]
        
[ Loop over all recordings in table, see which one needs processing and extract the corresponding stimuli,
file paths and metadata]
[ Loop over all recordings in table see which one needs processing and extract the corresponding stimuli file paths and metadata ]
def loop_over_recordings(self, skip_every=None):
        r = namedtuple("r", "recording_uid uid session_name software ai_file_path")
        for recn, recuid in enumerate(sorted(set(self.data.fetch("recording_uid")))):
            if skip_every is not None:
                if not recn % skip_every == 0: continue
            self.restore_settings()
            _rec = (Recording & "recording_uid='{}'".format(recuid)).fetch1()
            rec = r(*_rec.values())
            del _rec['software']
            del _rec["ai_file_path"]
            if self.process_recs_in_range is not None:
                if rec.uid < self.process_recs_in_range[0] or rec.uid > self.process_recs_in_range[1]: continue
            print("Processing recording: ", rec.recording_uid)
            self.video_savepath = os.path.join(self.save_folder, rec.recording_uid + "_all_trials.mp4")
            if os.path.isfile(self.video_savepath): 
                if os.path.getsize(self.video_savepath) > 10000: continue
            if rec.software == 'behaviour':
                continue
            else:
                self.stimuli = pd.DataFrame((self.data & _rec).fetch())
            if len(self.stimuli) == 0:
                warnings.warn("no stimuli found for {}".format(rec.recording_uid))
                continue
            if "video" in self.stimuli.stim_type or "visual" in self.stimuli.stim_type: 
                warnings.warn("Not implement for visual stimuli ??")
                continue
            self.rec_paths = pd.DataFrame(Recording.FilePaths & _rec)
            self.aligned_frame_times = pd.DataFrame(Recording.AlignedFrames & _rec)
            if not len(self.aligned_frame_times) and self.add_threat_video:
                warnings.warn("\n   cannot add threat video if the frames haven't been aligned, populate FrameTimes")
                self.add_threat_video = False
            if self.overlay_pose:
                self.overview_tracking = (TrackingData & _rec).fetch()
                if not len(self.overview_tracking): 
                    warnings.warn("\n Could not find tracking data for this recording")
                    self.overlay_pose = False
                elif self.add_threat_video:
                    self.threat_tracking = get_tracking_given_recuid(rec.recording_uid, cam="threat")
                    if not len(self.threat_tracking): self.threat_tracking = None
            ret = self.setup_clip_writing()
            if ret:
                self.prep_circles()
                self.create_clip()
def loop_over_recordings ( self , skip_every = None ) : r = namedtuple ( "r" , "recording_uid uid session_name software ai_file_path" ) for recn , recuid in enumerate ( sorted ( set ( self . data . fetch ( "recording_uid" ) ) ) ) : if skip_every is not None : if not recn % skip_every == 0 : continue self . restore_settings ( ) _rec = ( Recording & "recording_uid='{}'" . format ( recuid ) ) . fetch1 ( ) rec = r ( * _rec . values ( ) ) del _rec [ 'software' ] del _rec [ "ai_file_path" ] if self . process_recs_in_range is not None : if rec . uid < self . process_recs_in_range [ 0 ] or rec . uid > self . process_recs_in_range [ 1 ] : continue print ( "Processing recording: " , rec . recording_uid ) self . video_savepath = os . path . join ( self . save_folder , rec . recording_uid + "_all_trials.mp4" ) if os . path . isfile ( self . video_savepath ) : if os . path . getsize ( self . video_savepath ) > 10000 : continue if rec . software == 'behaviour' : continue else : self . stimuli = pd . DataFrame ( ( self . data & _rec ) . fetch ( ) ) if len ( self . stimuli ) == 0 : warnings . warn ( "no stimuli found for {}" . format ( rec . recording_uid ) ) continue if "video" in self . stimuli . stim_type or "visual" in self . stimuli . stim_type : warnings . warn ( "Not implement for visual stimuli ??" ) continue self . rec_paths = pd . DataFrame ( Recording . FilePaths & _rec ) self . aligned_frame_times = pd . DataFrame ( Recording . AlignedFrames & _rec ) if not len ( self . aligned_frame_times ) and self . add_threat_video : warnings . warn ( "\n   cannot add threat video if the frames haven't been aligned, populate FrameTimes" ) self . add_threat_video = False if self . overlay_pose : self . overview_tracking = ( TrackingData & _rec ) . fetch ( ) if not len ( self . overview_tracking ) : warnings . warn ( "\n Could not find tracking data for this recording" ) self . overlay_pose = False elif self . add_threat_video : self . threat_tracking = get_tracking_given_recuid ( rec . recording_uid , cam = "threat" ) if not len ( self . threat_tracking ) : self . threat_tracking = None ret = self . setup_clip_writing ( ) if ret : self . prep_circles ( ) self . create_clip ( )
[ Loop over all recordings in table, see which one needs processing and extract the corresponding stimuli,
file paths and metadata]
[ Loop over all recordings in table see which one needs processing and extract the corresponding stimuli file paths and metadata ]
"""[ Loop over all recordings in table, see which one needs processing and extract the corresponding stimuli,
        file paths and metadata]
        
        Raises:
            NotImplementedError: [Doesnt work for behaviour software]
            NotImplementedError: [doesnt work for visual stims]
        """ # Check if needs to be processed # Check if a video for this record exists already #? check that a video doesn't already exists. if it does but its empty overwrite it # Get the stimuli for this recording # Get videopath for this recording # Get the aligned overview and threat frames if they exist # # if there is no info about the aligned frame times we cannot add the threat video # get tracking data  # TODO need to create and fill a tracking data table for the threa vids first # Set up to write this recording's clip
[Doesnt work for behaviour software]
[ Doesnt work for behaviour software ]
NotImplementedError
[doesnt work for visual stims]
[ doesnt work for visual stims ]
NotImplementedError
self
skip_every