Skip to content

Commit

Permalink
[GENFI] add try/except to get EchoTime and RepetitionTime (#934)
Browse files Browse the repository at this point in the history
* add try/except

* Update clinica/iotools/converters/genfi_to_bids/genfi_to_bids_utils.py

Co-authored-by: Gensollen <[email protected]>

* Update clinica/iotools/converters/genfi_to_bids/genfi_to_bids_utils.py

Co-authored-by: Gensollen <[email protected]>

---------

Co-authored-by: Gensollen <[email protected]>
  • Loading branch information
MatthieuJoulot and NicolasGensollen authored Jun 5, 2023
1 parent 5c7010a commit ccd7c7d
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions clinica/iotools/converters/genfi_to_bids/genfi_to_bids_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,25 @@ def _handle_series_description(x: str) -> str:
are supposed to be very different between a T1 and T2. Therefore, we use this proxy to check that the series description is coherent.
The values used are in milliseconds, and have been chosen arbitrarily.
"""
import warnings

MAX_ECHO_TIME_FOR_A_T1 = 60
MAX_REPETITION_TIME_FOR_A_T1 = 2100
series_description = pdcm.dcmread(x).SeriesDescription
if any([modality in series_description.lower() for modality in ["t1", "t2"]]):
echo_time = pdcm.dcmread(x).EchoTime
repetition_time = pdcm.dcmread(x).RepetitionTime
if (
"t2" in series_description.lower()
and echo_time < MAX_ECHO_TIME_FOR_A_T1
and repetition_time < MAX_REPETITION_TIME_FOR_A_T1
):
return "t1"
try:
echo_time = pdcm.dcmread(x).EchoTime
repetition_time = pdcm.dcmread(x).RepetitionTime
if (
"t2" in series_description.lower()
and echo_time < MAX_ECHO_TIME_FOR_A_T1
and repetition_time < MAX_REPETITION_TIME_FOR_A_T1
):
return "t1"
except AttributeError:
warnings.warn(
message=f"The subject from DICOM {Path(x).parent} has no Echo Time or Repetition Time, it might be wrongly converted."
)
return series_description


Expand Down

0 comments on commit ccd7c7d

Please sign in to comment.