forked from DiedrichsenLab/surfAnalysisPy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmoothSurface.py
52 lines (37 loc) · 1.41 KB
/
smoothSurface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 21 21:32:02 2019
Smooth metric files
INPUT:
fileList: Text file of full paths to metric files
VARARGIN
surfaceFile: Full path to surface file on which to smooth
DEFAULT: empty
kernelSigma: Sigma (in mm) for gaussian kernel function
DEFAULT: 2.0
filePrefix Prefix for smoothed filenames (string)
DEFAULT: 'smooth'
OUTPUT:
Default algorithm (GEO_GAUSS_AREA) used, no other methods implemented or supported.
More information: https://www.humanconnectome.org/software/workbench-command/-metric-smoothing
@author: EBerlot 2019/05 (Python conversion: switt)
"""
import os
import sys
import numpy as np
import nibabel as nb
def smoothSurface(fileList,surfaceFile=[],kernelSigma=2.0,filePrefix='smooth'):
if not fileList:
sys.exit('Error: No fileList of .func.gii files provided.')
if not surfaceFile:
sys.exit('Error: No surfaceFile provided.')
with open(fileList, 'r') as f:
funcFileList = f.read()
funcFileList = funcFileList.split()
numFiles = len(funcFileList)
smoothedFileList = list()
for i in range(numFiles):
funcFilePath = os.path.split(funcFileList[i])
smoothedFileList.append(os.path.join(funcFilePath[0],'_'.join((filePrefix,funcFilePath[1]))))
subprocess.run(["wb_command","-metric-smoothing",surfaceFile,funcFileList[i],kernelSigma,smoothedFileList[i]])