Skip to content

Commit

Permalink
Make Anys in SeqInfo into Optional[str] + fix treat_age for None
Browse files Browse the repository at this point in the history
apparently treat_age would have made None into "None" string which maybe_na would
not map to n/a.  So decided to make it more explicit and specific here.
I checked on sample that we do get even time as  "str" from dcmdata, so
should be matching
  • Loading branch information
yarikoptic committed Apr 26, 2023
1 parent 1ca55c9 commit 389811d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
6 changes: 4 additions & 2 deletions heudiconv/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ def maybe_na(val: Any) -> str:
return "n/a"


def treat_age(age: str|float) -> str:
def treat_age(age: str|float|None) -> str|None:
"""Age might encounter 'Y' suffix or be a float"""
if age is None:
return None # might be converted to N/A by maybe_na
agestr = str(age)
if agestr.endswith("M"):
agestr = agestr.rstrip("M")
Expand Down Expand Up @@ -367,7 +369,7 @@ def tuneup_bids_json_files(json_files: list[str]) -> None:
set_readonly(json_phasediffname)


def add_participant_record(studydir: str, subject: str, age: str, sex: str) -> None:
def add_participant_record(studydir: str, subject: str, age: str|None, sex: str|None) -> None:
participants_tsv = op.join(studydir, "participants.tsv")
participant_id = "sub-%s" % subject

Expand Down
1 change: 1 addition & 0 deletions heudiconv/tests/test_bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def test_maybe_na() -> None:


def test_treat_age() -> None:
assert treat_age(None) == None
assert treat_age(0) == "0"
assert treat_age("0") == "0"
assert treat_age("0000") == "0"
Expand Down
14 changes: 7 additions & 7 deletions heudiconv/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ class SeqInfo(NamedTuple):
protocol_name: str # 12
is_motion_corrected: bool # 13
is_derived: bool # 14
patient_id: Any # 15
patient_id: Optional[str] # 15
study_description: str # 16
referring_physician_name: str # 17
series_description: str # 18
sequence_name: str # 19
image_type: tuple[str, ...] # 20
accession_number: str # 21
patient_age: Any # 22
patient_sex: Any # 23
date: Any # 24
series_uid: Any # 25
time: Any # 26
patient_age: Optional[str] # 22
patient_sex: Optional[str] # 23
date: Optional[str] # 24
series_uid: Optional[str] # 25
time: Optional[str] # 26


class StudySessionInfo(NamedTuple):
Expand Down Expand Up @@ -356,7 +356,7 @@ def treat_infofile(filename: str) -> None:
set_readonly(filename)


def slim_down_info(j: Any) -> Any:
def slim_down_info(j: dict[str, Any]) -> dict[str, Any]:
"""Given an aggregated info structure, removes excessive details
Such as CSA fields, and SourceImageSequence which on Siemens files could be
Expand Down

0 comments on commit 389811d

Please sign in to comment.