#!/usr/bin/env fslpython
#
# An example FEEDS test which loads some data from
# a shared data directory, and uses it to test an
# algorithm.
#
# This script is identical to the shared_data example,
# but its feedsInputs file is a bit different.
#
#

import sys
import os.path as op
import numpy   as np
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.
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'))
