#!/usr/bin/env fslpython
#
# An example test script which uses fslmaths to generate some data.
#

import               sys
import os.path    as op
import subprocess as sp


# Read in the command line arguments.
outdir = sys.argv[1]
indir  = sys.argv[2]


# Build filenames for the input image,
# and for a temporary output image.
infile   = op.join(indir,  'exampleData', 'input.nii.gz')
outfile  = op.join(outdir, 'output.nii.gz')
statfile = op.join(outdir, 'stats.txt')


# Run the algorithm using fslmaths.
sp.call(('fslmaths', infile, '-add', '5', '-mul', '20', outfile))


# Calculate some stats, save them to disk
result = sp.check_output(('fslstats', outfile, '-m', '-R')).decode('latin1')

with open(statfile, 'wt') as f:
    f.write('{}\n'.format(result))
