Skip to content

Commit 2f70865

Browse files
committed
Fix numpy docstring styles, use napoleon extension
Not sure if all were needed but most were. Still have 2 warnings locally cannot figure out
1 parent 057c8d3 commit 2f70865

File tree

8 files changed

+69
-82
lines changed

8 files changed

+69
-82
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Please file issues and suggest changes via Pull Requests.
5454

5555
HeuDiConv requires installation of
5656
`dcm2niix <https://github.com/rordenlab/dcm2niix/>`_ and optionally
57-
`DataLad <https://datalad.org>`_.
57+
`DataLad`_.
5858

5959
For development you will need a non-shallow clone (so there is a
6060
recent released tag) of the aforementioned repository. You can then

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
extensions = [
4444
'sphinx.ext.autodoc',
4545
'sphinxarg.ext',
46+
'sphinx.ext.napoleon',
4647
]
4748

4849
# Add any paths that contain templates here, relative to this directory.

docs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
sphinx-argparse
2+
sphinxcontrib-napoleon
23
-r ../dev-requirements.txt

heudiconv/bids.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Handle BIDS specific operations"""
22

3+
__docformat__ = "numpy"
4+
35
import hashlib
46
import os
57
import os.path as op
@@ -415,15 +417,14 @@ def save_scans_key(item, bids_files):
415417

416418

417419
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.
421421
422422
Parameters
423423
----------
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)
427428
"""
428429
if op.lexists(fn):
429430
with open(fn, 'r') as csvfile:
@@ -527,11 +528,11 @@ def get_shim_setting(json_file):
527528
Gets the "ShimSetting" field from a json_file.
528529
If no "ShimSetting" present, return error
529530
530-
Parameters:
531+
Parameters
531532
----------
532533
json_file : str
533534
534-
Returns:
535+
Returns
535536
-------
536537
str with "ShimSetting" value
537538
"""
@@ -552,13 +553,13 @@ def find_fmap_groups(fmap_dir):
552553
By groups here we mean fmaps that are intended to go together
553554
(with reversed PE polarity, magnitude/phase, etc.)
554555
555-
Parameters:
556+
Parameters
556557
----------
557558
fmap_dir : str or os.path
558559
path to the session folder (or to the subject folder, if there are no
559560
sessions).
560561
561-
Returns:
562+
Returns
562563
-------
563564
fmap_groups : dict
564565
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):
598599
(Note: It is the responsibility of the calling function to make sure
599600
the arguments are OK)
600601
601-
Parameters:
602+
Parameters
602603
----------
603604
json_file : str or os.path
604605
path to the json file
605606
matching_parameter : str in AllowedFmapParameterMatching
606607
matching_parameter that will be used to match runs
607608
608-
Returns:
609+
Returns
609610
-------
610611
key_info : dict
611612
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):
666667
(Note: It is the responsibility of the calling function to make sure
667668
the arguments are OK)
668669
669-
Parameters:
670+
Parameters
670671
----------
671672
json_file : str or os.path
672673
path to the json file
@@ -676,7 +677,7 @@ def find_compatible_fmaps_for_run(json_file, fmap_groups, matching_parameters):
676677
matching_parameters : list of str from AllowedFmapParameterMatching
677678
matching_parameters that will be used to match runs
678679
679-
Returns:
680+
Returns
680681
-------
681682
compatible_fmap_groups : dict
682683
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)
720721
(Note: It is the responsibility of the calling function to make sure
721722
the arguments are OK)
722723
723-
Parameters:
724+
Parameters
724725
----------
725726
path_to_bids_session : str or os.path
726727
path to the session folder (or to the subject folder, if there are no
727728
sessions).
728729
matching_parameters : list of str from AllowedFmapParameterMatching
729730
matching_parameters that will be used to match runs
730731
731-
Returns:
732+
Returns
732733
-------
733734
compatible_fmap : dict
734735
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
768769
(Note: It is the responsibility of the calling function to make sure
769770
the arguments are OK)
770771
771-
Parameters:
772+
Parameters
772773
----------
773774
json_file : str or os.path
774775
path to the json file
@@ -777,7 +778,7 @@ def select_fmap_from_compatible_groups(json_file, compatible_fmap_groups, criter
777778
criterion : str in ['First', 'Closest']
778779
matching_parameters that will be used to decide which fmap to use
779780
780-
Returns:
781+
Returns
781782
-------
782783
selected_fmap_key : str or os.path
783784
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):
859860
Because fmaps come in groups (with reversed PE polarity, or magnitude/
860861
phase), we work with fmap_groups.
861862
862-
Parameters:
863+
Parameters
863864
----------
864865
path_to_bids_session : str or os.path
865866
path to the session folder (or to the subject folder, if there are no

heudiconv/convert.py

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
__docformat__ = "numpy"
2+
13
import filelock
24
import os
35
import os.path as op
@@ -453,23 +455,6 @@ def convert(items, converter, scaninfo_suffix, custom_callable, with_prov,
453455
dcmconfig=None, populate_intended_for_opts={}):
454456
"""Perform actual conversion (calls to converter etc) given info from
455457
heuristic's `infotodict`
456-
457-
Parameters
458-
----------
459-
items
460-
symlink
461-
converter
462-
scaninfo_suffix
463-
custom_callable
464-
with_prov
465-
is_bids
466-
sourcedir
467-
outdir
468-
min_meta
469-
470-
Returns
471-
-------
472-
None
473458
"""
474459
prov_files = []
475460
tempdirs = TempDirs()
@@ -624,10 +609,6 @@ def convert_dicom(item_dicoms, bids_options, prefix,
624609
Create softlink to DICOMs - if False, create hardlink instead.
625610
overwrite : bool
626611
If True, allows overwriting of previous conversion
627-
628-
Returns
629-
-------
630-
None
631612
"""
632613
if bids_options is not None:
633614
# mimic the same hierarchy location as the prefix
@@ -666,18 +647,18 @@ def nipype_convert(item_dicoms, prefix, with_prov, bids_options, tmpdir, dcmconf
666647
667648
Parameters
668649
----------
669-
item_dicoms : List
650+
item_dicoms : list
670651
DICOM files to convert
671-
prefix : String
652+
prefix : str
672653
Heuristic output path
673-
with_prov : Bool
654+
with_prov : bool
674655
Store provenance information
675-
bids_options : List or None
656+
bids_options : list or None
676657
If not None then output BIDS sidecar JSONs
677658
List may contain bids specific options
678-
tmpdir : Directory
659+
tmpdir : str
679660
Conversion working directory
680-
dcmconfig : File (optional)
661+
dcmconfig : str, optional
681662
JSON file used for additional Dcm2niix configuration
682663
"""
683664
import nipype
@@ -723,18 +704,19 @@ def nipype_convert(item_dicoms, prefix, with_prov, bids_options, tmpdir, dcmconf
723704

724705
def save_converted_files(res, item_dicoms, bids_options, outtype, prefix, outname_bids, overwrite):
725706
"""Copy converted files from tempdir to output directory.
707+
726708
Will rename files if necessary.
727709
728710
Parameters
729711
----------
730712
res : Node
731713
Nipype conversion Node with results
732-
item_dicoms: list of filenames
733-
DICOMs converted
714+
item_dicoms: list
715+
Filenames of converted DICOMs
734716
bids : list or None
735717
If not list save to BIDS
736718
List may contain bids specific options
737-
prefix : string
719+
prefix : str
738720
739721
Returns
740722
-------
@@ -877,15 +859,13 @@ def save_converted_files(res, item_dicoms, bids_options, outtype, prefix, outnam
877859
return bids_outfiles
878860

879861

880-
def add_taskname_to_infofile(infofiles):
862+
def add_taskname_to_infofile(infofiles):
881863
"""Add the "TaskName" field to json files corresponding to func images.
882864
883865
Parameters
884866
----------
885-
infofiles : list with json filenames or single filename
886-
887-
Returns
888-
-------
867+
infofiles: list or str
868+
json filenames or a single filename.
889869
"""
890870

891871
# in case they pass a string with a path:
@@ -908,15 +888,15 @@ def add_taskname_to_infofile(infofiles):
908888

909889
def bvals_are_zero(bval_file):
910890
"""Checks if all entries in a bvals file are zero (or 5, for Siemens files).
911-
Returns True if that is the case, otherwise returns False
912891
913892
Parameters
914893
----------
915-
bval_file : file with the bvals
894+
bval_file : str
895+
file with the bvals
916896
917897
Returns
918898
-------
919-
True if all are zero; False otherwise.
899+
True if all are all 0 or 5; False otherwise.
920900
"""
921901

922902
with open(bval_file) as f:

heudiconv/parser.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
def find_files(regex, topdir=op.curdir, exclude=None,
3030
exclude_vcs=True, dirs=False):
3131
"""Generator to find files matching regex
32+
3233
Parameters
3334
----------
3435
regex: basestring
@@ -60,7 +61,8 @@ def find_files(regex, topdir=op.curdir, exclude=None,
6061

6162

6263
def get_extracted_dicoms(fl):
63-
"""Given a list of files, possibly extract some from tarballs
64+
"""Given a list of files, possibly extract some from tarballs.
65+
6466
For 'classical' heudiconv, if multiple tarballs are provided, they correspond
6567
to different sessions, so here we would group into sessions and return
6668
pairs `sessionid`, `files` with `sessionid` being None if no "sessions"
@@ -116,13 +118,15 @@ def get_extracted_dicoms(fl):
116118

117119
def get_study_sessions(dicom_dir_template, files_opt, heuristic, outdir,
118120
session, sids, grouping='studyUID'):
119-
"""Given options from cmdline sort files or dicom seqinfos into
120-
study_sessions which put together files for a single session of a subject
121-
in a study
122-
Two major possible workflows:
121+
"""Sort files or dicom seqinfos into study_sessions.
122+
123+
study_sessions put together files for a single session of a subject
124+
in a study. Two major possible workflows:
125+
123126
- if dicom_dir_template provided -- doesn't pre-load DICOMs and just
124127
loads files pointed by each subject and possibly sessions as corresponding
125-
to different tarballs
128+
to different tarballs.
129+
126130
- if files_opt is provided, sorts all DICOMs it can find under those paths
127131
"""
128132
study_sessions = {}

0 commit comments

Comments
 (0)