Skip to content

Commit

Permalink
Also track exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelzwiers committed Sep 29, 2023
1 parent 008011d commit 36492df
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 116 deletions.
23 changes: 15 additions & 8 deletions bidscoin/bcoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ def test_bidscoin(bidsmapfile: Union[Path,dict], options: dict=None, testplugins

if not success:
LOGGER.warning('Not all tests finishd successfully (this may be ok, but check the output above)')
trackusage('bidscoin_error')
else:
LOGGER.success('All tests finished successfully :-)')

Expand Down Expand Up @@ -557,6 +558,7 @@ def pulltutorialdata(tutorialfolder: str) -> None:
LOGGER.success(f"Done")
except Exception as unpackerror:
LOGGER.error(f"Could not unpack: {tutorialtargz}\n{unpackerror}")
trackusage('bidscoin_error')


def settracking(value: str):
Expand Down Expand Up @@ -596,14 +598,19 @@ def main():
# Parse the input arguments and run bidscoiner(args)
args = get_parser().parse_args(None if sys.argv[1:] else ['--help'])

list_executables(show=args.list)
list_plugins(show=args.plugins)
uninstall_plugins(filenames=args.uninstall)
install_plugins(filenames=args.install)
pulltutorialdata(tutorialfolder=args.download)
test_bidscoin(bidsmapfile=args.test)
test_bidsmap(bidsmapfile=args.bidsmaptest)
settracking(value=args.tracking)
try:
list_executables(show=args.list)
list_plugins(show=args.plugins)
uninstall_plugins(filenames=args.uninstall)
install_plugins(filenames=args.install)
pulltutorialdata(tutorialfolder=args.download)
test_bidscoin(bidsmapfile=args.test)
test_bidsmap(bidsmapfile=args.bidsmaptest)
settracking(value=args.tracking)

except Exception:
trackusage('bidscoin_exception')
raise


if __name__ == "__main__":
Expand Down
25 changes: 15 additions & 10 deletions bidscoin/bidsapps/deface.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,22 @@ def main():

from bidscoin.cli._deface import get_parser

trackusage('deface')

args = get_parser().parse_args()
deface(bidsdir = args.bidsfolder,
pattern = args.pattern,
subjects = args.participant_label,
force = args.force,
output = args.output,
cluster = args.cluster,
nativespec = args.nativespec,
kwargs = args.args)

trackusage('deface')
try:
deface(bidsdir = args.bidsfolder,
pattern = args.pattern,
subjects = args.participant_label,
force = args.force,
output = args.output,
cluster = args.cluster,
nativespec = args.nativespec,
kwargs = args.args)

except Exception:
trackusage('deface_exception')
raise


if __name__ == '__main__':
Expand Down
23 changes: 14 additions & 9 deletions bidscoin/bidsapps/echocombine.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,22 @@ def main():

from bidscoin.cli._echocombine import get_parser

trackusage('echocombine')

# Parse the input arguments and run bidscoiner(args)
args = get_parser().parse_args()
echocombine(bidsdir = args.bidsfolder,
pattern = args.pattern,
subjects = args.participant_label,
output = args.output,
algorithm = args.algorithm,
weights = args.weights,
force = args.force)

trackusage('echocombine')
try:
echocombine(bidsdir = args.bidsfolder,
pattern = args.pattern,
subjects = args.participant_label,
output = args.output,
algorithm = args.algorithm,
weights = args.weights,
force = args.force)

except Exception:
trackusage('echocombine_exception')
raise


if __name__ == '__main__':
Expand Down
27 changes: 16 additions & 11 deletions bidscoin/bidsapps/medeface.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,23 @@ def main():

from bidscoin.cli._medeface import get_parser

trackusage('medeface')

args = get_parser().parse_args()
medeface(bidsdir = args.bidsfolder,
pattern = args.pattern,
maskpattern = args.maskpattern,
subjects = args.participant_label,
force = args.force,
output = args.output,
cluster = args.cluster,
nativespec = args.nativespec,
kwargs = args.args)

trackusage('medeface')
try:
medeface(bidsdir = args.bidsfolder,
pattern = args.pattern,
maskpattern = args.maskpattern,
subjects = args.participant_label,
force = args.force,
output = args.output,
cluster = args.cluster,
nativespec = args.nativespec,
kwargs = args.args)

except Exception:
trackusage('medeface_exception')
raise


if __name__ == '__main__':
Expand Down
25 changes: 15 additions & 10 deletions bidscoin/bidsapps/skullstrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,22 @@ def main():

from bidscoin.cli._skullstrip import get_parser

trackusage('skullstrip')

args = get_parser().parse_args()
skullstrip(bidsdir = args.bidsfolder,
pattern = args.pattern,
subjects = args.participant_label,
masked = args.masked,
output = args.output,
force = args.force,
args = args.args,
cluster = args.cluster)

trackusage('skullstrip')
try:
skullstrip(bidsdir = args.bidsfolder,
pattern = args.pattern,
subjects = args.participant_label,
masked = args.masked,
output = args.output,
force = args.force,
args = args.args,
cluster = args.cluster)

except Exception:
trackusage('skullstrip_exception')
raise


if __name__ == '__main__':
Expand Down
35 changes: 20 additions & 15 deletions bidscoin/bidsapps/slicereport.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,22 +278,27 @@ def main():

from bidscoin.cli._slicereport import get_parser

trackusage('slicereport')

args = get_parser().parse_args()
slicereport(bidsdir = args.bidsfolder,
pattern = args.pattern,
outlinepattern = args.outlinepattern,
outlineimage = args.outlineimage,
subjects = args.participant_label,
reportdir = args.reportfolder,
crossdirs = args.xlinkfolder,
qccols = args.qcscores,
cluster = args.cluster,
options = args.options,
outputs = args.outputs,
suboptions = args.suboptions,
suboutputs = args.suboutputs)

trackusage('slicereport')
try:
slicereport(bidsdir = args.bidsfolder,
pattern = args.pattern,
outlinepattern = args.outlinepattern,
outlineimage = args.outlineimage,
subjects = args.participant_label,
reportdir = args.reportfolder,
crossdirs = args.xlinkfolder,
qccols = args.qcscores,
cluster = args.cluster,
options = args.options,
outputs = args.outputs,
suboptions = args.suboptions,
suboutputs = args.suboutputs)

except Exception:
trackusage('slicereport_exception')
raise


if __name__ == '__main__':
Expand Down
16 changes: 10 additions & 6 deletions bidscoin/bidscoiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,16 @@ def main():
args = get_parser().parse_args()

trackusage('bidscoiner')

bidscoiner(rawfolder = args.sourcefolder,
bidsfolder = args.bidsfolder,
subjects = args.participant_label,
force = args.force,
bidsmapfile = args.bidsmap)
try:
bidscoiner(rawfolder = args.sourcefolder,
bidsfolder = args.bidsfolder,
subjects = args.participant_label,
force = args.force,
bidsmapfile = args.bidsmap)

except Exception:
trackusage('bidscoiner_exception')
raise


if __name__ == "__main__":
Expand Down
12 changes: 8 additions & 4 deletions bidscoin/bidseditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1693,10 +1693,14 @@ def main():
args = get_parser().parse_args()

trackusage('bidseditor')

bidseditor(bidsfolder = args.bidsfolder,
bidsmapfile = args.bidsmap,
templatefile = args.template)
try:
bidseditor(bidsfolder = args.bidsfolder,
bidsmapfile = args.bidsmap,
templatefile = args.template)

except Exception:
trackusage('bidseditor_exception')
raise


if __name__ == '__main__':
Expand Down
30 changes: 17 additions & 13 deletions bidscoin/bidsmapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,23 @@ def main():
args = get_parser().parse_args()

trackusage('bidsmapper')

bidsmapper(rawfolder = args.sourcefolder,
bidsfolder = args.bidsfolder,
bidsmapfile = args.bidsmap,
templatefile = args.template,
plugins = args.plugins,
subprefix = args.subprefix,
sesprefix = args.sesprefix,
unzip = args.unzip,
store = args.store,
noeditor = args.automated,
force = args.force,
noupdate = args.no_update)
try:
bidsmapper(rawfolder = args.sourcefolder,
bidsfolder = args.bidsfolder,
bidsmapfile = args.bidsmap,
templatefile = args.template,
plugins = args.plugins,
subprefix = args.subprefix,
sesprefix = args.sesprefix,
unzip = args.unzip,
store = args.store,
noeditor = args.automated,
force = args.force,
noupdate = args.no_update)

except Exception:
trackusage('bidsmapper_exception')
raise


if __name__ == "__main__":
Expand Down
19 changes: 12 additions & 7 deletions bidscoin/utilities/bidsparticipants.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,19 @@ def main():

from bidscoin.cli._bidsparticipants import get_parser

trackusage('bidsparticipants')

args = get_parser().parse_args()
bidsparticipants(rawfolder = args.sourcefolder,
bidsfolder = args.bidsfolder,
keys = args.keys,
bidsmapfile = args.bidsmap,
dryrun = args.dryrun)

trackusage('bidsparticipants')
try:
bidsparticipants(rawfolder = args.sourcefolder,
bidsfolder = args.bidsfolder,
keys = args.keys,
bidsmapfile = args.bidsmap,
dryrun = args.dryrun)

except Exception:
trackusage('bidsparticipants_exception')
raise


if __name__ == "__main__":
Expand Down
29 changes: 18 additions & 11 deletions bidscoin/utilities/dicomsort.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def construct_name(scheme: str, dicomfile: Path, force: bool) -> str:
value = int(value.replace('.','')) # Convert the SeriesInstanceUID to an int
if not value and value != 0 and not force:
LOGGER.error(f"Missing '{field}' DICOM field specified in the '{scheme}' folder/naming scheme, cannot find a safe name for: {dicomfile}\n")
trackusage('dicomsort_error')
return ''
else:
schemevalues[field] = value
Expand Down Expand Up @@ -112,6 +113,7 @@ def sortsession(sessionfolder: Path, dicomfiles: List[Path], folderscheme: str,
subfolder = construct_name(folderscheme, dicomfile, force)
if not subfolder:
LOGGER.error('Cannot create subfolders, aborting dicomsort()...')
trackusage('dicomsort_error')
return
if subfolder not in subfolders:
subfolders.append(subfolder)
Expand Down Expand Up @@ -162,7 +164,7 @@ def sortsessions(sourcefolder: Path, subprefix: str='', sesprefix: str='', folde
LOGGER.error(f"Unexpected dicomsource argument '{sourcefolder}', aborting dicomsort()...")
return []
elif not sourcefolder.is_dir():
print(f"Sourcefolder '{sourcefolder}' not found")
LOGGER.error(f"Sourcefolder '{sourcefolder}' not found")
return []
if (folderscheme and not validscheme(folderscheme)) or (namescheme and not validscheme(namescheme)):
LOGGER.error('Wrong scheme input argument(s), aborting dicomsort()...')
Expand Down Expand Up @@ -214,20 +216,25 @@ def main():

from bidscoin.cli._dicomsort import get_parser

trackusage('dicomsort')
args = get_parser().parse_args()

# Set-up logging
bcoin.setup_logging()

args = get_parser().parse_args()
sortsessions(sourcefolder = args.dicomsource,
subprefix = args.subprefix,
sesprefix = args.sesprefix,
folderscheme = args.folderscheme,
namescheme = args.namescheme,
pattern = args.pattern,
force = args.force,
dryrun = args.dryrun)
trackusage('dicomsort')
try:
sortsessions(sourcefolder = args.dicomsource,
subprefix = args.subprefix,
sesprefix = args.sesprefix,
folderscheme = args.folderscheme,
namescheme = args.namescheme,
pattern = args.pattern,
force = args.force,
dryrun = args.dryrun)

except Exception:
trackusage('dicomsort_exception')
raise


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 36492df

Please sign in to comment.