Skip to content

Commit 4688912

Browse files
committed
Create convertall_custom.py as a demonstration for a derived heuristic with custom_seqinfo
1 parent cfdd3d7 commit 4688912

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

heudiconv/heuristics/convertall.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import logging
44
from typing import Optional
55

6-
from heudiconv.dicoms import dw
76
from heudiconv.utils import SeqInfo
87

98
lgr = logging.getLogger("heudiconv")
@@ -19,21 +18,6 @@ def create_key(
1918
return (template, outtype, annotation_classes)
2019

2120

22-
def custom_seqinfo(wrapper: dw.Wrapper, series_files: list[str]) -> tuple[str, str]:
23-
# Just a dummy demo for what custom_seqinfo could get/do
24-
# for already loaded DICOM data, and including storing/returning
25-
# the sample series file as was requested
26-
# in https://github.com/nipy/heudiconv/pull/333
27-
from nibabel.nicom.dicomwrappers import WrapperError
28-
29-
try:
30-
affine = wrapper.affine.tobytes()
31-
except WrapperError:
32-
lgr.exception("Errored out while obtaining/converting affine")
33-
affine = None
34-
return affine, series_files[0]
35-
36-
3721
def infotodict(
3822
seqinfo: list[SeqInfo],
3923
) -> dict[tuple[str, tuple[str, ...], None], list[str]]:
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""A demo convertall heuristic with custom_seqinfo extracting affine and sample DICOM path
2+
3+
This heuristic also demonstrates on how to create a "derived" heuristic which would augment
4+
behavior of an already existing heuristic without complete rewrite. Such approach could be
5+
useful for heuristic like reproin to overload mapping etc.
6+
"""
7+
8+
from .convertall import * # noqa: F403
9+
10+
11+
def custom_seqinfo(series_files, wrapper, **kw): # noqa: U100
12+
"""Demo for extracting custom header fields into custom_seqinfo field
13+
14+
Operates on already loaded DICOM data.
15+
Origin: https://github.com/nipy/heudiconv/pull/333
16+
"""
17+
18+
from nibabel.nicom.dicomwrappers import WrapperError
19+
20+
try:
21+
affine = wrapper.affine.tostring()
22+
except WrapperError:
23+
lgr.exception("Errored out while obtaining/converting affine") # noqa: F405
24+
affine = None
25+
return affine, series_files[0]

0 commit comments

Comments
 (0)