Skip to content

Commit

Permalink
run pre-commit magic!
Browse files Browse the repository at this point in the history
  • Loading branch information
bpinsard committed Jan 16, 2024
1 parent 3cc6fd3 commit b58e47f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ You can run your conversion automatically (which will produce a ``.heudiconv`` d
.. image:: figs/workflow.png


``heudiconv`` comes with `existing heuristics <https://github.com/nipy/heudiconv/tree/master/heudiconv/heuristics>`_ which can be used as is, or as examples.
``heudiconv`` comes with `existing heuristics <https://github.com/nipy/heudiconv/tree/master/heudiconv/heuristics>`_ which can be used as is, or as examples.
For instance, the Heuristic `convertall <https://github.com/nipy/heudiconv/blob/master/heudiconv/heuristics/convertall.py>`_ extracts standard metadata from all matching DICOMs.
``heudiconv`` creates mapping files, ``<something>.edit.text`` which lets researchers simply establish their own conversion mapping.

Expand Down
2 changes: 1 addition & 1 deletion heudiconv/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def prep_conversion(
custom_grouping=getattr(heuristic, "grouping", None),
# callable which will be provided dcminfo and returned
# structure extend seqinfo
custom_seqinfo=getattr(heuristic, 'custom_seqinfo', None),
custom_seqinfo=getattr(heuristic, "custom_seqinfo", None),
)
elif seqinfo is None:
raise ValueError("Neither 'dicoms' nor 'seqinfo' is given")
Expand Down
28 changes: 22 additions & 6 deletions heudiconv/dicoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@
from pathlib import Path
import sys
import tarfile
from typing import TYPE_CHECKING, Any, Dict, Hashable, List, NamedTuple, Optional, Union, Protocol, overload
from typing import (
TYPE_CHECKING,
Any,
Dict,
Hashable,
List,
NamedTuple,
Optional,
Protocol,
Union,
overload,
)
from unittest.mock import patch
import warnings

Expand Down Expand Up @@ -90,14 +101,19 @@ def create_seqinfo(
global total_files
total_files += len(series_files)

custom_seqinfo_data = custom_seqinfo(wrapper=mw, series_files=series_files) \
if custom_seqinfo else None
custom_seqinfo_data = (
custom_seqinfo(wrapper=mw, series_files=series_files)
if custom_seqinfo
else None
)
try:
hash(custom_seqinfo_data)
except TypeError:
raise RuntimeError("Data returned by the heuristics custom_seqinfo is not hashable. "
"See https://heudiconv.readthedocs.io/en/latest/heuristics.html#custom_seqinfo for more "
"details.")
raise RuntimeError(

Check warning on line 112 in heudiconv/dicoms.py

View check run for this annotation

Codecov / codecov/patch

heudiconv/dicoms.py#L111-L112

Added lines #L111 - L112 were not covered by tests
"Data returned by the heuristics custom_seqinfo is not hashable. "
"See https://heudiconv.readthedocs.io/en/latest/heuristics.html#custom_seqinfo for more "
"details."
)

return SeqInfo(
total_files_till_now=total_files,
Expand Down
3 changes: 2 additions & 1 deletion heudiconv/heuristics/convertall.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from heudiconv.dicoms import dw
from heudiconv.utils import SeqInfo

lgr = logging.getLogger('heudiconv')
lgr = logging.getLogger("heudiconv")


def create_key(
Expand All @@ -25,6 +25,7 @@ def custom_seqinfo(wrapper: dw.Wrapper, series_files: list[str]) -> tuple[str, s
# the sample series file as was requested
# in https://github.com/nipy/heudiconv/pull/333
from nibabel.nicom.dicomwrappers import WrapperError

try:
affine = wrapper.affine.tobytes()
except WrapperError:
Expand Down
2 changes: 1 addition & 1 deletion heudiconv/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def get_study_sessions(
file_filter=getattr(heuristic, "filter_files", None),
dcmfilter=getattr(heuristic, "filter_dicom", None),
custom_grouping=getattr(heuristic, "grouping", None),
custom_seqinfo=getattr(heuristic, 'custom_seqinfo', None),
custom_seqinfo=getattr(heuristic, "custom_seqinfo", None),
)

if sids:
Expand Down
8 changes: 3 additions & 5 deletions heudiconv/tests/test_dicoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,12 @@ def test_custom_seqinfo() -> None:
dcmfiles = glob(op.join(TESTS_DATA_PATH, "phantom.dcm"))

seqinfos = group_dicoms_into_seqinfos(
dcmfiles,
"studyUID",
flatten=True,
custom_seqinfo=custom_seqinfo)
dcmfiles, "studyUID", flatten=True, custom_seqinfo=custom_seqinfo
)

seqinfo = list(seqinfos.keys())[0]

assert hasattr(seqinfo, 'custom')
assert hasattr(seqinfo, "custom")
assert isinstance(seqinfo.custom, tuple)
assert len(seqinfo.custom) == 2
assert seqinfo.custom[1] == dcmfiles[0]
Expand Down

0 comments on commit b58e47f

Please sign in to comment.