Skip to content

Commit

Permalink
answer em comments
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudbore committed Sep 26, 2024
1 parent 1a913d7 commit 5596680
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions dwi_ml/data/hdf5/hdf5_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ def __init__(self, root_folder: Path, out_hdf_filename: Path,
save_intermediate: bool = False,
intermediate_folder: Path = None):
"""
Params step_size, nb_points and compress are mutually exclusive.
Params
------
root_folder: Path
Expand All @@ -159,7 +161,7 @@ def __init__(self, root_folder: Path, out_hdf_filename: Path,
groups_config: dict
Information from json file loaded as a dict.
dps_keys: List[str]
List of keys to keep in data_per_streamline. Default: None.
List of keys to keep in data_per_streamline. Default: [].
step_size: float
Step size to resample streamlines. Default: None.
nb_points: int
Expand Down Expand Up @@ -201,7 +203,7 @@ def __init__(self, root_folder: Path, out_hdf_filename: Path,
self._analyse_config_file()

# -------- Performing checks

self._check_streamlines_operations()
# Check that all subjects exist.
logging.debug("Preparing hdf5 creator for \n"
" training subjs {}, \n"
Expand Down Expand Up @@ -353,6 +355,19 @@ def flatten_list(a_list):
self.enforce_files_presence,
folder=subj_input_dir)

def _check_streamlines_operations(self):
valid = True
if self.step_size and self.nb_points:
valid = False
elif self.step_size and self.compress:
valid = False
elif self.nb_points and self.compress:
valid = False
if not valid:
raise ValueError(
"Only one option can be chosen: either resampling to "
"step_size, nb_points or compressing, not both.")

def create_database(self):
"""
Generates a hdf5 dataset from a group of subjects. Hdf5 dataset will
Expand Down Expand Up @@ -746,11 +761,11 @@ def _load_and_process_sft(self, tractogram_file, header):
"We do not support file's type: {}. We only support .trk "
"and .tck files.".format(tractogram_file))
if file_extension == '.trk':
if header:
if not is_header_compatible(str(tractogram_file), header):
raise ValueError("Streamlines group is not compatible "
"with volume groups\n ({})"
.format(tractogram_file))
if header and not is_header_compatible(str(tractogram_file),
header):
raise ValueError("Streamlines group is not compatible "
"with volume groups\n ({})"
.format(tractogram_file))
# overriding given header.
header = 'same'

Expand Down

0 comments on commit 5596680

Please sign in to comment.