コード例 #1
0
def test_fit():
    """Test the routine to fit the parameters of the dce normalization."""

    # Load the data with only a single serie
    currdir = os.path.dirname(os.path.abspath(__file__))
    path_data = os.path.join(currdir, 'data', 'full_dce')
    # Create an object to handle the data
    dce_mod = DCEModality()

    # Read the data
    dce_mod.read_data_from_path(path_data)

    # Load the GT data
    path_gt = [os.path.join(currdir, 'data', 'full_gt', 'prostate')]
    label_gt = ['prostate']
    gt_mod = GTModality()
    gt_mod.read_data_from_path(label_gt, path_gt)

    # Create the object to make the normalization
    stn = StandardTimeNormalization(dce_mod)

    # Create a synthetic model to fit on
    stn.model_ = np.array([30., 30., 32., 31., 31., 30., 35., 55., 70., 80.])
    stn.is_model_fitted_ = True

    # Fit the parameters on the model
    stn.fit(dce_mod, gt_mod, label_gt[0])

    assert_almost_equal(stn.fit_params_['scale-int'], 1.2296657327848537,
                        decimal=PRECISION_DECIMAL)
    assert_equal(stn.fit_params_['shift-time'], 0.0)
    data = np.array([191.29, 193.28, 195.28, 195.28, 195.28, 197.28, 213.25,
                     249.18, 283.12, 298.10])
    assert_array_almost_equal(stn.fit_params_['shift-int'], data,
                              decimal=PRECISION_DECIMAL)
コード例 #2
0
def test_normalize_denormalize_3():
    """Test the data normalization and denormalization with shift > 0."""

    # Load the data with only a single serie
    currdir = os.path.dirname(os.path.abspath(__file__))
    path_data = os.path.join(currdir, 'data', 'full_dce')
    # Create an object to handle the data
    dce_mod = DCEModality()

    # Read the data
    dce_mod.read_data_from_path(path_data)

    # Load the GT data
    path_gt = [os.path.join(currdir, 'data', 'full_gt', 'prostate')]
    label_gt = ['prostate']
    gt_mod = GTModality()
    gt_mod.read_data_from_path(label_gt, path_gt)

    # Create the object to make the normalization
    stn = StandardTimeNormalization(dce_mod)

    # Simulate that we fitted the data
    stn.model_ = np.array([30., 30., 32., 31., 31., 30., 35., 55., 70., 80.])
    stn.is_model_fitted_ = True
    stn.fit_params_ = {'scale-int': 1.2296657327848537,
                       'shift-time': 3.0,
                       'shift-int': np.array([191.29, 193.28, 195.28, 195.28,
                                              195.28, 197.28, 213.25, 249.18,
                                              283.12, 298.10])}
    stn.is_fitted_ = True

    # Store the data somewhere
    data_gt_cp = dce_mod.data_.copy()

    # Normalize the data
    dce_mod_norm = stn.normalize(dce_mod)

    # Check if the data are properly normalized
    dce_mod_norm.data_.flags.writeable = False
    data = np.load(os.path.join(currdir, 'data', 'data_normalized_dce_3.npy'))
    assert_equal(hash(dce_mod_norm.data_.data), data)

    dce_mod_norm.data_.flags.writeable = True

    dce_mod_2 = stn.denormalize(dce_mod_norm)
    dce_mod_2.data_.flags.writeable = False
    assert_equal(hash(dce_mod_2.data_.data), -3781160829709175881)