-
Notifications
You must be signed in to change notification settings - Fork 127
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
RF: embed_nifti -> embed_dicom_and_nifti_metadata and not invoke it if min_meta #432
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3986114
minor: PEP8ing
yarikoptic b8119dc
RF: if min_meta - do not bother calling embed_metadata_from_dicoms
yarikoptic 55c7930
RF (not backward compatible): embed_nifti -> embed_dicom_and_nifti_me…
yarikoptic 7312b70
NF: @assert_cwd_unchanged() to check if test went somewhere else and …
yarikoptic 8935e25
ENH: Use @assert_cwd_unchanged for test_embed_dicom_and_nifti_metadata
yarikoptic 189d0a9
BF: use save_json, not adhoc call to json.dump
yarikoptic cafd968
ENH: no need to copy just loaded meta_info
yarikoptic 4fd4391
ENH(TST): test that we raise NotImplementedError if .nii does not exist
yarikoptic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,12 @@ | |
|
||
from heudiconv.external.pydicom import dcm | ||
from heudiconv.cli.run import main as runner | ||
from heudiconv.dicoms import parse_private_csa_header, embed_nifti | ||
from .utils import TESTS_DATA_PATH | ||
from heudiconv.convert import nipype_convert | ||
from heudiconv.dicoms import parse_private_csa_header, embed_dicom_and_nifti_metadata | ||
from .utils import ( | ||
assert_cwd_unchanged, | ||
TESTS_DATA_PATH, | ||
) | ||
|
||
# Public: Private DICOM tags | ||
DICOM_FIELDS_TO_TEST = { | ||
|
@@ -26,35 +30,37 @@ def test_private_csa_header(tmpdir): | |
runner(['--files', dcm_file, '-c' 'none', '-f', 'reproin']) | ||
|
||
|
||
def test_nifti_embed(tmpdir): | ||
@assert_cwd_unchanged(ok_to_chdir=True) # so we cd back after tmpdir.chdir | ||
def test_embed_dicom_and_nifti_metadata(tmpdir): | ||
"""Test dcmstack's additional fields""" | ||
tmpdir.chdir() | ||
# set up testing files | ||
dcmfiles = [op.join(TESTS_DATA_PATH, 'axasc35.dcm')] | ||
infofile = 'infofile.json' | ||
|
||
# 1) nifti does not exist | ||
out = embed_nifti(dcmfiles, 'nifti.nii', 'infofile.json', None, False) | ||
# string -> json | ||
out = json.loads(out) | ||
# should have created nifti file | ||
assert op.exists('nifti.nii') | ||
out_prefix = str(tmpdir / "nifti") | ||
# 1) nifti does not exist -- no longer supported | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should test that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. easy enough and wortwhile indeed - done in 4fd4391 |
||
with pytest.raises(NotImplementedError): | ||
embed_dicom_and_nifti_metadata(dcmfiles, out_prefix + '.nii.gz', infofile, None) | ||
|
||
# we should produce nifti using our "standard" ways | ||
nipype_out, prov_file = nipype_convert( | ||
dcmfiles, prefix=out_prefix, with_prov=False, | ||
bids_options=None, tmpdir=str(tmpdir)) | ||
niftifile = nipype_out.outputs.converted_files | ||
|
||
assert op.exists(niftifile) | ||
# 2) nifti exists | ||
nifti, info = embed_nifti(dcmfiles, 'nifti.nii', 'infofile.json', None, False) | ||
assert op.exists(nifti) | ||
assert op.exists(info) | ||
with open(info) as fp: | ||
embed_dicom_and_nifti_metadata(dcmfiles, niftifile, infofile, None) | ||
assert op.exists(infofile) | ||
with open(infofile) as fp: | ||
out2 = json.load(fp) | ||
|
||
assert out == out2 | ||
|
||
# 3) with existing metadata | ||
bids = {"existing": "data"} | ||
nifti, info = embed_nifti(dcmfiles, 'nifti.nii', 'infofile.json', bids, False) | ||
with open(info) as fp: | ||
embed_dicom_and_nifti_metadata(dcmfiles, niftifile, infofile, bids) | ||
with open(infofile) as fp: | ||
out3 = json.load(fp) | ||
|
||
assert out3["existing"] | ||
del out3["existing"] | ||
assert out3 == out2 == out | ||
assert out3.pop("existing") == "data" | ||
assert out3 == out2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we keep the same indentation here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was on an edge for this one, and decided that we better do not delay fixing this inconsistency (which we should have done long ago). Especially now since in case of min_meta, file would be saved with our "standard" indentation (of 4), thus differ from this one. So, I decided to stay consistent and just use
save_json
with defaults...but now you made me look at how we use
save_json
and it seems that we preferindent=2
in many places:As a separate PR I will propose making default indent to be
2
and thus removing any "ad-hoc" indent use