Esempio n. 1
0
    def __init__(self, session, TF_setup, TF_settings, clips_l):
        # set up class variables
        self.session = session

        # TF set up -- check if TF is running already
        self.TF_setup = TF_setup
        self.TF_settings = TF_settings
        self.clips_l = clips_l

        # Load settings from config
        self.cfg = load_yaml(track_options['cfg_std'])
        self.dlc_config_settings = load_yaml(track_options['cfg_dlc'])
        self.dlc_config_settings['clips'] = {
            'visual': {},
            'audio': {},
            'digital': {}
        }

        # params for contour extraction
        self.fps = self.session['Metadata'].videodata[0]['Frame rate'][0]
        self.background = self.session['Metadata'].videodata[0]['Background']
        self.arena_floor = False

        # params from showing tracing results in preview
        self.trace_length = 10
        self.magnif_factor = 2

        # params for data saving
        self.coord_l = []

        #### NOW TRACK ####
        try:
            self.main()
        except:
            warn('Something went wrong with tracking')
Esempio n. 2
0
def create_trial_metadata(trial_name, stim_type, start_frame, stop_frame, video_path):
    """ organise trial metadata """
    tr_metadata = {
        'Name': trial_name,
        'Stim type': stim_type,
        'Start frame': start_frame,
        'Stop frame': stop_frame,
        'Video path': video_path,
        'Created': datetime.datetime.now().strftime("%y-%m-%d-%H-%M"),
        'Last modified': datetime.datetime.now().strftime("%y-%m-%d-%H-%M"),
        'std tracking settings': load_yaml(track_options['cfg_std']),
        'dlc tracking settings': load_yaml(track_options['cfg_dlc'])
    }
    return tr_metadata
Esempio n. 3
0
    def __init__(self, session):
        print(colored('\n      Plotting whole session summary', 'green'))
        # Prep up useful variables
        self.colors = [[.2, .2, .2], [.8, .4, .4], [.4, .8, .4], [.4, .4, .8]]
        self.session = session
        self.settings = load_yaml(plotting_options['cfg'])

        # Create figure and set up axes
        self.set_up_fig()

        # Plot
        self.session_plot()

        # Save or display the figure
        if self.settings['save figs']:
            path = 'D:\\Dropbox (UCL - SWC)\\Dropbox (UCL - SWC)\\Rotation_vte\\data\\z_TrialImages'
            name = '{}'.format(self.session.name)
            print(
                colored('             ... saving figure {}'.format(name),
                        'grey'))
            self.f.savefig(os.path.join(path, name), facecolor=[0.3, 0.3, 0.3])
            if send_messages:
                send_email_attachments(name, os.path.join(path, name))
            plt.close('all')
        else:
            plt.show()
Esempio n. 4
0
    def __init__(self, session):
        print(colored('\n       Plotting single trials summaries', 'green'))

        plt.ion()
        if not session is None:
            # Get a number of useful flags
            plotting_settings = load_yaml(plotting_options['cfg'])
            self.exploration_maxmin = plotting_settings['exploration max length']
            self.plot_pose = plotting_settings['plot pose']
            self.save_figs = plotting_settings['save figs']

            self.session = session

            # Define stuff used for extracting data
            self.sel_trial = 0
            self.prestim_frames = 5
            self.poststim_frames = 180

            # Define stuff used for plotting
            self.colors = {
                'Rear': [0.4, 0.8, 0.4],
                'Lear': [0.4, 0.8, 0.4],
                'snout': [0.5, 0.6, 0.5],
                'neck': [0.6, 0.4, 0.4],
                'body': [0.8, 0.3, 0.3],
                'tail': [0.4, 0.4, 0.8],
            }

            # Get trials data and start main() which takes care of plotting each trial
            self.get_trials_metadata()
            self.main()
Esempio n. 5
0
    def plotting_session(self, session):
        plotting_settings = load_yaml(plotting_options['cfg'])

        Single_trial_summary.Plotter(session)

        if plotting_settings['plot exp specific'] and exp_type == 'maze':
            from Plotting import Maze_session_summary
            Maze_session_summary.MazeSessionPlotter(session)
Esempio n. 6
0
def dlc_setupTF(options):
    dlc_config_settings = load_yaml(options['cfg_dlc'])
    cfg = load_config(dlc_config_settings['dlc_network_posecfg'])
    cfg['init_weights'] = dlc_config_settings['dlc_network_snapshot']
    scorer = dlc_config_settings['scorer']
    sess, inputs, outputs = predict.setup_pose_prediction(cfg)

    return {'scorer': scorer, 'sess': sess, 'inputs': inputs, 'outputs': outputs, 'cfg': cfg}
Esempio n. 7
0
    def __init__(self, session, database):
        print(colored('        processing...', 'green'))

        # load processing settings from yaml file
        self.settings = load_yaml(processing_options['cfg'])

        self.session = session
        self.database = database

        # Process tracking data
        for data_name, tracking_data in sorted(list(self.session.Tracking.items())):
            try:
                if data_name == 'Exploration' or data_name == 'Whole Session':
                    print(colored('          processing currently only supports processing of trial data, not {}'.format(
                        data_name), 'yellow'))
                    continue

                print(colored('        Trial {}'.format(data_name), 'green'))
                self.tracking_data = tracking_data

                # Save info about processing options in the metadata
                self.define_processing_metadata()
                # Apply processes in parallel
                # TODO use decorator to make sure that functions are automatically added to the list, avoid bugs
                funcs = [self.extract_bodylength, self.extract_velocity, self.extract_location_relative_shelter,
                          self.extract_orientation]
                pool = ThreadPool(len(funcs))
                [pool.apply(func) for func in funcs]

                # Other processing steps will not be done in parallel
                self.extract_ang_velocity()
                # PoseReconstructor(self.tracking_data.dlc_tracking['Posture'])  # WORK IN PROGRESS, buggy

            except:
                warnings.warn('Could not analyse this trial!!!')  # but avoid crashing the whole analysis
                print(colored('          trial {} could not be processed!'.format(data_name), 'yellow'))
                slack_chat_messenger('Could not process trial {}'.format(data_name))

        # Call experiment specific processing tools [only implemented for maze experiments]
        if self.settings['apply exp-specific']:
            ProcessingTrialsMaze(self.session, debugging=self.settings['debug exp-specific'])
            ProcessingSessionMaze(self.session)

        else:
            from warnings import warn
            warn('Experiment type {} is not supported yet'.format(exp_type))
Esempio n. 8
0
    def tracking_use_dlc(database, clips_l):
        print(
            '====================================\nExtracting Pose using DeepLabCut'
        )

        dlc_config_settings = load_yaml(track_options['cfg_dlc'])

        print('        ... extracting pose from clips')
        TF_settings = dlc_setupTF(track_options)
        dlc_analyseVideos.analyse(TF_settings,
                                  dlc_config_settings['clips_folder'], clips_l)

        print('        ... integrating results in database')
        database = dlc_retreive_data(dlc_config_settings['clips_folder'],
                                     database, clips_l)

        print('        ... cleaning up')
        if not dlc_config_settings['store trial videos']:
            dlc_clear_folder(dlc_config_settings['clips_folder'],
                             dlc_config_settings['store trial videos'])

        return database