Remove code duplication for function `crop_nifti`
Closed this issue · 1 comments
The crop_nifti
function is currently defined in two places:
clinica/clinica/pipelines/t1_linear/anat_linear_utils.py
Lines 59 to 94 in 81e0586
and
clinica/clinica/pipelines/pet_linear/pet_linear_utils.py
Lines 105 to 133 in 81e0586
By a quick inspection, there are exactly the same except that the later was modernized a bit and that the first one returns both the cropped image and the reference.
It would be great to have a single function with a better signature:
def crop_nifti(input_image: Path, reference_image: Path) -> Path:
...
and an adapter task for Nipype:
def crop_nifti_task(input_image: str, reference_image: str) -> str:
return str(crop_nifti(Path(input_image), Path(reference_image)))
Note: I don't think we need to return the reference as it is one of the inputs. Modifying the connections in the related pipeline should do the trick in my opinion.
I'm not sure where to put these as it will be used by PETLinear and T1Linear. Maybe we could have the function in clinica.utils.image
and the adapter within a tasks.py
module under clinica.pipelines
which defines tasks shared by all pipelines ?
I'm reopening because we forgot to add crop_nifti
here:
clinica/clinica/utils/image.py
Lines 9 to 14 in 232d335
@AliceJoubert could you make a small follow-up PR to add it ?