Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/physiopy/phys2bids into a…
Browse files Browse the repository at this point in the history
…dd/logger
  • Loading branch information
eurunuela committed Jan 27, 2020
2 parents 96026fc + 6daf381 commit 0fef5af
Show file tree
Hide file tree
Showing 8 changed files with 364 additions and 124 deletions.
9 changes: 7 additions & 2 deletions phys2bids/cli/run.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# -*- coding: utf-8 -*-
"""
Parser for phys2bids
"""

import argparse

Expand All @@ -13,10 +16,12 @@ def _get_parser():
-------
parser.parse_args() : argparse dict
"""
parser = argparse.ArgumentParser()
Notes
-----
# Argument parser follow template provided by RalphyZ.
# https://stackoverflow.com/a/43456577
"""
parser = argparse.ArgumentParser()
optional = parser._action_groups.pop()
required = parser.add_argument_group('Required Argument:')
required.add_argument('-in', '--input-file',
Expand Down
17 changes: 16 additions & 1 deletion phys2bids/interfaces/acq.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,22 @@

def populate_phys_input(filename, chtrig):
"""
Populate object phys_input
Populate object phys_input from acq files.
Parameters
----------
filename: str
path to the txt labchart file
chtrig : int
index of trigger channel
Returns
-------
BlueprintInput
See Also
--------
physio_obj.BlueprintInput
"""

data = read_file(filename).channels
Expand Down
15 changes: 10 additions & 5 deletions phys2bids/interfaces/txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,21 @@ def populate_phys_input(filename, chtrig):
"""
Populate object phys_input
for now this works only with labchart files
Input (Properties)
------------------
Parameters
----------
filename: str
path to the txt labchart file
chtrig : int
index of trigger channel
Output
------------------
BlueprintInput object for more see BlueprintInput docs
Returns
-------
BlueprintInput
See Also
--------
physio_obj.BlueprintInput
"""
header = []
channel_list = []
Expand Down
47 changes: 26 additions & 21 deletions phys2bids/phys2bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def print_summary(filename, ntp_expected, ntp_found, samp_freq, time_offset, out
"""
Prints a summary onscreen and in file with informations on the files.
Input
-----
Parameters
----------
filename: str
Name of the input of phys2bids.
ntp_expected: int
Expand All @@ -62,8 +62,9 @@ def print_summary(filename, ntp_expected, ntp_found, samp_freq, time_offset, out
outfile: str or path
Fullpath to output file.
Outcome
-------
Notes
-----
Outcome:
summary: str
Prints the summary on screen
outfile: .log file
Expand All @@ -87,8 +88,8 @@ def print_json(outfile, samp_freq, time_offset, ch_name):
"""
Prints the json required by BIDS format.
Input
-----
Parameters
----------
outfile: str or path
Fullpath to output file.
samp_freq: float
Expand All @@ -98,9 +99,9 @@ def print_json(outfile, samp_freq, time_offset, ch_name):
ch_name: list of str
List of channel names, as specified by BIDS format.
Outcome
-------
Notes
-----
Outcome:
outfile: .json file
File containing information for BIDS.
"""
Expand All @@ -117,8 +118,8 @@ def use_heuristic(heur_file, sub, ses, filename, outdir, record_label=''):
Import the heuristic file specified by the user and uses its output
to rename the file.
Input
-----
Parameters
----------
heur_file: path
Fullpath to heuristic file.
sub: str or int
Expand All @@ -133,28 +134,27 @@ def use_heuristic(heur_file, sub, ses, filename, outdir, record_label=''):
record_label: str
Optional label for the "record" entry of BIDS.
Output
Returns
-------
heurpath: str or path
Returned fullpath to tsv.gz new file (post BIDS formatting).
"""

if sub[:4] != 'sub-':
name = 'sub-' + sub
name = f'sub-{sub}'
else:
name = sub

fldr = outdir + '/' + name
fldr = os.path.join(outdir, name)

if ses:
if ses[:4] != 'ses-':
fldr = fldr + '/ses-' + ses
name = name + '_ses-' + ses
else:
fldr = fldr + '/' + ses
name = name + ses
ses = f'ses-{ses}'

fldr = fldr + '/func'
fldr = os.path.join(fldr, ses)
name = f'{name}_{ses}'

fldr = os.path.join(fldr, 'func')
utils.path_exists_or_make_it(fldr)

cwd = os.getcwd()
Expand All @@ -167,7 +167,7 @@ def use_heuristic(heur_file, sub, ses, filename, outdir, record_label=''):
if record_label:
recording = f'_recording-{record_label}'

heurpath = fldr + '/' + name + recording + '_physio'
heurpath = os.path.join(fldr, f'{name}{recording}_physio')
# for ext in ['.tsv.gz', '.json', '.log']:
# move_file(outfile, heurpath, ext)
os.chdir(cwd)
Expand All @@ -184,6 +184,11 @@ def _main(argv=None):
Otherwise, it operates on the input to return a .tsv.gz file, possibily
in BIDS format.
Raises
------
NotImplementedError
If the file extension is not supported yet.
"""
options = _get_parser().parse_args(argv)
# Check options to make them internally coherent
Expand Down
Loading

0 comments on commit 0fef5af

Please sign in to comment.