Commit 167a166d authored by William Clarke's avatar William Clarke
Browse files

Merge branch 'bf/win_script_support' into 'dev/windows_support'

enh: installation verification script

See merge request !50
parents 080f479c b3beb24b
Pipeline #14537 passed with stages
in 15 minutes and 24 seconds
#!/usr/bin/env python
# fsl_mrs_veridy - script to verify fsl_mrs sucessfull installation
#
# Author: William Clarke <william.clarke@ndcn.ox.ac.uk>
# Saad Jbabdi <saad@fmrib.ox.ac.uk>
#
# Copyright (C) 2022 University of Oxford
# SHBASECOPYRIGHT
# Quick imports
import urllib.request
import shutil
import tarfile
from pathlib import Path
import subprocess
import pandas as pd
import numpy as np
from fsl_mrs import __version__
def main():
print(f'FSL-MRS version {__version__}.')
# Verify SVS fitting functionality
print('Verifying SVS fitting:')
print('--> Downloading data.')
data_base_url = 'https://git.fmrib.ox.ac.uk/fsl/fsl_mrs/-/'
svs_data = {
'metab.nii.gz': 'raw/master/example_usage/example_data/metab.nii.gz?inline=false',
'wref.nii.gz': 'raw/master/example_usage/example_data/wref.nii.gz?inline=false',
'steam_11ms.tar.gz': 'archive/master/fsl_mrs-master.tar.gz?path=example_usage/example_data/steam_11ms',
'T1.anat.tar.gz': 'archive/master/fsl_mrs-master.tar.gz?path=example_usage/example_data/T1.anat'}
for file in svs_data:
curr_url = data_base_url + svs_data[file]
with urllib.request.urlopen(curr_url) as response, open(file, 'wb') as f:
shutil.copyfileobj(response, f)
if 'tar.gz' in file:
# extract file
tfile = tarfile.open(file)
for member in tfile.getmembers():
# Remove file structure
if member.isfile():
member.name = Path(member.name).name
tfile.extract(member, path='./' + file.replace('.tar.gz', ''))
tfile.close()
Path(file).unlink()
print('--> Running svs_segment')
subprocess.check_call([
'svs_segment',
'-a', 'T1.anat',
'metab.nii.gz'
], stdout=subprocess.DEVNULL)
print('--> Running fsl_mrs')
t1_path = Path('T1.anat') / 'T1_biascorr.nii.gz'
subprocess.check_call([
'fsl_mrs',
'--data', 'metab.nii.gz',
'--basis', 'steam_11ms',
'--output', 'fsl_mrs_test_results',
'--metab_groups', 'Mac',
'--combine', 'Cr', 'PCr',
'--combine', 'NAA', 'NAAG',
'--combine', 'GPC', 'PCh',
'--t1', str(t1_path),
'--tissue_frac', 'segmentation.json',
'--h2o', 'wref.nii.gz',
'--report',
])
assert (Path('fsl_mrs_test_results') / 'summary.csv').is_file()
assert (Path('fsl_mrs_test_results') / 'report.html').is_file()
assert (Path('fsl_mrs_test_results') / 'voxel_location.png').is_file()
svs_results = pd.read_csv(Path('fsl_mrs_test_results') / 'summary.csv', index_col=0)
assert np.isclose(svs_results.loc['NAA+NAAG', 'mM'], 13.18, atol=1E-2)
print('SVS fitting checks passed')
print('All done')
if __name__ == '__main__':
main()
'''FSL-MRS test script
Test the installation verification script
Copyright Will Clarke, University of Oxford, 2022'''
from fsl_mrs.scripts import fsl_mrs_verify
def test_verify(tmp_path):
with tmp_path:
try:
fsl_mrs_verify.main()
except Exception as exc:
assert False, f"'fsl_mrs_verify.main()' fialed and raised an exception {exc}"
......@@ -50,7 +50,8 @@ setup(name='fsl_mrs',
'merge_mrs_reports = fsl_mrs.scripts.merge_mrs_reports:main',
'svs_segment = fsl_mrs.scripts.svs_segment:main',
'mrsi_segment = fsl_mrs.scripts.mrsi_segment:main',
'results_to_spectrum = fsl_mrs.scripts.results_to_spectrum:main'
'results_to_spectrum = fsl_mrs.scripts.results_to_spectrum:main',
'fsl_mrs_verify = fsl_mrs.scripts.fsl_mrs_verify:main'
]
}
)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment