import re from pathlib import Path import pandas as pd import videobatch # for extraction of ROI names from files ROI_PATTERN = re.compile(r"_([a-zA-Z]+)\.png") # base spec, used in videobatch base_spec = { "command": "pixylation", "mode": "CM", "colors": dict(Magenta=[260,360], Green=[90,225]), "sources": ["*.mp4"] } # the root repository dir rootdir = Path().resolve().parent # dataset dirs rawdir = rootdir / "datasets" / "raw" trkdir = rootdir / "datasets" / "tracking" # read info from SESSIONS sessions = pd.read_csv(str(rootdir / "SESSIONS.csv")) # iterate over sessions for rowidx in range(sessions.shape[0]): session = sessions.iloc[rowidx] sname = f"session{session.date}-{session.index:03d}" # source video directory srcdir = rawdir / session.subject / sname / "video" # read ROI info roidir = trkdir / session.subject / sname / "ROI" # may not be in the repository ROIs = {} for child in roidir.iterdir(): is_ROIfile = ROI_PATTERN.search(child.name) if not is_ROIfile: continue else: ROIname = is_ROIfile.group(1) ROIs[ROIname] = str(child) # output directories resultdir = trkdir / session.subject / sname / "tracked" maskdir = trkdir / session.subject / sname / "mask" # not in the repository # configure specs spec = base_spec.copy() spec['sourcedir'] = str(srcdir) spec['Rois'] = ROIs spec['resultdir'] = str(resultdir) spec['maskdir'] = str(maskdir) # run videobatch for this session videobatch.run(spec)