Skip to content

Commit

Permalink
complete merge
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultdvx committed Dec 18, 2024
1 parent bac2315 commit f431c7f
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 34 deletions.
11 changes: 5 additions & 6 deletions clinicadl/data/datasets/caps_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,9 @@ def _get_df_from_input(
df = self._check_data_instance(data)
self.df = df

if not self._check_preprocessing_config():
raise ClinicaDLCAPSError(
f"The DataFrame does not match the preprocessing configuration: {self.preprocessing.preprocessing.value}"
)
self.caps_reader.check_preprocessing(
self._get_participant_session_couples(), self.preprocessing
)

return df

Expand All @@ -260,11 +259,11 @@ def _check_data_instance(self, data: Optional[Union[pd.DataFrame, Path]] = None)
"Please ensure the file path is correct and accessible."
)
df = tsv_to_df(data)
if isinstance(data, pd.DataFrame):
elif isinstance(data, pd.DataFrame):
df = check_df(data)
else:
raise ValueError(
f"'data' must be a Pandas DataFrame, a path to a TSV file or None. Got{data}"
f"'data' must be a Pandas DataFrame, a path to a TSV file or None. Got {data}"
)

return df
Expand Down
2 changes: 1 addition & 1 deletion clinicadl/predictor/old_predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ def _compute_output_tensors(
Compute the output tensors and saves them in the MAPS.
Args:
dataset (clinicadl.dataset.caps_dataset.CapsDataset): wrapper of the data set.
dataset (clinicadl.data.datasets.caps_dataset.CapsDataset): wrapper of the data set.
data_group (str): name of the data group used for the task.
split (int): split number.
selection_metrics (list[str]): metrics used for model selection.
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/dataset/test_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from clinicadl.dataset.config import FileType
from clinicadl.data.config import FileType
from clinicadl.utils.enum import PreprocessingMethod


Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/dataset/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import pytest
import torchio as tio

from clinicadl.dataset.datasets.caps_dataset import CapsDataset
from clinicadl.dataset.preprocessing import PreprocessingPET, PreprocessingT1
from clinicadl.data.datasets import CapsDataset
from clinicadl.data.preprocessing import PreprocessingPET, PreprocessingT1
from clinicadl.transforms import Transforms
from clinicadl.utils.exceptions import (
ClinicaDLArgumentError,
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/dataset/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import pytest

from clinicadl.dataset.preprocessing import PreprocessingT1
from clinicadl.dataset.readers import CapsReader
from clinicadl.data.preprocessing import PreprocessingT1
from clinicadl.data.readers import CapsReader
from clinicadl.utils.enum import PreprocessingMethod
from clinicadl.utils.exceptions import (
ClinicaDLArgumentError,
Expand Down
20 changes: 3 additions & 17 deletions tests/unittests/splitter/test_splitter.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
import json
from pathlib import Path

import nibabel as nib
import numpy as np
import pandas as pd
import pytest
from pydantic import ValidationError

from clinicadl.data.datasets.caps_dataset import CapsDataset
from clinicadl.data.preprocessing import PreprocessingT1, PreprocessingT2
from clinicadl.splitter.split import Split
from clinicadl.data.preprocessing import PreprocessingT1
from clinicadl.splitter.splitter.kfold import KFold, KFoldConfig
from clinicadl.splitter.splitter.single_split import SingleSplit, SingleSplitConfig
from clinicadl.splitter.splitter.splitter import (
Splitter,
SplitterConfig,
SubjectsSessionsSplit,
)
from clinicadl.splitter.splitter.splitter import SubjectsSessionsSplit
from clinicadl.transforms import Transforms
from clinicadl.utils.enum import Preprocessing
from clinicadl.utils.exceptions import (
ClinicaDLArgumentError,
ClinicaDLCAPSError,
ClinicaDLConfigurationError,
ClinicaDLTSVError,
)
from clinicadl.utils.exceptions import ClinicaDLTSVError

caps_dir = Path(__file__).parents[1] / "ressources" / "caps_example"
split_dir = caps_dir / "split_test" / "split"
Expand Down
10 changes: 5 additions & 5 deletions tests/unittests/transforms/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,22 @@ def test_get_transforms():
assert (tio_image.label.tensor == old_tio_image.label.tensor).all()
assert (tio_image.mask_1.tensor == old_tio_image.mask_1.tensor).all()

tio_sample = transforms.extraction.extract_tio_sample(tio_image, 0)
tio_sample, _ = transforms.extraction.extract_tio_sample(tio_image, 0)
patch_mask = np.zeros((1, 4, 4, 4))
patch_mask[:, 1:, 1:, 1:] = 1
patch_mask = torch.from_numpy(patch_mask)
assert (tio_sample.sample.tensor == tio_image.image.tensor[:, :4, :4, :4]).all()
assert (tio_sample.image.tensor == tio_image.image.tensor[:, :4, :4, :4]).all()
assert (tio_sample.label.tensor == tio_image.label.tensor[:, :4, :4, :4]).all()
assert (tio_sample.mask_1.tensor == patch_mask).all()

tio_sample = sample_transforms(tio_sample)
assert tio_sample.sample.tensor.shape == (1, 6, 6, 6)
assert tio_sample.image.tensor.shape == (1, 6, 6, 6)
assert tio_sample.label.tensor.shape == (1, 6, 6, 6)
assert tio_sample.mask_1.tensor.shape == (1, 6, 6, 6)

tio_sample = sample_augmentations(tio_sample)
assert (tio_sample.sample.tensor[:, :2, :2, :2] == 0.0).all()
assert (tio_sample.sample.tensor[:, 5:, 5:, 5:] == 0.0).all()
assert (tio_sample.image.tensor[:, :2, :2, :2] == 0.0).all()
assert (tio_sample.image.tensor[:, 5:, 5:, 5:] == 0.0).all()


def test_str():
Expand Down

0 comments on commit f431c7f

Please sign in to comment.