#!/usr/bin/env fslpython
#
# An example FEEDS test which loads some data from
# a shared data directory, and uses it to test an
# algorithm.
#

import sys
import os.path as op
import nibabel as nib


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


def fancy_algorithm_that_needs_testing(data):
    return (data + 5) * 20


# Load the input data. The exampleData
# directory contains an input image,
# and a reference image which has been
# generated by the algorithm, and which
# we know to be correct. We can use the
# reference image as a benchmark for
# testing.
inimg = nib.load(op.join(indir, 'exampleData', 'input.nii.gz'))

# Get access to the image data
# through the nibabel wrapper.
indata = inimg.get_fdata()

# Run the algorithm, save its output
processedData = fancy_algorithm_that_needs_testing(indata)

image = nib.Nifti1Image(processedData,
                        inimg.affine,
                        inimg.header)

nib.save(image, op.join(outdir, 'output.nii.gz'))
