Skip to content

Commit

Permalink
Add new example
Browse files Browse the repository at this point in the history
  • Loading branch information
ofgulban committed Feb 27, 2023
1 parent 88ba2f1 commit d2d5c11
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions wip/collate_vmp_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""Collate VMP files."""

import os
import bvbabel
import numpy as np
import pprint


FILES = [
"/path/to/sub-control01_run-01_facefix.vmp",
"/path/to/sub-control02_run-01_facefix.vmp",
]

SUFFIX = "collated_bvbabel"

# =============================================================================
for i in range(len(FILES)):
# Load main vmr
header_main, data_main = bvbabel.vmp.read_vmp(FILES[i])

# Add subject identifier to the map name
basename = FILES[i].split(os.extsep, 1)[0]
filename = basename.split(os.sep)[-1]
mapname_main = header_main["Map"][0]["MapName"]
header_main["Map"][0]["MapName"] = f"{filename}: {mapname_main}"

for j in range(len(FILES)):
if j == i:
pass
else:
# Load additional vmr
header_temp, data_temp = bvbabel.vmp.read_vmp(FILES[j])

# Add subject identifier to the map name
basename_temp = FILES[j].split(os.extsep, 1)[0]
filename_temp = basename_temp.split(os.sep)[-1]
mapname = header_temp["Map"][0]["MapName"]
header_temp["Map"][0]["MapName"] = f"{filename_temp}: {mapname}"

# Append new VMP map from another subject
header_main["NrOfSubMaps"] += 1
header_main["Map"].append(header_temp["Map"][0])
data_main = np.squeeze(np.stack([data_main, data_temp], axis=3))

# Write VMP
outname = f"{basename}_{SUFFIX}.vmp"
bvbabel.vmp.write_vmp(outname, header_main, data_main)

print("Finished.")

0 comments on commit d2d5c11

Please sign in to comment.