Skip to content

Commit d51eddd

Browse files
committed
-c ls-studysections to show tables with unique fields in dicom series
1 parent 49cb77d commit d51eddd

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

heudiconv/cli/run.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ def get_parser():
134134
'--command',
135135
choices=(
136136
'heuristics', 'heuristic-info',
137-
'ls', 'populate-templates',
137+
'ls', 'ls-studysessions',
138+
'populate-templates',
138139
'sanitize-jsons', 'treat-jsons',
139140
'populate-intended-for'
140141
),

heudiconv/main.py

+40
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,46 @@ def process_extra_commands(outdir, command, files, dicom_dir_template,
9494
"\t%s %d sequences%s"
9595
% (str(study_session), len(sequences), suf)
9696
)
97+
elif command == 'ls-studysessions':
98+
ensure_heuristic_arg(heuristic)
99+
heuristic = load_heuristic(heuristic)
100+
# heuristic_ls = getattr(heuristic, 'ls', None)
101+
study_sessions = get_study_sessions(
102+
dicom_dir_template, files, heuristic, outdir,
103+
session, subjs, grouping=grouping)
104+
for ss, seqinfos in study_sessions.items():
105+
print(f"{ss}:")
106+
# deduce unique attributes
107+
from heudiconv.utils import get_dicts_intersection
108+
seqinfo_dicts = [s._asdict() for s in seqinfos]
109+
common_seqinfo = get_dicts_intersection(seqinfo_dicts)
110+
111+
diff_seqinfo = []
112+
for sd in seqinfo_dicts:
113+
diff = {
114+
k: v for k, v in sd.items()
115+
if (k not in common_seqinfo) and
116+
(k not in {'total_files_till_now', 'series_uid'})}
117+
# some transformations might be needed to please pyout
118+
for k, v in diff.items():
119+
if isinstance(v, tuple):
120+
diff[k] = ', '.join(v)
121+
diff_seqinfo.append(diff)
122+
123+
if diff_seqinfo == [{}]:
124+
print(f" only common: {common_seqinfo}")
125+
continue
126+
from pyout import Tabular
127+
with Tabular(
128+
columns=['example_dcm_file', 'series_files', 'series_id', 'protocol_name', 'series_description'],
129+
style={"header_": dict(bold=True,),
130+
"example_dcm_file": dict(bold=True,),
131+
"image_type": dict(transform=str)},
132+
mode='final'
133+
) as out:
134+
for diffs, files in zip(diff_seqinfo, seqinfos.values()):
135+
out(diffs)
136+
# print(f"{path_id} {diffs}")
97137
elif command == 'populate-templates':
98138
ensure_heuristic_arg(heuristic)
99139
heuristic = load_heuristic(heuristic)

0 commit comments

Comments
 (0)