Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for labchart files that don't have the time in the channel_list #140

Merged
merged 14 commits into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ before_install:
pip install flake8;
fi
- if [ "${CHECK_TYPE}" == "test" ]; then
pip install "pytest>=3.6" pytest-cov coverage coveralls codecov;
pip install "pytest>=3.6" pytest-cov coverage coveralls codecov wget;
fi
- if [ "${CHECK_TYPE}" == "docdoctest" ]; then
pip install "sphinx>2.0" sphinx_rtd_theme pandas sphinx-argparse;
Expand Down
Binary file modified docs/_static/phys2bids_logo1280×640.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/phys2bids_logo2000x400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion phys2bids/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def _get_parser():
optional.add_argument('-chplot', '--channels-plot',
dest='chplot',
type=str,
help='path to store channels plot ',
help='full path to store channels plot ',
default='')
optional.add_argument('-v', '--version', action='version',
version=('%(prog)s ' + __version__))
Expand Down
38 changes: 28 additions & 10 deletions phys2bids/interfaces/txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ def process_labchart(channel_list, chtrig, header=[]):
physio_obj.BlueprintInput
"""
# get frequency
# check header has some length
if len(header) == 0:
raise AttributeError('Files without header are not supported yet')
interval = header[0][1].split(" ")
# check the interval is in some of the correct labchart units
if interval[-1] not in ['hr', 'min', 's', 'ms', 'µs']:
raise AttributeError(f'Interval unit "{interval[-1]}" is not in a valid LabChart'
'time unit, this probably means your file is not in Labchart format')

# check if interval is in seconds, if not change the units to seconds
if interval[-1] != 's':
print('Interval is not in seconds. Converting its value.')
if interval[-1] == 'hr':
Expand All @@ -68,21 +70,32 @@ def process_labchart(channel_list, chtrig, header=[]):
for item in range_list:
orig_units.append(item.split(' ')[1])
units = ['s', 'V']
orig_units.pop(chtrig - 1)
units = units + orig_units
# get names
orig_names = header[4][1:]
orig_names_len = len(orig_names)
names = ['time', 'trigger']
orig_names.pop(chtrig - 1)
names = names + orig_names
# get channels
timeseries = np.matrix(channel_list).T.tolist()
freq = [1 / interval[0]] * len(timeseries)
timeseries = [np.array(darray) for darray in timeseries]
ordered_timeseries = [timeseries[0], timeseries[chtrig]]
timeseries.pop(chtrig)
timeseries.pop(0)
ordered_timeseries = ordered_timeseries + timeseries
# check the file has a time channel if not create it and add it
if (orig_names_len < len(timeseries)):
vinferrer marked this conversation as resolved.
Show resolved Hide resolved
ordered_timeseries = [timeseries[0], timeseries[chtrig]]
timeseries.pop(chtrig)
timeseries.pop(0)
ordered_timeseries = ordered_timeseries + timeseries
orig_units.pop(chtrig - 1)
orig_names.pop(chtrig - 1)
names = names + orig_names
units = units + orig_units
else:
duration = (timeseries[0].shape[0] + 1) * interval[0]
t_ch = np.ogrid[0:duration:interval[0]][:-1] # create time channel
ordered_timeseries = [t_ch, timeseries[chtrig]]
timeseries.pop(chtrig)
ordered_timeseries = ordered_timeseries + timeseries
names = names + orig_names[1:]
units = units + orig_units[1:]
return BlueprintInput(ordered_timeseries, freq, names, units)


Expand Down Expand Up @@ -116,15 +129,17 @@ def process_acq(channel_list, chtrig, header=[]):
physio_obj.BlueprintInput
"""
timeseries = np.matrix(channel_list).T.tolist()
# get frequency
# check header is not empty
if len(header) == 0:
raise AttributeError('Files without header are not supported yet')
interval = header[1][0].split()
# check the interval is in some of the correct AcqKnowledge units
if interval[-1].split('/')[0] not in ['min', 'sec', 'µsec', 'msec', 'MHz', 'kHz', 'Hz']:
raise AttributeError(f'Interval unit "{interval[-1]}" is not in a '
'valid AcqKnowledge format time unit, this probably'
'means your file is not in min, sec, msec, µsec, Mhz, KHz or Hz')
interval[-1] = interval[-1].split('/')[0]
# Check if the header is in frequency or sampling interval
if 'Hz' in interval[-1].split('/')[0]:
print('frequency is given in the header, calculating sample Interval'
' and standarizing to Hz if needed')
Expand All @@ -137,6 +152,8 @@ def process_acq(channel_list, chtrig, header=[]):
interval[0] = 1 / freq
freq = [freq] * (len(timeseries) + 1)
else:
# check if interval is in seconds, if not change the units to seconds and
# calculate frequency
if interval[-1].split('/')[0] != 'sec':
print('Interval is not in seconds. Converting its value.')
if interval[-1].split('/')[0] == 'min':
Expand Down Expand Up @@ -253,6 +270,7 @@ def populate_phys_input(filename, chtrig):
physio_obj.BlueprintInput
"""
header, channel_list = read_header_and_channels(filename, chtrig)
# check header is not empty and detect if it is in labchart or Acqknoledge format
if len(header) == 0:
raise AttributeError('Files without header are not supported yet')
elif 'Interval=' in header[0]:
Expand Down
Loading