示例#1
0
 def test_run_no_mask(self):
     rundata = FabberRunData()
     rundata["model"] = "poly"
     rundata["degree"] = "2"
     # rundata["save-mean"] = "" FIXME causes error due to compatibility options
     rundata["data"] = os.path.join(self.datadir, "test_data_small")
     run = self.fab.run(rundata)
示例#2
0
 def test_model_evaluate(self):
     rundata = FabberRunData()
     rundata["model"] = "poly"
     rundata["degree"] = "2"
     ret = self.fab.model_evaluate(rundata, {"c0": 1, "c1": 2, "c2": 3}, 5)
     self.assertEquals(5, len(ret))
     for t in range(5):
         self.assertEquals(1 + 2 * (t + 1) + 3 * (t + 1) * (t + 1), ret[t])
示例#3
0
 def test_get_model_params(self):
     rundata = FabberRunData()
     rundata["model"] = "poly"
     rundata["degree"] = "2"
     params = self.fab.get_model_params(rundata)
     self.assertTrue("c0" in params)
     self.assertTrue("c1" in params)
     self.assertTrue("c2" in params)
示例#4
0
 def test_run_no_mask(self):
     data = np.fromfunction(self.quad_data, (3, 3, 3, 3))
     rundata = FabberRunData()
     rundata["model"] = "poly"
     rundata["degree"] = "2"
     rundata["save-mean"] = ""
     run = self.fab.run_with_data(rundata, {"data": data})
     self.assertAlmostEqual(run.data["mean_c0"][0, 0, 0], c0, delta=0.1)
     self.assertAlmostEqual(run.data["mean_c1"][0, 0, 0], c1, delta=0.1)
     self.assertAlmostEqual(run.data["mean_c2"][0, 0, 0], c2, delta=0.1)
示例#5
0
 def test_run_empty_mask(self):
     data = np.fromfunction(self.quad_data, (3, 3, 3, 3))
     mask = np.zeros((3, 3, 3))
     rundata = FabberRunData()
     rundata["model"] = "poly"
     rundata["degree"] = "2"
     rundata["save-mean"] = ""
     run = self.fab.run_with_data(rundata, {"data": data}, mask)
     self.assertEqual(run.data["mean_c0"].max(), 0)
     self.assertEqual(run.data["mean_c1"].max(), 0)
     self.assertEqual(run.data["mean_c2"].max(), 0)
示例#6
0
    def test_run_cb(self):
        data = np.fromfunction(self.quad_data, (3, 3, 3, 3))
        rundata = FabberRunData()
        rundata["model"] = "poly"
        rundata["degree"] = "2"
        rundata["save-mean"] = ""
        run = self.fab.run_with_data(rundata, {"data": data},
                                     progress_cb=self.progress_cb)

        self.assertEquals(0, self.progress[0][0])
        last = self.progress[-1]
        self.assertTrue(last[0] > 0)
        self.assertEquals(last[0], last[1])
Example: Create a test dataset for the simple polynomial model

generate_test_image.py --model=poly --degree=2 --param-c0=10,20,30 --param-c1=0.5,1,2 --param-c2=5 --nt=10
"""

import os, sys
import traceback

import numpy as np
import nibabel as nib

sys.path.insert(0, os.environ["FSLDIR"] + "/lib/python")
from fabber import FabberRunData, generate_test_data

try:
    rundata = FabberRunData()
    params = {}
    model_libs = []
    outfile="test_image.nii"
    nt = 10
    for arg in sys.argv[1:]:
        if arg.startswith("--loadmodels"):
            model_libs.append(arg.split("=")[1])
        if arg.startswith("--outfile"):
            outfile=arg.split("=")[1]
        elif arg.startswith("--nt"):
            nt = int(arg.split("=")[1])
        elif arg.startswith("--param-"):
            key, value = arg[8:].split("=")
            params[key] = [float(v) for v in value.split(",")]
        elif arg.startswith("--"):