-
Notifications
You must be signed in to change notification settings - Fork 0
/
bxh.py
executable file
·54 lines (45 loc) · 1.95 KB
/
bxh.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
52
53
54
#!/usr/bin/env python
import subprocess
import directory
import sys
import shutil
import my_logger as l
import config
WRAP_NAME = 'WRAPPED.bxh'
ANALYSIS_FOLDER = 'ANALYSIS'
SLICE_ROOT = 'QA_z'
def wrapEPIdata(dataDir,outputDir):
rl = l.RuntimeLogger(outputDir)
dataFolder = directory.getNameFromPath(dataDir)
rl.info(dataDir)
# The relative output path is used to get absolute paths in the output
command = 'dicom2bxh --xcede * ..'+ directory.SEP + dataFolder + directory.SEP + WRAP_NAME
# command = 'dicom2bxh --xcede *.' + config.DATA_EXT + ' ..' + directory.SEP + dataFolder + directory.SEP + WRAP_NAME
rl.info('To execute: '+command)
p = subprocess.Popen(command, cwd=dataDir, shell=True)
p.communicate() # this causes the script to wait until dicom2bxh is finished
rl.info('Done: ' + command)
primaryPath = directory.joinPath([dataDir, WRAP_NAME])
outputPath = directory.joinPath([outputDir, WRAP_NAME])
try:
shutil.move(primaryPath, outputPath)
except:
e_text = 'Error: moving ' + WRAP_NAME + ' to ' + outputPath + '!! Check what went wrong!!'
print e_text
rl.error(e_text)
sys.exit(1)
def fmriQaAnalysis(workingDir,sliceNumber):
rl = l.RuntimeLogger(workingDir)
sliceFolder = directory.joinPath([workingDir, SLICE_ROOT])
command = ['fmriqa_phantomqa.pl', '--zselect', str(sliceNumber), ' WRAPPED.bxh', sliceFolder + str(sliceNumber)]
command = ' '.join(command)
rl.info('To execute: ' + command)
subprocess.call(command, cwd=workingDir, shell=True)
rl.info('Done: ' + command)
def analyzeSlices(workingDir,sliceList):
rl = l.RuntimeLogger(workingDir)
rl.info('To execute bxh slice analysis on : ' + workingDir)
rl.info('analyzing for slices: ' + str(sliceList))
for zslice in sliceList:
fmriQaAnalysis(workingDir, zslice)
rl.info('Done bxh slice analysis on : ' + workingDir)