Skip to content

Commit 9a83bfe

Browse files
authored
Merge pull request #130 from dartmouth-pbs/rf-heuristics-inside
RF+ENH: Move heuristics/ to become a heudiconv.heuristics submodule
2 parents 428242c + ace129e commit 9a83bfe

26 files changed

+290
-82
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ install:
3636
- git config --global user.name "Travis Almighty"
3737

3838
script:
39-
- coverage run `which py.test` -s -v tests heuristics/*.py
39+
- coverage run `which py.test` -s -v tests heudiconv/heuristics/*.py
4040

4141
after_success:
4242
- codecov

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ First release after major refactor
1414
- `Dockerfile` is generated by [neurodocker](https://github.com/kaczmarj/neurodocker)
1515
- Logging verbosity reduced
1616
- Increased leniency with missing DICOM fields
17+
- dbic_bids heuristic renamed into reproin
1718
### Removed
1819
### Deprecated
1920
### Fixed

Makefile

Lines changed: 0 additions & 15 deletions
This file was deleted.

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ provided to address various use-cases
2525

2626
- the [cmrr_heuristic](heuristics/cmrr_heuristic.py) provides an
2727
example for a conversion to [BIDS]
28-
- the [dbic_bids](heuristics/dbic_bids.py) could be used to establish
28+
- the [reproin](heuristics/reproin.py) could be used to establish
2929
a complete imaging center wide automation to convert all acquired
3030
data to [BIDS] following a simple naming
3131
[convention](https://goo.gl/o0YASC) for studies and sequences
@@ -35,19 +35,19 @@ provided to address various use-cases
3535
### Released versions
3636

3737
Released versions of HeuDiConv are available from PyPI so you could
38-
just `pip install heudiconv` but it would require manual installation
38+
just `pip install heudiconv[all]` for the most complete installation,
39+
and it would require manual installation ony
3940
of the [dcm2niix](https://github.com/rordenlab/dcm2niix/). On
4041
Debian-based systems we recommend to use
4142
[NeuroDebian](http://neuro.debian.net) providing
4243
[heudiconv Debian package](http://neuro.debian.net/pkgs/heudiconv.html).
4344

4445
### From source
4546

46-
You can clone this directory and do a `make install`
47+
You can clone this directory and use `pip install .[all]` (with `--user`,
48+
`-e` and other flags appropriate for your case), or
4749

48-
or `pip install https://github.com/nipy/heudiconv/archive/master.zip`
49-
50-
as long as the following dependencies are in your path you can use the package
50+
`pip install https://github.com/nipy/heudiconv/archive/master.zip`
5151

5252
## Dependencies
5353

@@ -57,6 +57,10 @@ as long as the following dependencies are in your path you can use the package
5757
- nibabel
5858
- dcm2niix
5959

60+
and should be checked/installed during `pip install` call, all but `dcm2niix`
61+
which should be installed directly from upstream or using the distribution
62+
manager appropriate for your OS.
63+
6064
## Tutorial with example conversion to BIDS format using Docker
6165
Please read this tutorial to understand how heudiconv works in practice.
6266

heudiconv/cli/run.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def process_extra_commands(outdir, args):
6060
for f in args.files:
6161
treat_infofile(f)
6262
elif args.command == 'ls':
63-
heuristic = load_heuristic(op.realpath(args.heuristic_file))
63+
heuristic = load_heuristic(args.heuristic)
6464
heuristic_ls = getattr(heuristic, 'ls', None)
6565
for f in args.files:
6666
study_sessions = get_study_sessions(
@@ -76,11 +76,21 @@ def process_extra_commands(outdir, args):
7676
% (str(study_session), len(sequences), suf)
7777
)
7878
elif args.command == 'populate-templates':
79-
heuristic = load_heuristic(op.realpath(args.heuristic_file))
79+
heuristic = load_heuristic(args.heuristic)
8080
for f in args.files:
8181
populate_bids_templates(f, getattr(heuristic, 'DEFAULT_FIELDS', {}))
8282
elif args.command == 'sanitize-jsons':
8383
tuneup_bids_json_files(args.files)
84+
elif args.command == 'heuristics':
85+
from ..utils import get_known_heuristics_with_descriptions
86+
for name_desc in get_known_heuristics_with_descriptions().items():
87+
print("- %s: %s" % name_desc)
88+
elif args.command == 'heuristic-info':
89+
from ..utils import get_heuristic_description, get_known_heuristic_names
90+
if not args.heuristic:
91+
raise ValueError("Specify heuristic using -f. Known are: %s"
92+
% ', '.join(get_known_heuristic_names()))
93+
print(get_heuristic_description(args.heuristic, full=True))
8494
else:
8595
raise ValueError("Unknown command %s", args.command)
8696
return
@@ -149,9 +159,11 @@ def get_parser():
149159
'DICOMs to anonymized IDs. Such command must take a '
150160
'single argument and return a single anonymized ID. '
151161
'Also see --conv-outdir')
152-
parser.add_argument('-f', '--heuristic', dest='heuristic_file',
153-
required=True,
154-
help='python script containing heuristic')
162+
parser.add_argument('-f', '--heuristic', dest='heuristic',
163+
# some commands might not need heuristic
164+
# required=True,
165+
help='Name of a known heuristic or path to the Python'
166+
'script containing heuristic')
155167
parser.add_argument('-p', '--with-prov', action='store_true',
156168
help='Store additional provenance information. '
157169
'Requires python-rdflib.')
@@ -174,8 +186,11 @@ def get_parser():
174186
help='Do not catch exceptions and show exception '
175187
'traceback')
176188
parser.add_argument('--command',
177-
choices=('ls', 'populate-templates',
178-
'treat-jsons', 'sanitize-jsons'),
189+
choices=(
190+
'heuristics', 'heuristic-info',
191+
'ls', 'populate-templates',
192+
'sanitize-jsons', 'treat-jsons',
193+
),
179194
help='custom actions to be performed on provided '
180195
'files instead of regular operation.')
181196
parser.add_argument('-g', '--grouping', default='studyUID',
@@ -203,19 +218,20 @@ def process_args(args):
203218
# pre-process provided list of files and possibly sort into groups/sessions
204219
# Group files per each study/sid/session
205220

206-
lgr.info(INIT_MSG(packname=__packagename__,
207-
version=__version__))
208-
209221
outdir = op.abspath(args.outdir)
210222

211223
if args.command:
212224
process_extra_commands(outdir, args)
213225
return
214226

227+
lgr.info(INIT_MSG(packname=__packagename__,
228+
version=__version__))
229+
230+
215231
#
216232
# Load heuristic -- better do it asap to make sure it loads correctly
217233
#
218-
heuristic = load_heuristic(op.realpath(args.heuristic_file))
234+
heuristic = load_heuristic(args.heuristic)
219235

220236
study_sessions = get_study_sessions(args.dicom_dir_template, args.files,
221237
heuristic, outdir, args.session,

heudiconv/heuristics/__init__.py

Whitespace-only changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)