Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: add HeudiconvVersion to sidecar .json files #529

Merged
merged 1 commit into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions heudiconv/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
is_readonly,
get_datetime,
)
from . import __version__

lgr = logging.getLogger(__name__)

Expand All @@ -40,6 +41,10 @@
("Description", "md5 hash of UIDs")])),
])

#: JSON Key where we will embed our version in the newly produced .json files
HEUDICONV_VERSION_JSON_KEY = 'HeudiconvVersion'


class BIDSError(Exception):
pass

Expand Down Expand Up @@ -244,6 +249,10 @@ def tuneup_bids_json_files(json_files):
# Let's hope no word 'Date' comes within a study name or smth like
# that
raise ValueError("There must be no dates in .json sidecar")
# Those files should not have our version field already - should have been
# freshly produced
assert HEUDICONV_VERSION_JSON_KEY not in json_
json_[HEUDICONV_VERSION_JSON_KEY] = str(__version__)
save_json(jsonfile, json_)

# Load the beast
Expand Down
31 changes: 21 additions & 10 deletions heudiconv/tests/test_heuristics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@

from glob import glob
from os.path import join as pjoin, dirname
from pathlib import Path
import csv
import re

from .. import __version__
from ..bids import HEUDICONV_VERSION_JSON_KEY
from ..utils import load_json

import pytest
from .utils import TESTS_DATA_PATH

Expand Down Expand Up @@ -140,16 +145,22 @@ def test_scout_conversion(tmpdir):
).split(' ') + ['-o', tmppath]
runner(args)

assert not op.exists(pjoin(
tmppath,
'Halchenko/Yarik/950_bids_test4/sub-phantom1sid1/ses-localizer/anat'))

assert op.exists(pjoin(
tmppath,
'Halchenko/Yarik/950_bids_test4/sourcedata/sub-phantom1sid1/'
'ses-localizer/anat/sub-phantom1sid1_ses-localizer_scout.dicom.tgz'
)
)
dspath = Path(tmppath) / 'Halchenko/Yarik/950_bids_test4'
sespath = dspath / 'sub-phantom1sid1/ses-localizer'

assert not (sespath / 'anat').exists()
assert (
dspath /
'sourcedata/sub-phantom1sid1/ses-localizer/'
'anat/sub-phantom1sid1_ses-localizer_scout.dicom.tgz'
).exists()

# Let's do some basic checks on produced files
j = load_json(sespath / 'fmap/sub-phantom1sid1_ses-localizer_acq-3mm_phasediff.json')
# We store HeuDiConv version in each produced .json file
# TODO: test that we are not somehow overwritting that version in existing
# files which we have not produced in a particular run.
assert j[HEUDICONV_VERSION_JSON_KEY] == __version__


@pytest.mark.parametrize(
Expand Down