本文整理汇总了Python中protoclass.data_management.GTModality.read_data_from_path方法的典型用法代码示例。如果您正苦于以下问题:Python GTModality.read_data_from_path方法的具体用法?Python GTModality.read_data_from_path怎么用?Python GTModality.read_data_from_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类protoclass.data_management.GTModality
的用法示例。
在下文中一共展示了GTModality.read_data_from_path方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_partial_fit_model_dict_wrong_type
# 需要导入模块: from protoclass.data_management import GTModality [as 别名]
# 或者: from protoclass.data_management.GTModality 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)
示例2: test_qte_transform_regular
# 需要导入模块: from protoclass.data_management import GTModality [as 别名]
# 或者: from protoclass.data_management.GTModality 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)
示例3: test_extract_index
# 需要导入模块: from protoclass.data_management import GTModality [as 别名]
# 或者: from protoclass.data_management.GTModality import read_data_from_path [as 别名]
def test_extract_index():
""" Test if the indexes of a GT will be well extracted. """
# Load the data with only a single serie
currdir = os.path.dirname(os.path.abspath(__file__))
path_data = os.path.join(currdir, 'data', 'gt_folders')
path_data_list = [os.path.join(path_data, 'prostate'),
os.path.join(path_data, 'cg'),
os.path.join(path_data, 'pz'),
os.path.join(path_data, 'cap')]
# Give the list for the ground_truth
label = ['prostate', 'cg', 'pz', 'cap']
# Create an object to handle the data
gt_mod = GTModality()
# Read the data
gt_mod.read_data_from_path(label, path_data=path_data_list)
# Extract the prostate indexes
label_extr = 'prostate'
idx_prostate = gt_mod.extract_gt_data(label_extr, 'index')
data = np.load(os.path.join(currdir, 'data', 'extract_gt_index.npy'))
# Check each table
for idx_arr, test_arr in zip(idx_prostate, data):
assert_array_equal(idx_arr, test_arr)
示例4: test_partial_fit_model_2
# 需要导入模块: from protoclass.data_management import GTModality [as 别名]
# 或者: from protoclass.data_management.GTModality 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_)
示例5: test_read_gt_data_path_list_constructor
# 需要导入模块: from protoclass.data_management import GTModality [as 别名]
# 或者: from protoclass.data_management.GTModality import read_data_from_path [as 别名]
def test_read_gt_data_path_list_constructor():
""" Test if we can read gt series. """
# Load the data with only a single serie
currdir = os.path.dirname(os.path.abspath(__file__))
path_data = os.path.join(currdir, 'data', 'gt_folders')
path_data_list = [os.path.join(path_data, 'prostate'),
os.path.join(path_data, 'cg'),
os.path.join(path_data, 'pz'),
os.path.join(path_data, 'cap')]
# Give the list for the ground_truth
label = ['prostate', 'cg', 'pz', 'cap']
# Create an object to handle the data
gt_mod = GTModality(path_data_list)
# Check that the data have been read
assert_true(not gt_mod.is_read())
gt_mod.read_data_from_path(label)
# Check that the data have been read
assert_true(gt_mod.is_read())
# Check the data here
data = np.load(os.path.join(currdir, 'data', 'gt_path_list.npy'))
assert_array_equal(gt_mod.data_, data)
assert_equal(gt_mod.n_serie_, 4)
示例6: test_fit
# 需要导入模块: from protoclass.data_management import GTModality [as 别名]
# 或者: from protoclass.data_management.GTModality 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)
示例7: test_shift_heatmap_wrong_shift
# 需要导入模块: from protoclass.data_management import GTModality [as 别名]
# 或者: from protoclass.data_management.GTModality 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)
示例8: test_shift_heatmap
# 需要导入模块: from protoclass.data_management import GTModality [as 别名]
# 或者: from protoclass.data_management.GTModality 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)
示例9: test_gn_wrong_size_gt
# 需要导入模块: from protoclass.data_management import GTModality [as 别名]
# 或者: from protoclass.data_management.GTModality import read_data_from_path [as 别名]
def test_gn_wrong_size_gt():
""" Test either if an error is raised when the size of the ground-truth
is different from the size of the base modality. """
# Create a T2WModality object
currdir = os.path.dirname(os.path.abspath(__file__))
path_data_t2w = os.path.join(currdir, 'data', 't2w')
t2w_mod = T2WModality(path_data_t2w)
t2w_mod.read_data_from_path()
# Create the GTModality object
path_data_gt = os.path.join(currdir, 'data', 'gt_folders')
path_data_gt_list = [os.path.join(path_data_gt, 'prostate'),
os.path.join(path_data_gt, 'pz'),
os.path.join(path_data_gt, 'cg'),
os.path.join(path_data_gt, 'cap')]
label_gt = ['prostate', 'pz', 'cg', 'cap']
gt_mod = GTModality()
gt_mod.read_data_from_path(cat_gt=label_gt, path_data=path_data_gt_list)
# Change the size of the data of the modality
t2w_mod.data_ = t2w_mod.data_[:-1, :, :]
gaussian_norm = GaussianNormalization(T2WModality())
assert_raises(ValueError, gaussian_norm.fit, t2w_mod, gt_mod, label_gt[0])
示例10: test_ese_transform_gt_cat
# 需要导入模块: from protoclass.data_management import GTModality [as 别名]
# 或者: from protoclass.data_management.GTModality 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)
示例11: test_gn_fit_fix_mu_sigma
# 需要导入模块: from protoclass.data_management import GTModality [as 别名]
# 或者: from protoclass.data_management.GTModality import read_data_from_path [as 别名]
def test_gn_fit_fix_mu_sigma():
""" Test the fitting routine with fixed mean and std. """
# Create a T2WModality object
currdir = os.path.dirname(os.path.abspath(__file__))
path_data_t2w = os.path.join(currdir, 'data', 't2w')
t2w_mod = T2WModality(path_data_t2w)
t2w_mod.read_data_from_path()
# Create the GTModality object
path_data_gt = os.path.join(currdir, 'data', 'gt_folders')
path_data_gt_list = [os.path.join(path_data_gt, 'prostate'),
os.path.join(path_data_gt, 'pz'),
os.path.join(path_data_gt, 'cg'),
os.path.join(path_data_gt, 'cap')]
label_gt = ['prostate', 'pz', 'cg', 'cap']
gt_mod = GTModality()
gt_mod.read_data_from_path(cat_gt=label_gt, path_data=path_data_gt_list)
params = {'mu': 200., 'sigma': 70.}
gaussian_norm = GaussianNormalization(T2WModality(), params=params)
gaussian_norm.fit(t2w_mod, gt_mod, label_gt[0])
assert_almost_equal(gaussian_norm.fit_params_['mu'], 245.90,
decimal=DECIMAL_PRECISON)
assert_almost_equal(gaussian_norm.fit_params_['sigma'], 74.31,
decimal=DECIMAL_PRECISON)
示例12: test_denormalize_wt_fitting
# 需要导入模块: from protoclass.data_management import GTModality [as 别名]
# 或者: from protoclass.data_management.GTModality import read_data_from_path [as 别名]
def test_denormalize_wt_fitting():
"""Test either an error is raised if the data are not fitted first."""
# Create a T2WModality object
currdir = os.path.dirname(os.path.abspath(__file__))
path_data_t2w = os.path.join(currdir, 'data', 't2w')
t2w_mod = T2WModality(path_data_t2w)
t2w_mod.read_data_from_path()
# Create the GTModality object
path_data_gt = os.path.join(currdir, 'data', 'gt_folders')
path_data_gt_list = [os.path.join(path_data_gt, 'prostate'),
os.path.join(path_data_gt, 'pz'),
os.path.join(path_data_gt, 'cg'),
os.path.join(path_data_gt, 'cap')]
label_gt = ['prostate', 'pz', 'cg', 'cap']
gt_mod = GTModality()
gt_mod.read_data_from_path(cat_gt=label_gt, path_data=path_data_gt_list)
# Store the data before the normalization
pdf_copy = t2w_mod.pdf_.copy()
data_copy = t2w_mod.data_.copy()
# Normalize the data
gaussian_norm = GaussianNormalization(T2WModality())
assert_raises(ValueError, gaussian_norm.denormalize, t2w_mod)
示例13: test_rn_fit_fix_params
# 需要导入模块: from protoclass.data_management import GTModality [as 别名]
# 或者: from protoclass.data_management.GTModality import read_data_from_path [as 别名]
def test_rn_fit_fix_params():
""" Test the fitting routine with fixed parameters. """
# Create a T2WModality object
currdir = os.path.dirname(os.path.abspath(__file__))
path_data_t2w = os.path.join(currdir, 'data', 't2w')
t2w_mod = T2WModality(path_data_t2w)
t2w_mod.read_data_from_path()
# Create the GTModality object
path_data_gt = os.path.join(currdir, 'data', 'gt_folders')
path_data_gt_list = [os.path.join(path_data_gt, 'prostate'),
os.path.join(path_data_gt, 'pz'),
os.path.join(path_data_gt, 'cg'),
os.path.join(path_data_gt, 'cap')]
label_gt = ['prostate', 'pz', 'cg', 'cap']
gt_mod = GTModality()
gt_mod.read_data_from_path(cat_gt=label_gt, path_data=path_data_gt_list)
params = {'b': 200., 'off': 7., 'sigma': 80.}
rician_norm = RicianNormalization(T2WModality(), params=params)
rician_norm.fit(t2w_mod, gt_mod, label_gt[0])
assert_almost_equal(rician_norm.fit_params_['b'], 1.4463929678319398,
decimal=DECIMAL_PRECISON)
assert_almost_equal(rician_norm.fit_params_['off'], 0.12668917318976813,
decimal=DECIMAL_PRECISON)
assert_almost_equal(rician_norm.fit_params_['sigma'], 0.10331905081688209,
decimal=DECIMAL_PRECISON)
示例14: test_build_graph
# 需要导入模块: from protoclass.data_management import GTModality [as 别名]
# 或者: from protoclass.data_management.GTModality 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)
示例15: test_save_model_wrong_ext
# 需要导入模块: from protoclass.data_management import GTModality [as 别名]
# 或者: from protoclass.data_management.GTModality 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'))