当前位置: 首页>>代码示例>>Python>>正文


Python DCEModality.read_data_from_path方法代码示例

本文整理汇总了Python中protoclass.data_management.DCEModality.read_data_from_path方法的典型用法代码示例。如果您正苦于以下问题:Python DCEModality.read_data_from_path方法的具体用法?Python DCEModality.read_data_from_path怎么用?Python DCEModality.read_data_from_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在protoclass.data_management.DCEModality的用法示例。


在下文中一共展示了DCEModality.read_data_from_path方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_save_model_wrong_ext

# 需要导入模块: from protoclass.data_management import DCEModality [as 别名]
# 或者: from protoclass.data_management.DCEModality import read_data_from_path [as 别名]
def test_save_model_wrong_ext():
    """Test either if an error is raised if the filename as a wrong
    extension while storing the model."""

    # 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)
    stn.partial_fit_model(dce_mod, gt_mod, label_gt[0])

    # Try to store the file not with an npy file
    assert_raises(ValueError, stn.save_model, os.path.join(currdir, 'data',
                                                           'model.rnd'))
开发者ID:glemaitre,项目名称:protoclass,代码行数:28,代码来源:test_standard_time_normalization.py

示例2: test_dce_get_pdf_roi

# 需要导入模块: from protoclass.data_management import DCEModality [as 别名]
# 或者: from protoclass.data_management.DCEModality import read_data_from_path [as 别名]
def test_dce_get_pdf_roi():
    """Test the function to get a pdf from ROI."""

    # Load the data with only a single serie
    currdir = os.path.dirname(os.path.abspath(__file__))
    path_data = os.path.join(currdir, 'data', 'dce_folders')
    # Create the list of path
    path_data_list = [os.path.join(path_data, 's_2'),
                      os.path.join(path_data, 's_1')]
    # Create an object to handle the data
    dce_mod = DCEModality()

    dce_mod.read_data_from_path(path_data_list)

    # Create ground truth array
    pos = np.ones((368, 448), dtype=bool)
    neg = np.zeros((368, 448), dtype=bool)
    gt_index = np.rollaxis(np.array([neg, pos, pos, pos, neg]), 0, 3)

    # Compute the histgram for the required data
    pdf, bins = dce_mod.get_pdf_list(roi_data=(gt_index))

    pdf_roi = np.load(os.path.join(currdir, 'data', 'pdf_roi.npy'))
    bins_roi = np.load(os.path.join(currdir, 'data', 'bins_roi.npy'))

    for pdf_s, bins_s, pdf_gt, bins_gt in zip(pdf, bins,
                                              pdf_roi, bins_roi):
        assert_array_equal(pdf_s, pdf_gt)
        assert_array_equal(bins_s, bins_gt)
开发者ID:glemaitre,项目名称:protoclass,代码行数:31,代码来源:test_dce_modality.py

示例3: test_build_heatmap_roi

# 需要导入模块: from protoclass.data_management import DCEModality [as 别名]
# 或者: from protoclass.data_management.DCEModality import read_data_from_path [as 别名]
def test_build_heatmap_roi():
    """ Test if the heatmap is built properly when providing a ROI. """

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

    # Read the data
    dce_mod.read_data_from_path(path_data)
    dce_mod.data_ /= 2.
    dce_mod.update_histogram()

    # Create some ground-truth
    pos = np.ones((368, 448), dtype=bool)
    neg = np.zeros((368, 448), dtype=bool)
    gt_index = np.rollaxis(np.array([neg, pos, pos, pos, neg]), 0, 3)

    # Build the heatmap
    heatmap, bins_heatmap = dce_mod.build_heatmap(roi_data=(gt_index))

    # Check that heatmap is what we expect
    data = np.load(os.path.join(currdir, 'data', 'heatmap_roi_mod.npy'))
    assert_array_equal(heatmap, data)
    data = np.load(os.path.join(currdir, 'data', 'bins_heatmap_roi_mod.npy'))
    assert_array_equal(bins_heatmap, data)
开发者ID:glemaitre,项目名称:protoclass,代码行数:29,代码来源:test_dce_modality.py

示例4: test_tqe_compute_fit_no_aif

# 需要导入模块: from protoclass.data_management import DCEModality [as 别名]
# 或者: from protoclass.data_management.DCEModality import read_data_from_path [as 别名]
def test_tqe_compute_fit_no_aif():
    """Test the fit function."""

    # Try to fit an object with another modality
    currdir = os.path.dirname(os.path.abspath(__file__))
    path_data = os.path.join(currdir,
                             '../../preprocessing/tests/data/full_dce')
    # Create an object to handle the data
    dce_mod = DCEModality()
    dce_mod.read_data_from_path(path_data)

    # Create the object for Tofts quantification extraction
    tqe = ToftsQuantificationExtraction(DCEModality(), 1.6, 3.5,
                                        random_state=RND_SEED)

    # Perform the fitting
    tqe.fit(dce_mod, fit_aif=False)

    # Check the value fitted
    assert_almost_equal(tqe.TR_, 0.00324, decimal=DECIMAL_PRECISION)
    assert_almost_equal(tqe.flip_angle_, 10., decimal=DECIMAL_PRECISION)
    assert_equal(tqe.start_enh_, 3)
    cp_r_gt = np.array([0., 0., 0., 0.13859428, 6.23675492, 6.90344512,
                        1.80619315, 2.22619032, 3.69060743, 3.32021637])
    assert_array_almost_equal(tqe.cp_t_, cp_r_gt, decimal=DECIMAL_PRECISION)
开发者ID:glemaitre,项目名称:protoclass,代码行数:27,代码来源:test_tofts_quantification_extraction.py

示例5: test_partial_fit_model_dict_wrong_type

# 需要导入模块: from protoclass.data_management import DCEModality [as 别名]
# 或者: from protoclass.data_management.DCEModality import read_data_from_path [as 别名]
def test_partial_fit_model_dict_wrong_type():
    """Test either if an error is raised when a parameters is a wrong
     type in the dictionary."""

    # Load the data with only a single serie
    currdir = os.path.dirname(os.path.abspath(__file__))
    path_data = os.path.join(currdir, 'data', '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', 'gt_folders', '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)
    params = {'std': 50., 'exp': 25., 'alpha': .9, 'max_iter': 5.}
    assert_raises(ValueError, stn.partial_fit_model, dce_mod,
                  ground_truth=gt_mod, cat=label_gt[0], params=params)

    params = {'std': 50., 'exp': 25, 'alpha': .9, 'max_iter': 5}
    assert_raises(ValueError, stn.partial_fit_model, dce_mod,
                  ground_truth=gt_mod, cat=label_gt[0], params=params)
开发者ID:glemaitre,项目名称:protoclass,代码行数:30,代码来源:test_standard_time_normalization.py

示例6: test_partial_fit_model_2

# 需要导入模块: from protoclass.data_management import DCEModality [as 别名]
# 或者: from protoclass.data_management.DCEModality import read_data_from_path [as 别名]
def test_partial_fit_model_2():
    """Test the routine to fit two models."""

    # 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)
    stn.partial_fit_model(dce_mod, gt_mod, label_gt[0])
    stn.partial_fit_model(dce_mod, gt_mod, label_gt[0])

    # Check the model computed
    model_gt = np.array([22.26479174, 22.51070962, 24.66027277, 23.43488237,
                         23.75601817, 22.56173871, 26.86244505, 45.06227804,
                         62.34273874, 71.35327656])
    assert_array_almost_equal(stn.model_, model_gt, decimal=PRECISION_DECIMAL)
    assert_true(stn.is_model_fitted_)
开发者ID:glemaitre,项目名称:protoclass,代码行数:31,代码来源:test_standard_time_normalization.py

示例7: test_shift_heatmap_wrong_shift

# 需要导入模块: from protoclass.data_management import DCEModality [as 别名]
# 或者: from protoclass.data_management.DCEModality import read_data_from_path [as 别名]
def test_shift_heatmap_wrong_shift():
    """Test if an error is raised when the shidt provided is not consistent."""

    # Load the data with only a single serie
    currdir = os.path.dirname(os.path.abspath(__file__))
    path_data = os.path.join(currdir, 'data', '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', 'gt_folders', 'prostate')]
    label_gt = ['prostate']
    gt_mod = GTModality()
    gt_mod.read_data_from_path(label_gt, path_gt)

    # Build a heatmap from the dce data
    # Reduce the number of bins to enforce low memory consumption
    nb_bins = [100] * dce_mod.n_serie_
    heatmap, bins_heatmap = dce_mod.build_heatmap(gt_mod.extract_gt_data(
        label_gt[0]), nb_bins=nb_bins)

    # Create a list of shift which do not have the same number of entries
    # than the heatmap - There is 4 series, let's create only 2
    shift_arr = np.array([10] * 2)

    assert_raises(ValueError, StandardTimeNormalization._shift_heatmap,
                  heatmap, shift_arr)
开发者ID:glemaitre,项目名称:protoclass,代码行数:32,代码来源:test_standard_time_normalization.py

示例8: test_shift_heatmap

# 需要导入模块: from protoclass.data_management import DCEModality [as 别名]
# 或者: from protoclass.data_management.DCEModality import read_data_from_path [as 别名]
def test_shift_heatmap():
    """Test the routine which shift the heatmap."""

    # Load the data with only a single serie
    currdir = os.path.dirname(os.path.abspath(__file__))
    path_data = os.path.join(currdir, 'data', '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', 'gt_folders', 'prostate')]
    label_gt = ['prostate']
    gt_mod = GTModality()
    gt_mod.read_data_from_path(label_gt, path_gt)

    # Build a heatmap from the dce data
    # Reduce the number of bins to enforce low memory consumption
    nb_bins = [100] * dce_mod.n_serie_
    heatmap, bins_heatmap = dce_mod.build_heatmap(gt_mod.extract_gt_data(
        label_gt[0]), nb_bins=nb_bins)

    # Create a list of shift which do not have the same number of entries
    # than the heatmap - There is 4 series, let's create only 2
    shift_arr = np.array([10] * 4)

    heatmap_shifted = StandardTimeNormalization._shift_heatmap(heatmap,
                                                               shift_arr)

    data = np.load(os.path.join(currdir, 'data', 'heatmap_shifted.npy'))
    assert_array_equal(heatmap_shifted, data)
开发者ID:glemaitre,项目名称:protoclass,代码行数:35,代码来源:test_standard_time_normalization.py

示例9: test_tqe_conv_signal_conc

# 需要导入模块: from protoclass.data_management import DCEModality [as 别名]
# 或者: from protoclass.data_management.DCEModality import read_data_from_path [as 别名]
def test_tqe_conv_signal_conc():
    """Test the conversion from signal to concentration."""

    # Try to fit an object with another modality
    currdir = os.path.dirname(os.path.abspath(__file__))
    path_data = os.path.join(currdir,
                             '../../preprocessing/tests/data/full_dce')
    # Create an object to handle the data
    dce_mod = DCEModality()
    dce_mod.read_data_from_path(path_data)

    # Create the object for the Tofts extraction
    tqe = ToftsQuantificationExtraction(DCEModality(), 1.6, 3.5)
    tqe.fit(dce_mod, fit_aif=False)

    # Try to perform a conversion
    signal = np.array([379., 366., 343., 355., 367., 470., 613., 628., 604.,
                       575.])

    conc = tqe.signal_to_conc(signal, 343.)
    conc_gt = np.array([2.15201846e-02, 1.36794587e-02, 2.44758162e-13,
                        7.10669089e-03, 1.42797742e-02, 7.87199894e-02,
                        1.77659845e-01, 1.88748637e-01, 1.71075044e-01,
                        1.50198853e-01])
    assert_almost_equal(conc, conc_gt)

    # Apply the back conversion
    signal_back = tqe.conc_to_signal(conc, 343.)
    assert_almost_equal(signal_back, signal, decimal=DECIMAL_PRECISION)
开发者ID:glemaitre,项目名称:protoclass,代码行数:31,代码来源:test_tofts_quantification_extraction.py

示例10: test_ese_transform_gt_cat

# 需要导入模块: from protoclass.data_management import DCEModality [as 别名]
# 或者: from protoclass.data_management.DCEModality import read_data_from_path [as 别名]
def test_ese_transform_gt_cat():
    """Test the transform routine with a given ground-truth."""

    # Create the normalization object with the right modality
    dce_ese = EnhancementSignalExtraction(DCEModality())

    # Try to fit an object with another modality
    currdir = os.path.dirname(os.path.abspath(__file__))
    path_data = os.path.join(currdir, 'data', 'dce')
    # Create an object to handle the data
    dce_mod = DCEModality()
    dce_mod.read_data_from_path(path_data)

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

    # Fit and raise the error
    data = dce_ese.transform(dce_mod, gt_mod, label_gt[0])

    # Check the size of the data
    assert_equal(data.shape, (12899, 4))
    # Check the hash of the data
    data.flags.writeable = False
    assert_equal(hash(data.data), -3808597525488161265)
开发者ID:glemaitre,项目名称:protoclass,代码行数:29,代码来源:test_enhancement_signal_extraction.py

示例11: test_tqe_compute_fit_aif

# 需要导入模块: from protoclass.data_management import DCEModality [as 别名]
# 或者: from protoclass.data_management.DCEModality import read_data_from_path [as 别名]
def test_tqe_compute_fit_aif():
    """Test the fit function."""

    # Try to fit an object with another modality
    currdir = os.path.dirname(os.path.abspath(__file__))
    path_data = os.path.join(currdir,
                             '../../preprocessing/tests/data/full_dce')
    # Create an object to handle the data
    dce_mod = DCEModality()
    dce_mod.read_data_from_path(path_data)

    # Create the object for Tofts quantification extraction
    tqe = ToftsQuantificationExtraction(DCEModality(), 1.6, 3.5,
                                        random_state=RND_SEED)

    # Perform the fitting
    tqe.fit(dce_mod, fit_aif=True)

    # Check the value fitted
    assert_almost_equal(tqe.TR_, 0.00324, decimal=DECIMAL_PRECISION)
    assert_almost_equal(tqe.flip_angle_, 10., decimal=DECIMAL_PRECISION)
    assert_equal(tqe.start_enh_, 3)
    cp_r_gt = np.array([3.71038e-02, 2.35853e-02, 4.21997e-13, 1.22529e-02,
                        2.46203e-02, 1.35724e-01, 3.06310e-01, 3.25429e-01,
                        2.94957e-01, 2.58964e-01])
    assert_array_almost_equal(tqe.cp_t_, cp_r_gt, decimal=DECIMAL_PRECISION)
开发者ID:glemaitre,项目名称:protoclass,代码行数:28,代码来源:test_tofts_quantification_extraction.py

示例12: test_update_histogram_fix_bins

# 需要导入模块: from protoclass.data_management import DCEModality [as 别名]
# 或者: from protoclass.data_management.DCEModality import read_data_from_path [as 别名]
def test_update_histogram_fix_bins():
    """ Test that the function properly update the value of the histogram
    and fixing the number of bins. """

    # Load the data and then call the function independently
    currdir = os.path.dirname(os.path.abspath(__file__))
    path_data = os.path.join(currdir, 'data', 'dce')
    # Create an object to handle the data
    dce_mod = DCEModality()

    dce_mod.read_data_from_path(path_data)

    # Change something in the data to check that the computation
    # is working
    dce_mod.data_[0, 20:40, :, :] = 1000.
    nb_bins = [100, 100]
    dce_mod.update_histogram(nb_bins=nb_bins)

    # We need to check that the minimum and maximum were proprely computed
    assert_equal(dce_mod.min_series_, 0.)
    assert_equal(dce_mod.max_series_, 1000.)

    # Check that bin is what we expect
    data = np.load(os.path.join(currdir, 'data',
                                'bin_dce_data_update_100_bins.npy'))
    # Check that each array are the same
    for exp, gt in zip(dce_mod.bin_series_, data):
        assert_array_equal(exp, gt)

    # Check that pdf is what we expect
    data = np.load(os.path.join(currdir, 'data',
                                'pdf_dce_data_update_100_bins.npy'))
    # Check that each array are the same
    for exp, gt in zip(dce_mod.pdf_series_, data):
        assert_array_equal(exp, gt)
开发者ID:glemaitre,项目名称:protoclass,代码行数:37,代码来源:test_dce_modality.py

示例13: test_qte_transform_regular

# 需要导入模块: from protoclass.data_management import DCEModality [as 别名]
# 或者: from protoclass.data_management.DCEModality import read_data_from_path [as 别名]
def test_qte_transform_regular():
    """Test the transform function for regular model."""

    # Try to fit an object with another modality
    currdir = os.path.dirname(os.path.abspath(__file__))
    path_data = os.path.join(currdir,
                             '../../preprocessing/tests/data/full_dce')
    # Create an object to handle the data
    dce_mod = DCEModality()
    dce_mod.read_data_from_path(path_data)
    # Create the gt data
    gt_mod = GTModality()
    gt_cat = ['cap']
    path_data = [os.path.join(
        currdir,
        '../../preprocessing/tests/data/full_gt/cap')]
    gt_mod.read_data_from_path(gt_cat, path_data)

    # Create the object for the Tofts extraction
    tqe = ToftsQuantificationExtraction(DCEModality(), 1.6, 3.5,
                                        random_state=RND_SEED)
    tqe.fit(dce_mod)
    data = tqe.transform(dce_mod, gt_mod, gt_cat[0], kind='regular')

    data_gt = np.load(os.path.join(currdir, 'data/tofts_reg_data.npy'))
    assert_array_almost_equal(data, data_gt, decimal=DECIMAL_PRECISION)
开发者ID:glemaitre,项目名称:protoclass,代码行数:28,代码来源:test_tofts_quantification_extraction.py

示例14: test_fit

# 需要导入模块: from protoclass.data_management import DCEModality [as 别名]
# 或者: from protoclass.data_management.DCEModality import read_data_from_path [as 别名]
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)
开发者ID:glemaitre,项目名称:protoclass,代码行数:37,代码来源:test_standard_time_normalization.py

示例15: test_build_graph

# 需要导入模块: from protoclass.data_management import DCEModality [as 别名]
# 或者: from protoclass.data_management.DCEModality import read_data_from_path [as 别名]
def test_build_graph():
    """Test the method to build a graph from the heatmap."""

    # Load the data with only a single serie
    currdir = os.path.dirname(os.path.abspath(__file__))
    path_data = os.path.join(currdir, 'data', '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', 'gt_folders', 'prostate')]
    label_gt = ['prostate']
    gt_mod = GTModality()
    gt_mod.read_data_from_path(label_gt, path_gt)

    # Build a heatmap from the dce data
    # Reduce the number of bins to enforce low memory consumption
    nb_bins = [100] * dce_mod.n_serie_
    heatmap, bins_heatmap = dce_mod.build_heatmap(gt_mod.extract_gt_data(
        label_gt[0]), nb_bins=nb_bins)

    # Build the graph by taking the inverse exponential of the heatmap
    graph = StandardTimeNormalization._build_graph(heatmap, .5)
    graph_dense = graph.toarray()

    data = np.load(os.path.join(currdir, 'data', 'graph.npy'))
    assert_array_equal(graph_dense, data)
开发者ID:glemaitre,项目名称:protoclass,代码行数:32,代码来源:test_standard_time_normalization.py


注:本文中的protoclass.data_management.DCEModality.read_data_from_path方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。