1
1
"""Handle BIDS specific operations"""
2
2
3
+ __docformat__ = "numpy"
4
+
3
5
import hashlib
4
6
import os
5
7
import os .path as op
@@ -157,12 +159,12 @@ def populate_bids_templates(path, defaults={}):
157
159
158
160
159
161
def populate_aggregated_jsons (path ):
160
- """Aggregate across the entire BIDS dataset .json' s into top level .json' s
162
+ """Aggregate across the entire BIDS dataset `` .json``\ s into top level `` .json``\ s
161
163
162
164
Top level .json files would contain only the fields which are
163
- common to all subject[/session]/type/*_modality.json' s.
165
+ common to all `` subject[/session]/type/*_modality.json``\ s.
164
166
165
- ATM aggregating only for *_task*_bold.json files. Only the task- and
167
+ ATM aggregating only for `` *_task*_bold.json`` files. Only the task- and
166
168
OPTIONAL _acq- field is retained within the aggregated filename. The other
167
169
BIDS _key-value pairs are "aggregated over".
168
170
@@ -415,15 +417,14 @@ def save_scans_key(item, bids_files):
415
417
416
418
417
419
def add_rows_to_scans_keys_file (fn , newrows ):
418
- """
419
- Add new rows to file fn for scans key filename and generate accompanying json
420
- descriptor to make BIDS validator happy.
420
+ """Add new rows to the _scans file.
421
421
422
422
Parameters
423
423
----------
424
- fn: filename
425
- newrows: extra rows to add
426
- dict fn: [acquisition time, referring physician, random string]
424
+ fn: str
425
+ filename
426
+ newrows: dict
427
+ extra rows to add (acquisition time, referring physician, random string)
427
428
"""
428
429
if op .lexists (fn ):
429
430
with open (fn , 'r' ) as csvfile :
@@ -527,11 +528,11 @@ def get_shim_setting(json_file):
527
528
Gets the "ShimSetting" field from a json_file.
528
529
If no "ShimSetting" present, return error
529
530
530
- Parameters:
531
+ Parameters
531
532
----------
532
533
json_file : str
533
534
534
- Returns:
535
+ Returns
535
536
-------
536
537
str with "ShimSetting" value
537
538
"""
@@ -552,13 +553,13 @@ def find_fmap_groups(fmap_dir):
552
553
By groups here we mean fmaps that are intended to go together
553
554
(with reversed PE polarity, magnitude/phase, etc.)
554
555
555
- Parameters:
556
+ Parameters
556
557
----------
557
558
fmap_dir : str or os.path
558
559
path to the session folder (or to the subject folder, if there are no
559
560
sessions).
560
561
561
- Returns:
562
+ Returns
562
563
-------
563
564
fmap_groups : dict
564
565
key: prefix common to the group (e.g. no "dir" entity, "_phase"/"_magnitude", ...)
@@ -598,14 +599,14 @@ def get_key_info_for_fmap_assignment(json_file, matching_parameter):
598
599
(Note: It is the responsibility of the calling function to make sure
599
600
the arguments are OK)
600
601
601
- Parameters:
602
+ Parameters
602
603
----------
603
604
json_file : str or os.path
604
605
path to the json file
605
606
matching_parameter : str in AllowedFmapParameterMatching
606
607
matching_parameter that will be used to match runs
607
608
608
- Returns:
609
+ Returns
609
610
-------
610
611
key_info : dict
611
612
part of the json file that will need to match between the fmap and
@@ -666,7 +667,7 @@ def find_compatible_fmaps_for_run(json_file, fmap_groups, matching_parameters):
666
667
(Note: It is the responsibility of the calling function to make sure
667
668
the arguments are OK)
668
669
669
- Parameters:
670
+ Parameters
670
671
----------
671
672
json_file : str or os.path
672
673
path to the json file
@@ -676,7 +677,7 @@ def find_compatible_fmaps_for_run(json_file, fmap_groups, matching_parameters):
676
677
matching_parameters : list of str from AllowedFmapParameterMatching
677
678
matching_parameters that will be used to match runs
678
679
679
- Returns:
680
+ Returns
680
681
-------
681
682
compatible_fmap_groups : dict
682
683
Subset of the fmap_groups which match json_file, according
@@ -720,15 +721,15 @@ def find_compatible_fmaps_for_session(path_to_bids_session, matching_parameters)
720
721
(Note: It is the responsibility of the calling function to make sure
721
722
the arguments are OK)
722
723
723
- Parameters:
724
+ Parameters
724
725
----------
725
726
path_to_bids_session : str or os.path
726
727
path to the session folder (or to the subject folder, if there are no
727
728
sessions).
728
729
matching_parameters : list of str from AllowedFmapParameterMatching
729
730
matching_parameters that will be used to match runs
730
731
731
- Returns:
732
+ Returns
732
733
-------
733
734
compatible_fmap : dict
734
735
Dict of compatible_fmaps_groups (values) for each non-fmap run (keys)
@@ -768,7 +769,7 @@ def select_fmap_from_compatible_groups(json_file, compatible_fmap_groups, criter
768
769
(Note: It is the responsibility of the calling function to make sure
769
770
the arguments are OK)
770
771
771
- Parameters:
772
+ Parameters
772
773
----------
773
774
json_file : str or os.path
774
775
path to the json file
@@ -777,7 +778,7 @@ def select_fmap_from_compatible_groups(json_file, compatible_fmap_groups, criter
777
778
criterion : str in ['First', 'Closest']
778
779
matching_parameters that will be used to decide which fmap to use
779
780
780
- Returns:
781
+ Returns
781
782
-------
782
783
selected_fmap_key : str or os.path
783
784
key from the compatible_fmap_groups for the selected fmap group
@@ -859,7 +860,7 @@ def populate_intended_for(path_to_bids_session, matching_parameters, criterion):
859
860
Because fmaps come in groups (with reversed PE polarity, or magnitude/
860
861
phase), we work with fmap_groups.
861
862
862
- Parameters:
863
+ Parameters
863
864
----------
864
865
path_to_bids_session : str or os.path
865
866
path to the session folder (or to the subject folder, if there are no
0 commit comments