Exemplo n.º 1
0
    def get_mouse_state_durations(self, states=None, ret_states=False):
        """ returns the durations the mouse spends in each state 
        
        If a list of `states` is given, only these states are included in
            the result.
        If `ret_states` is True, the states that are considered are returned
            as a list
        """
        states, state_cat = self.get_mouse_state_vector(states,
                                                        ret_states=True)

        # get durations
        durations = collections.defaultdict(list)
        for state, start, end in contiguous_int_regions_iter(state_cat):
            durations[state].append(end - start)

        # convert to numpy arrays and add units
        durations = {
            states[key]: np.array(value) * self.time_scale
            for key, value in durations.iteritems()
        }

        if ret_states:
            return durations, states
        else:
            return durations
Exemplo n.º 2
0
 def write_mouse_state(self):
     """ write out the mouse state as a comma separated value file """
     mouse_state = self.data['pass2/mouse_trajectory'].states
     mouse_state_file = self.get_filename('mouse_state.csv', 'results')
     with open(mouse_state_file, 'w') as fp:
         csv_file = csv.writer(fp, delimiter=',')
         
         # write header
         header = ['%s (%s)' % (name, ', '.join(states))
                   for name, states in mouse.state_converter.get_categories()]
         header.append('Duration [sec]')
         csv_file.writerow(header)
         
         # write data
         frame_duration = 1/self.result['video/fps']
         for state, start, end in contiguous_int_regions_iter(mouse_state):
             data = [c for c in mouse.state_converter.int_to_symbols(state)]
             data.append(frame_duration * (end - start)) 
             csv_file.writerow(data)
Exemplo n.º 3
0
    def write_mouse_state(self):
        """ write out the mouse state as a comma separated value file """
        mouse_state = self.data['pass2/mouse_trajectory'].states
        mouse_state_file = self.get_filename('mouse_state.csv', 'results')
        with open(mouse_state_file, 'w') as fp:
            csv_file = csv.writer(fp, delimiter=',')

            # write header
            header = [
                '%s (%s)' % (name, ', '.join(states))
                for name, states in mouse.state_converter.get_categories()
            ]
            header.append('Duration [sec]')
            csv_file.writerow(header)

            # write data
            frame_duration = 1 / self.result['video/fps']
            for state, start, end in contiguous_int_regions_iter(mouse_state):
                data = [c for c in mouse.state_converter.int_to_symbols(state)]
                data.append(frame_duration * (end - start))
                csv_file.writerow(data)
Exemplo n.º 4
0
 def get_mouse_state_durations(self, states=None, ret_states=False):
     """ returns the durations the mouse spends in each state 
     
     If a list of `states` is given, only these states are included in
         the result.
     If `ret_states` is True, the states that are considered are returned
         as a list
     """
     states, state_cat = self.get_mouse_state_vector(states, ret_states=True)
         
     # get durations
     durations = collections.defaultdict(list)
     for state, start, end in contiguous_int_regions_iter(state_cat):
         durations[state].append(end - start)
         
     # convert to numpy arrays and add units
     durations = {states[key]: np.array(value) * self.time_scale
                  for key, value in durations.iteritems()}
         
     if ret_states:
         return durations, states
     else:
         return durations