Skip to content

Commit 07b9266

Browse files
committed
Minor tweaks
1 parent 9610601 commit 07b9266

File tree

12 files changed

+15
-29
lines changed

12 files changed

+15
-29
lines changed

bidscoin/bidsapps/slicereport.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# NB: Set os.environ['DUECREDIT'] values as early as possible to capture all credits
55
import os
66
import sys
7-
if __name__ == "__main__" and os.getenv('DUECREDIT_ENABLE','').lower() not in ('1', 'yes', 'true') and len(sys.argv) > 1: # Ideally the due state (`self.__active=True`) should also be checked (but that's impossible)
7+
if __name__ == "__main__" and os.getenv('DUECREDIT_ENABLE','').lower() not in ('1', 'yes', 'true') and len(sys.argv) > 1: # Ideally, the due state (`self.__active=True`) should also be checked (but that's impossible)
88
os.environ['DUECREDIT_ENABLE'] = 'yes'
99
os.environ['DUECREDIT_FILE'] = os.path.join(sys.argv[1], 'code', 'bidscoin', '.duecredit_slicereport.p') # NB: argv[1] = bidsfolder
1010

@@ -44,6 +44,7 @@
4444

4545
JOBIDS = [] # Collect JOBIDS to synchronize DRMAA jobs
4646

47+
4748
def parse_options(options: list) -> str:
4849
"""Check the OPTIONS arguments and return them to a string that can be passed to slicer"""
4950
for n, option in enumerate(options):
@@ -88,7 +89,7 @@ def slicer_append(inputimage: Path, operations: str, outlineimage: Path, mainopt
8889
"""Run fslmaths, slicer and pngappend (locally or on the cluster) to create a montage of the sliced images"""
8990

9091
# Create a workdir and the shell command
91-
workdir = montage.parent/next(tempfile._get_candidate_names())
92+
workdir = montage.parent/f"work_{next(tempfile._get_candidate_names())}"
9293
workdir.mkdir()
9394
inputimg = nib.load(inputimage)
9495
reorient = ''
@@ -110,6 +111,7 @@ def slicer_append(inputimage: Path, operations: str, outlineimage: Path, mainopt
110111
f"pngappend {sliceroutput} {montage.name}\n" \
111112
f"mv {montage.name} {montage.parent}\n" \
112113
+ (f"rm -r {workdir}" if not DEBUG else '')
114+
LOGGER.bcdebug(f"Command: {command}")
113115

114116
# Run the command on the HPC cluster or directly in the shell
115117
if cluster:
@@ -126,12 +128,12 @@ def slicer_append(inputimage: Path, operations: str, outlineimage: Path, mainopt
126128
jt.joinFiles = True
127129
jt.jobName = 'slicereport'
128130
jt.outputPath = f"{os.getenv('HOSTNAME')}:{workdir if DEBUG else tempfile.gettempdir()}/{jt.jobName}.out"
131+
LOGGER.bcdebug(f"nativeSpecification: {cluster} -> {jt.nativeSpecification}")
129132
JOBIDS.append(pbatch.runJob(jt))
130133
pbatch.deleteJobTemplate(jt)
131-
LOGGER.verbose(f"Your '{jt.jobName}' job has been submitted with ID: {JOBIDS[-1]}")
134+
LOGGER.info(f"Your '{jt.jobName}' job has been submitted with ID: {JOBIDS[-1]}")
132135

133136
else:
134-
LOGGER.bcdebug(f"Command: {command}")
135137
process = subprocess.run(command, shell=True, capture_output=True, text=True)
136138
if process.stderr or process.returncode != 0:
137139
LOGGER.warning(f"{command}\nErrorcode {process.returncode}:\n{process.stdout}\n{process.stderr}")
@@ -241,11 +243,11 @@ def slicereport(bidsfolder: str, pattern: str, outlinepattern: str, outlineimage
241243
tsv_writer.writerow([str(session.relative_to(bidsdir))] + len(qcscores) * ['n/a'])
242244

243245
# Search for the (nibabel supported) image(s) to report
244-
LOGGER.info(f"Processing images in: {session.relative_to(bidsdir)}")
245246
images = sorted([match for match in session.glob(pattern) if match.suffixes[0] in valid_exts])
246247
if not images:
247248
LOGGER.warning(f"Could not find images using: {session.relative_to(bidsdir)}/{pattern}")
248249
continue
250+
LOGGER.info(f"Processing {len(images)} images in: {session.relative_to(bidsdir)}")
249251
outlineimages = [''] * len(images)
250252
if outlinepattern:
251253
outlinesession = outlinedir/session.relative_to(bidsdir)

bidscoin/cli/_bcoin.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,11 @@ def get_parser() -> argparse.ArgumentParser:
4444
description=textwrap.dedent(__doc__),
4545
epilog='examples:\n'
4646
' bidscoin -l\n'
47-
' bidscoin -d data/bidscoin_tutorial\n'
47+
' bidscoin -d data/bidscoin\n'
4848
' bidscoin -t\n'
4949
' bidscoin -t my_template_bidsmap\n'
5050
' bidscoin -b my_study_bidsmap\n'
5151
' bidscoin -i data/my_template_bidsmap.yaml downloads/my_plugin.py\n'
52-
' bidscoin -c myproject/bids\n'
5352
' bidscoin -c myproject/bids format bibtex\n'
5453
' bidscoin --tracking show\n ')
5554
parser.add_argument('-l', '--list', help='List all executables (i.e. the apps, bidsapps and utilities)', action='store_true')

bidscoin/utilities/bidsparticipants.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ def bidsparticipants(sourcefolder: str, bidsfolder: str, bidsmap: str='bidsmap.y
3434
raise SystemExit(f"\n[ERROR] Exiting the program because your bidsfolder argument '{bidsfolder}' was not found")
3535

3636
# Start logging
37-
if dryrun:
38-
console = bcoin.setup_logging()
39-
else:
40-
console = bcoin.setup_logging(bidsfolder/'code'/'bidscoin'/'bidsparticipants.log')
37+
console = bcoin.setup_logging(Path() if dryrun else bidsfolder/'code'/'bidscoin'/'bidsparticipants.log')
4138
LOGGER.info('')
4239
LOGGER.info(f"-------------- START bidsparticipants {__version__} ------------")
4340
LOGGER.info(f">>> bidsparticipants sourcefolder={rawfolder} bidsfolder={bidsfolder} bidsmap={bidsmap}")
@@ -73,7 +70,7 @@ def bidsparticipants(sourcefolder: str, bidsfolder: str, bidsmap: str='bidsmap.y
7370
LOGGER.info(f"------------------- Subject {n}/{len(subjects)} -------------------")
7471
personals = {}
7572
subject = rawfolder/subject.name.replace('sub-', subprefix.replace('*','')) # TODO: This assumes e.g. that the subject-ids in the rawfolder did not contain BIDS-invalid characters (such as '_')
76-
sessions = lsdirs(subject, ('' if sesprefix=='*' else sesprefix) + '*')
73+
sessions = lsdirs(subject, ('' if sesprefix == '*' else sesprefix) + '*')
7774
if not subject.is_dir():
7875
LOGGER.error(f"Could not find source-folder: {subject}")
7976
continue

docs/utilities.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,11 @@ The bidscoin command-line utility serves as a central starting point to test and
5151

5252
examples:
5353
bidscoin -l
54-
bidscoin -d data/bidscoin_tutorial
54+
bidscoin -d data/bidscoin
5555
bidscoin -t
5656
bidscoin -t my_template_bidsmap
5757
bidscoin -b my_study_bidsmap
5858
bidscoin -i data/my_template_bidsmap.yaml downloads/my_plugin.py
59-
bidscoin -c myproject/bids
6059
bidscoin -c myproject/bids format bibtex
6160
bidscoin --tracking show
6261

tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
import sys
99
sys.path.append(str(Path(__file__).parents[2]))
1010
from bidscoin.utilities import dicomsort
11+
from bidscoin import bcoin
1112

1213
Path('./.duecredit.p').unlink(missing_ok=True)
13-
14+
bcoin.setup_logging()
1415

1516
@pytest.fixture(scope='session')
1617
def raw_dicomdir(tmp_path_factory):

tests/test_bcoin.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from bidscoin import bcoin
44
from pathlib import Path
55

6-
bcoin.setup_logging()
76

87
assert bidscoin.schemafolder.is_dir()
98
assert bidscoin.templatefolder.is_dir()

tests/test_bids.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
from bidscoin import bcoin, bids, bidsmap_template, bidscoinroot
1111
from bidscoin.bids import BidsMap, RunItem, DataSource, Plugin, Meta
1212

13-
bcoin.setup_logging()
14-
1513

1614
@pytest.fixture(scope='module')
1715
def dcm_file():

tests/test_bidsmapper.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import re
33
from bidscoin import bcoin, bidsmapper, bidsmap_template
44

5-
bcoin.setup_logging()
6-
75

86
@pytest.mark.parametrize('subprefix', ['Doe', 'Doe^', '*'])
97
@pytest.mark.parametrize('sesprefix', ['0', '*'])

tests/test_fixmeta.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import json
22
import shutil
33
from pathlib import Path
4-
from bidscoin import bcoin
54
from bidscoin.bidsapps.fixmeta import fixmeta
65

7-
bcoin.setup_logging()
8-
96

107
def test_fixmeta(tmp_path, test_data):
118

tests/test_heuristics.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import jsonschema
22
import json
33
import yaml
4-
from bidscoin import bcoin, bidscoinroot
5-
6-
bcoin.setup_logging()
4+
from bidscoin import bidscoinroot
75

86

97
def test_jsonschema_validate_bidsmaps():

0 commit comments

Comments
 (0)