Run track2p programatically

Run track2p programatically#

Track2p can also be easily launched through a notebook or a script as shown below

from track2p.t2p import run_t2p                     # main function that launches track2p
from track2p.ops.default import DefaultTrackOps     # default track2p options

# load default settings / parameters
track_ops = DefaultTrackOps()

After importing the algorithm function and initialising default parameters, we can set the paths and modify parameters as shown below (Note: the parameters follow the same naming convention as in the ‘Run algorithm’ window of the GUI):

# overwrite some defaults
track_ops.all_ds_path = [           # list of paths to datasets containing a `suite2p` folder
            '/Users/jure/Documents/cossart_lab/data/jm/jm038/2023-04-30_a',
            '/Users/jure/Documents/cossart_lab/data/jm/jm038/2023-05-01_a',
            '/Users/jure/Documents/cossart_lab/data/jm/jm038/2023-05-02_a',
            '/Users/jure/Documents/cossart_lab/data/jm/jm038/2023-05-03_a',
            '/Users/jure/Documents/cossart_lab/data/jm/jm038/2023-05-04_a',
            '/Users/jure/Documents/cossart_lab/data/jm/jm038/2023-05-05_a',
            '/Users/jure/Documents/cossart_lab/data/jm/jm038/2023-05-06_a'
        ]

track_ops.save_path = '/Users/jure/Documents/cossart_lab/data/jm/jm038/'    # path where to save the outputs of algorithm 
                                                                            # (a 'track2p' folder will be created where figures for
                                                                            # visualisation and matrices of matches would be saved)

track_ops.reg_chan = 1              # channel to use for registration (0=functional, 1=anatomical) (use 0 if only recording gcamp!)
track_ops.iscell_thr = 0.5          # threshold for iscell (0.5 is a good value)

Before running algorithm we can also check the settings track2p will use, to be sure everything is correct:

# print all the settings / parameters used for running the algorithm
for attr, value in track_ops.__dict__.items():
    print(attr, '=', value)

We can then simply launch the algorithm by passing the track_ops object to the run_t2p function.

# run the algorithm
run_t2p(track_ops)