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

Add BIDSJSONFile #444

Merged
merged 8 commits into from
Jul 11, 2019
Merged

Add BIDSJSONFile #444

merged 8 commits into from
Jul 11, 2019

Conversation

tyarkoni
Copy link
Collaborator

Adds a BIDSJSONFile to the BIDSFile hierarchy. This introduces .get_dict() and .get_json() methods that return the contents of a .json file. See #442 for discussion.

@tyarkoni tyarkoni requested a review from yarikoptic May 14, 2019 17:30
Copy link
Collaborator

@yarikoptic yarikoptic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just added a few suggestions.

So this is only a preamble to get #442 "addressed"?

(git-annex)hopa:~/datalad/openfmri/ds000001[master]git
$> python -c "from pprint import pprint; import bids; b = bids.BIDSLayout('.'); print('Version: ', bids.__version__); pprint(b.get_metadata('dataset_description.json'))"
('Version: ', '0.8.0+208.g5860e4f')
{}
$> python -c "from pprint import pprint; import bids; b = bids.BIDSLayout('.'); print('Version: ', bids.__version__); pprint(b.get_metadata('$PWD/dataset_description.json'))"
('Version: ', '0.8.0+208.g5860e4f')                                                                                                          
{}

bids/layout/models.py Outdated Show resolved Hide resolved
j = jf.get_json()
assert isinstance(j, six.string_types)
assert 'RepetitionTime' in j
assert json.loads(j) == d
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a test specifically on dataset_description.json would be great

@codecov
Copy link

codecov bot commented May 14, 2019

Codecov Report

Merging #444 into master will increase coverage by 0.89%.
The diff coverage is 91.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #444      +/-   ##
==========================================
+ Coverage   82.61%   83.51%   +0.89%     
==========================================
  Files          23       23              
  Lines        2848     3039     +191     
  Branches      718      829     +111     
==========================================
+ Hits         2353     2538     +185     
- Misses        314      321       +7     
+ Partials      181      180       -1
Flag Coverage Δ
#unittests 83.51% <91.66%> (+0.89%) ⬆️
Impacted Files Coverage Δ
bids/layout/__init__.py 100% <100%> (ø) ⬆️
bids/layout/layout.py 87.81% <100%> (+3.66%) ⬆️
bids/layout/models.py 89.55% <80%> (-0.4%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a833393...2ee727a. Read the comment docs.

@tyarkoni
Copy link
Collaborator Author

Re: getting #442 addressed, I'm not sure I follow... as I said in the other thread, I see the fact that get_metadata() returns nothing now as expected behavior. The metadata contained inside JSON sidecars describes other files, not the JSON file itself. So to my mind it makes sense that calling get_metadata() on a JSON file should return nothing. The .get_dict and get_json methods are intended as substitutes for get_metadata in this particular use case, not as an implementation layer.

@yarikoptic
Copy link
Collaborator

ah, ok, gotcha.

The metadata contained inside JSON sidecars describes other files, not the JSON file itself.

although generally the case, with dataset_description.json I could argue it is different since it describes the entire dataset, so this metadata is relevant to all files, including meta- data in the dataset, and thus itself as well.

So now I would need to use explicitly BIDSJSONFile('./dataset_description.json').get_dict() to get metadata pertinent to entire dataset or there is another shorter/easier way?
Sorry for the RTFM level questions ;)

@tyarkoni
Copy link
Collaborator Author

tyarkoni commented May 14, 2019

For the special case of dataset_description.json, I think it's reasonable to have a BIDSLayout-level method, as that's a special file in the spec itself. What do you think it should be called? get_dataset_description()?

Edit: or maybe just .describe()?

@yarikoptic
Copy link
Collaborator

I kinda liked get_dataset_description since it is matching what it would do ;)

But I also wondered, that get_metadata without path being provided (change to have path=None in get_metadata signature) could serve the same purpose and make sense. So without specific path - get dataset level metadata. Question though -- would it stay consistent with how information is queried/presented from derivatives/, i.e. e.g. how would then I get such description about specific derivative? may be then if path points to a top directory of the dataset?

@tyarkoni
Copy link
Collaborator Author

tyarkoni commented May 14, 2019

I'm not crazy about the idea of making get_metadata() with path=None return layout-level metadata. Especially because you're right that it would make getting derivatives descriptions complicated. If we add a get_dataset_description() method, we can then just add a scope argument that wraps the _get_layouts_in_scope helper, which is the pattern I use everywhere else. I think this would be both more consistent with the existing API and cleaner implementationally.

@tyarkoni
Copy link
Collaborator Author

@yarikoptic please check to make sure this implementation of get_dataset_description() works for you.

@tyarkoni
Copy link
Collaborator Author

tyarkoni commented Jul 8, 2019

@yarikoptic just pinging you about this... totally fine if you don't have time to look it over. I'm happy with it and can merge as-is.

@effigies
Copy link
Collaborator

@yarikoptic Care to have another review?

@effigies effigies added this to the 0.9.2 milestone Jul 10, 2019
@yarikoptic
Copy link
Collaborator

Oh, sorry for missing the pings! I will check how things work out for datalad-neuroimaging later today - away from the laptop ATM

@effigies
Copy link
Collaborator

Hi @yarikoptic, did you get a chance to test this out?

@yarikoptic
Copy link
Collaborator

doing it now, if you don't hear from me within an hour -- forget I exist and proceed forward and I will show my "pretty" face later on ;-)

@yarikoptic
Copy link
Collaborator

ok, initial wave -- made datalad-neuroimaging compatible with current branch by using get_dataset_description and tuning up the tests. PR: datalad/datalad-neuroimaging#70

will try now on some openneuro dataset to see what potentially has changed in the output

@yarikoptic
Copy link
Collaborator

ran into some other gotchas, will report on that separately -- don't wait! carry on (feel welcomed to merge, sorry for the delays!)

@effigies
Copy link
Collaborator

Sounds good. Thanks for the review.

@effigies effigies merged commit 7f7e039 into master Jul 11, 2019
@effigies effigies deleted the bids-json-file branch July 11, 2019 22:33
@yarikoptic
Copy link
Collaborator

just for my own sake -- tested on ds00258. Differences from using 0.8 just added extension and absent probably bogus super precise float

@@ -4456,10 +4458,11 @@
       2.38766666667,
       1.15266666667
     ],
-    "SpacingBetweenSlices": 4.840000000000001,
+    "SpacingBetweenSlices": 4.84,
     "TaskName": "rest",
     "datatype": "func",
     "echo": "2",
+    "extension": "nii.gz",
     "subject": "04570",
     "suffix": "bold",
     "task": "rest"

differences from some prior (0.5...?) version (to 0.8 and this) include loss of metadata from derivatives folders... I guess we needed to adjust more ;-)

yarikoptic added a commit to neurodebian/pybids that referenced this pull request Aug 1, 2019
Version 0.9.2 (July 12, 2019)

This version includes a number of minor fixes and improvements.
EEG files are better handled, and `BIDSLayout` and `BIDSFile` play more
nicely with `Path`-like objects.

With thanks to new contributor Cecile Madjar.

* FIX: Instantiate `ignore`/`force_index` after root validation (bids-standard#457)
* FIX: Restore `<entity>=None` query returning files lacking the entity (bids-standard#458)
* ENH: Add `BIDSJSONFile` (bids-standard#444)
* ENH: Add `BIDSFile.__fspath__` to work with pathlib (bids-standard#449)
* ENH: Add `eeg` datatype to layout config (bids-standard#455)
* RF: Remove unused kwargs to BIDSFile (bids-standard#443)
* DOC: Improve docstring consistency, style (bids-standard#443)
* DOC: Address final JOSS review (bids-standard#453)
* STY: PEP8 Fixes (bids-standard#456)
* MAINT: Set name explicitly in setup.py (bids-standard#450)

* tag '0.9.2': (318 commits)
  MAINT: Update changelog, Zenodo ordering
  fix(BIDSLayout): more readable query building
  tst(BIDSLayout): add two more tests to the entity=None case
  FIX: Allow None to select for the absence of a tag
  TEST: Verify entity=None fails to find files lacking that entity
  FIX: Instantiate ignore/force_index after root validation
  fix test
  revert turning '==' into 'is'
  pep8 fixes
  fix typo in docstring
  fix typo and added eeg to the config bids.json file
  TEST: Expect failure on Python < 3.6
  TEST: Verify Path can accept a BIDSFile
  ENH: Add BIDSFile.__fspath__ to work with pathlib
  DOC: Fix BIDS citation
  DOC: Spaces around emdashes, italicize e.g., i.e.
  DOC: Drop Zenodo reference
  DOC: Update bibliography file with eye to formatting
  fix name in setup.py so used-by count works; h/t @effigies
  DOC: Add PyPI badge for latest version available
  ...
yarikoptic added a commit to yarikoptic/datalad-neuroimaging that referenced this pull request Aug 12, 2019
yarikoptic added a commit to yarikoptic/datalad-neuroimaging that referenced this pull request Aug 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants