I kinda figured it out a while ago. I ended up using nibabel and numpy in python to average the surfaces across subjects. Hopefully this function helps someone out later.
After using this function, I used SurfStat to project the averaged files onto a fsaverage surface
import nibabel as nib
import numpy as np
def average_mgh_files(input_files, output_file):
# Read the first file to initialize the sum and get the affine
first_img = nib.load(input_files[0])
sum_data = first_img.get_fdata().astype(np.float32) # Ensure data is float32
affine = first_img.affine
# Iterate over the rest of the files and accumulate the sum
for file in input_files[1:]:
img = nib.load(file)
sum_data += img.get_fdata().astype(np.float32) # Ensure data is float32
# Calculate the average
avg_data = sum_data / len(input_files)
# Convert the average data to a recognized data type, here using float32
avg_data = avg_data.astype(np.float32)
# Save the result to a new .mgh file
avg_img = nib.MGHImage(avg_data, affine)
nib.save(avg_img, output_file)
rh_input_files = ['ses-1_trc-18FAV45_pet_space-fsaverage_suvr-cerebellumPons_pvc-iy_hemi-rh_fwhm-5_projection.mgh', ...]
# include list of right hemisphere files for every subject, then do the same for left hemisphere
average_mgh_files(rh_input_files, 'rh_average.mgh')