Skip to content

Commit

Permalink
RF + BF: pmu2bids returns the PhysioData, saved to file in main
Browse files Browse the repository at this point in the history
It modifies `physio2bidsphysio` accordingly.
Addresses second part of #5
  • Loading branch information
pvelasco committed Nov 25, 2020
1 parent 92c016e commit 801c8d4
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def main():
# make sure input files exist:
for infile in args.infiles:
if not os.path.exists(infile):
raise FileNotFoundError( '{i} file not found'.format(i=infile))
raise FileNotFoundError('{i} file not found'.format(i=infile))

# check that the input file is recognized (check extension):
knownExtensions = ['dcm', 'puls', 'resp', 'acq', 'log']
Expand All @@ -97,17 +97,20 @@ def main():
os.makedirs(odir)

# depending on the allowedExtension, call the XXX2bids method of corresponding module:
physio_data = None
if allowedExtensions == 'dcm':
if len(args.infiles) > 1:
raise Exception('Only one input file is allowed for DICOM physio files')
d2bp.dcm2bids( args.infiles, args.bidsprefix, verbose=args.verbose )
physio_data = d2bp.dcm2bids(args.infiles, verbose=args.verbose)
elif allowedExtensions == 'log':
d2bp.dcm2bids(args.infiles, args.bidsprefix, verbose=args.verbose)
physio_data = d2bp.dcm2bids(args.infiles, verbose=args.verbose)
elif allowedExtensions == 'acq':
a2bp.acq2bids( args.infiles, args.bidsprefix )
elif allowedExtensions == ['puls','resp']:
p2bp.pmu2bids( args.infiles, args.bidsprefix, verbose=args.verbose )
physio_data = a2bp.acq2bids(args.infiles)
elif allowedExtensions == ['puls', 'resp']:
physio_data = p2bp.pmu2bids(args.infiles, verbose=args.verbose)

if physio_data.labels():
physio_data.save_to_bids_with_trigger(args.bidsprefix)


# This is the standard boilerplate that calls the main() function.
Expand Down
10 changes: 6 additions & 4 deletions bidsphysio.physio2bids/tests/test_physio2bidsphysio.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest

from bidsphysio.physio2bids import physio2bidsphysio
from bidsphysio.base.bidsphysio import PhysioData
from bidsphysio.acq2bids import acq2bidsphysio as a2bp
from bidsphysio.dcm2bids import dcm2bidsphysio as d2bp
from bidsphysio.pmu2bids import pmu2bidsphysio as p2bp
Expand All @@ -31,16 +32,19 @@ def mock_acq2bids(*args, **kwargs):
print('mock_acq2bids called')
for a in args:
print(a)
return PhysioData()

def mock_dcm2bids(*args, **kwargs):
print('mock_dcm2bids called')
for a in args:
print(a)
return PhysioData()

def mock_pmu2bids(*args, **kwargs):
print('mock_pmu2bids called')
for a in args:
print(a)
return PhysioData()

monkeypatch.setattr(a2bp, "acq2bids", mock_acq2bids)
monkeypatch.setattr(d2bp, "dcm2bids", mock_dcm2bids)
Expand Down Expand Up @@ -95,10 +99,9 @@ def test_main(
monkeypatch.setattr(sys, 'argv', args)
physio2bidsphysio.main()
out = capfd.readouterr().out
printout, inarg, bidsarg, _ = out.split('\n')
printout, inarg, _ = out.split('\n')
assert 'mock_' in printout and '2bids called' in printout
assert infile in inarg
assert bidsarg == bidsPrefix

# also, check that the output folder is created:
assert (tmpdir / 'mydir').exists()
Expand All @@ -124,7 +127,6 @@ def test_main(
monkeypatch.setattr(sys, 'argv', args)
physio2bidsphysio.main()
out = capfd.readouterr().out
printout, inarg, bidsarg, _ = out.split('\n')
printout, inarg, _ = out.split('\n')
assert 'mock_' in printout and '2bids called' in printout
assert inarg == str(multifile)
assert bidsarg == bidsPrefix
Loading

0 comments on commit 801c8d4

Please sign in to comment.