Skip to content

Commit

Permalink
Refinements
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Apr 11, 2023
1 parent efb554a commit 83f86c4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
15 changes: 4 additions & 11 deletions heudiconv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def process_extra_commands(
outdir: str,
command: str,
files: list[str],
dicom_dir_template: Optional[str],
heuristic: Optional[str],
session: Optional[str],
subjs: Optional[list[str]],
Expand All @@ -75,13 +74,6 @@ def process_extra_commands(
Heudiconv command to run
files : list of str
List of files
dicom_dir_template : str
Location of dicomdir that can be indexed with subject id
{subject} and session {session}. Tarballs (can be compressed)
are supported in addition to directory. All matching tarballs
for a subject are extracted and their content processed in a
single pass. If multiple tarballs are found, each is assumed to
be a separate session and the 'session' argument is ignored.
heuristic : str
Path to heuristic file or name of builtin heuristic.
session : str
Expand All @@ -101,7 +93,7 @@ def process_extra_commands(
heuristic_ls = getattr(heuristic_mod, "ls", None)
for fname in files:
study_sessions = get_study_sessions(
dicom_dir_template,
None,
[fname],
heuristic_mod,
outdir,
Expand All @@ -111,9 +103,10 @@ def process_extra_commands(
)
print(fname)
for study_session, sequences in study_sessions.items():
assert isinstance(sequences, dict)
suf = ""
if heuristic_ls:
suf += heuristic_ls(study_session, sequences)
suf += heuristic_ls(study_session, list(sequences.keys()))
print("\t%s %d sequences%s" % (str(study_session), len(sequences), suf))
elif command == "populate-templates":
ensure_heuristic_arg(heuristic)
Expand Down Expand Up @@ -366,11 +359,11 @@ def workflow(
if command:
if files is None:
raise ValueError("'command' given but 'files' is None")
assert dicom_dir_template is None
process_extra_commands(
outdir,
command,
files,
dicom_dir_template,
heuristic,
session,
subjs,
Expand Down
6 changes: 3 additions & 3 deletions heudiconv/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import re
import shutil
from types import ModuleType
from typing import Any, Optional
from typing import Optional

from .dicoms import group_dicoms_into_seqinfos
from .utils import SeqInfo, StudySessionInfo, TempDirs, docstring_parameter
Expand Down Expand Up @@ -156,7 +156,7 @@ def get_study_sessions(
session: Optional[str],
sids: Optional[list[str]],
grouping: str = "studyUID",
) -> dict[StudySessionInfo, Any]:
) -> dict[StudySessionInfo, list[str] | dict[SeqInfo, list[str]]]:
"""Sort files or dicom seqinfos into study_sessions.
study_sessions put together files for a single session of a subject
Expand All @@ -168,7 +168,7 @@ def get_study_sessions(
- if files_opt is provided, sorts all DICOMs it can find under those paths
"""
study_sessions: dict[StudySessionInfo, Any] = {}
study_sessions: dict[StudySessionInfo, list[str] | dict[SeqInfo, list[str]]] = {}
if dicom_dir_template:
dicom_dir_template = op.abspath(dicom_dir_template)

Expand Down
3 changes: 1 addition & 2 deletions heudiconv/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ def test_populate_intended_for(
bids_folder,
"populate-intended-for",
[],
"",
"example",
session,
subjects,
Expand All @@ -374,7 +373,7 @@ def test_populate_intended_for(
if session:
os.makedirs(opj(subj_dir, "ses-" + session))
process_extra_commands(
outdir, "populate-intended-for", [], "", "example", None, [], "all"
outdir, "populate-intended-for", [], "example", None, [], "all"
)
for s in subjects:
expected_info = 'Adding "IntendedFor" to the fieldmaps in ' + opj(
Expand Down

0 comments on commit 83f86c4

Please sign in to comment.