Skip to content

Commit

Permalink
Updating the heatmap generation unit test, minor attributes renaming.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbouget committed Feb 1, 2024
1 parent c977915 commit 13a3ace
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
4 changes: 2 additions & 2 deletions raidionicsmaps/Computation/heatmap_computation_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def setup(self, cohort) -> None:
self.cohort = cohort

for p in list(self.cohort.patients.keys()):
mask_fn = self.cohort.patients[p].registered_label_filepaths
mask_fn = self.cohort.patients[p].registered_label_filepath
if mask_fn is None or not os.path.exists(mask_fn):
logging.warning("Registered annotation mask missing for {}".format(self.cohort.patients[p].patient_id))
else:
Expand Down Expand Up @@ -192,7 +192,7 @@ def __run(self, dense_parameters=None, cat_parameters=None) -> None:
param_value = self.cohort.extra_patients_parameters.loc[self.cohort.extra_patients_parameters['Patient'] == pid][cat_parameters[0]].values[0]
if param_value != cat_parameters[1]:
continue
fl = patient.registered_label_filepaths
fl = patient.registered_label_filepath
labels = None
try:
labels_ni = nib.load(fl)
Expand Down
8 changes: 4 additions & 4 deletions raidionicsmaps/Computation/registration_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def setup(self, patient_parameters):
"""
self.patient_parameters = patient_parameters
try:
self._moving_volume_filepath = self.patient_parameters.volume_filepaths
self._moving_volume_filepath = self.patient_parameters.volume_filepath
self._fixed_volume_filepath = SharedResources.getInstance().mni_atlas_filepath_T1
except Exception as e:
logging.error("[RegistrationStep] Setting up process failed with {}".format(traceback.format_exc()))
Expand All @@ -69,7 +69,7 @@ def execute(self):
self.__registration(self._fixed_volume_filepath, self._moving_volume_filepath)

# Flag for skipping applying registration to annotation files if they exist already
if self.patient_parameters.registered_label_filepaths is None:
if self.patient_parameters.registered_label_filepath is None:
self.__apply_registration()

self._registration_runner.clear_cache()
Expand Down Expand Up @@ -145,12 +145,12 @@ def __apply_registration(self):
shutil.move(reg_input_fn, os.path.join(self.patient_parameters.output_folderpath, 'input_reg_mni.nii.gz'))
self.patient_parameters.registered_volume_filepaths = os.path.join(self.patient_parameters.output_folderpath,
'input_reg_mni.nii.gz')
moving_filepath = self.patient_parameters.label_filepaths
moving_filepath = self.patient_parameters.label_filepath
reg_anno_fn = self._registration_runner.apply_registration_transform(fixed=self._fixed_volume_filepath,
moving=moving_filepath)
reg_base_name = 'input_reg_mni_' + SharedResources.getInstance().maps_gt_files_suffix
shutil.move(reg_anno_fn, os.path.join(self.patient_parameters.output_folderpath, reg_base_name))
self.patient_parameters.registered_label_filepaths = os.path.join(self.patient_parameters.output_folderpath,
self.patient_parameters.registered_label_filepath = os.path.join(self.patient_parameters.output_folderpath,
reg_base_name)
except Exception as e:
logging.error("[RegistrationStep] Apply registration failed with: {}.".format(traceback.format_exc()))
Expand Down
44 changes: 22 additions & 22 deletions raidionicsmaps/Structures/PatientStructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,35 +79,35 @@ def input_folderpath(self, input_folderpath: str) -> None:
self._input_folderpath = input_folderpath

@property
def volume_filepaths(self) -> str:
def volume_filepath(self) -> str:
return self._volume_filepath

@volume_filepaths.setter
def volume_filepaths(self, volume_filepaths: str) -> None:
self._volume_filepath = volume_filepaths
@volume_filepath.setter
def volume_filepath(self, volume_filepath: str) -> None:
self._volume_filepath = volume_filepath

@property
def label_filepaths(self) -> str:
def label_filepath(self) -> str:
return self._label_filepath

@label_filepaths.setter
def label_filepaths(self, label_filepaths: str) -> None:
self._label_filepath = label_filepaths
@label_filepath.setter
def label_filepath(self, label_filepath: str) -> None:
self._label_filepath = label_filepath

@property
def registered_volume_filepaths(self) -> str:
def registered_volume_filepath(self) -> str:
return self._registered_volume_filepath

@registered_volume_filepaths.setter
def registered_volume_filepaths(self, filepath: str) -> None:
@registered_volume_filepath.setter
def registered_volume_filepath(self, filepath: str) -> None:
self._registered_volume_filepath = filepath

@property
def registered_label_filepaths(self) -> str:
def registered_label_filepath(self) -> str:
return self._registered_label_filepath

@registered_label_filepaths.setter
def registered_label_filepaths(self, filepath: str) -> None:
@registered_label_filepath.setter
def registered_label_filepath(self, filepath: str) -> None:
self._registered_label_filepath = filepath

@property
Expand All @@ -132,8 +132,8 @@ def __init_from_disk(self) -> None:
volume_files.append(f)
break

self.volume_filepaths = os.path.join(self.input_folderpath, volume_files[0])
self.label_filepaths = os.path.join(self.input_folderpath, label_files[0])
self.volume_filepath = os.path.join(self.input_folderpath, volume_files[0])
self.label_filepath = os.path.join(self.input_folderpath, label_files[0])

res_patient_folder = os.path.join(SharedResources.getInstance().maps_output_folder, self.patient_id)
if os.path.exists(res_patient_folder):
Expand Down Expand Up @@ -177,15 +177,15 @@ def __init_from_disk(self) -> None:
reg_labels_fn = os.path.join(self.output_folderpath,
'input_reg_mni_' + SharedResources.getInstance().maps_gt_files_suffix)
if os.path.exists(reg_input_fn):
self.registered_volume_filepaths = reg_input_fn
self.registered_volume_filepath = reg_input_fn
if os.path.exists(reg_labels_fn):
self.registered_label_filepaths = reg_labels_fn
self.registered_label_filepath = reg_labels_fn

if SharedResources.getInstance().maps_use_registered_data:
if self.registered_volume_filepaths is None:
self.registered_volume_filepaths = self.volume_filepaths
if self.registered_label_filepaths is None:
self.registered_label_filepaths = self.label_filepaths
if self.registered_volume_filepath is None:
self.registered_volume_filepath = self.volume_filepath
if self.registered_label_filepath is None:
self.registered_label_filepath = self.label_filepath

def include_registration(self, reg_uid: str, registration: Registration) -> None:
self.registrations[reg_uid] = registration
1 change: 1 addition & 0 deletions tests/heatmap_generation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def heatmap_generation_test():
unit_test_config.set('Default', 'output_folder', os.path.join(test_dir, 'Cohort_UnitTest1_Output'))
unit_test_config.add_section('Maps')
unit_test_config.set('Maps', 'input_folder', os.path.join(test_dir, 'label_tumor.nii.gz'))
unit_test_config.set('Maps', 'use_registered_data', 'true')
config_filename = os.path.join(test_dir, 'config.ini')
with open(config_filename, 'w') as outfile:
unit_test_config.write(outfile)
Expand Down

0 comments on commit 13a3ace

Please sign in to comment.