Skip to content

Commit

Permalink
Fixes all the mess I had created locally
Browse files Browse the repository at this point in the history
  • Loading branch information
eurunuela committed Feb 11, 2020
1 parent 2506039 commit ec0a7fe
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
18 changes: 9 additions & 9 deletions phys2bids/interfaces/txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ def process_labchart(channel_list, chtrig, header=[]):
"""
# get frequency
if len(header) == 0:
LGR.error('Files without header are not supported yet')
raise AttributeError('Files without header are not supported yet')
interval = header[0][1].split(" ")
if interval[-1] not in ['hr', 'min', 's', 'ms', 'µs']:
LGR.error(f'Interval unit "{interval[-1]}" is not in a valid LabChart'
'time unit, this probably means your file is not in Labchart format')
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')

if interval[-1] != 's':
LGR.warning('Interval is not in seconds. Converting its value.')
Expand Down Expand Up @@ -123,12 +123,12 @@ def process_acq(channel_list, chtrig, header=[]):
timeseries = np.matrix(channel_list).T.tolist()
# get frequency
if len(header) == 0:
LGR.error('Files without header are not supported yet')
raise AttributeError('Files without header are not supported yet')
interval = header[1][0].split()
if interval[-1].split('/')[0] not in ['min', 'sec', 'µsec', 'msec', 'MHz', 'kHz', 'Hz']:
LGR.error(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')
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]
if 'Hz' in interval[-1].split('/')[0]:
print('frequency is given in the header, calculating sample Interval'
Expand Down Expand Up @@ -259,13 +259,13 @@ def populate_phys_input(filename, chtrig):
"""
header, channel_list = read_header_and_channels(filename, chtrig)
if len(header) == 0:
LGR.error('Files without header are not supported yet')
raise AttributeError('Files without header are not supported yet')
elif 'Interval=' in header[0]:
LGR.info('phys2bids detected that your file is in Labchart format')
phys_in = process_labchart(channel_list, chtrig, header)
elif 'acq' in header[0][0]:
LGR.info('phys2bids detected that your file is in AcqKnowledge format')
phys_in = process_acq(channel_list, chtrig, header)
else:
LGR.error('This file format is not supported yet for txt files')
raise AttributeError('This file format is not supported yet for txt files')
return phys_in
2 changes: 1 addition & 1 deletion phys2bids/phys2bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def _main(argv=None):
from phys2bids.interfaces.txt import populate_phys_input
else:
# #!# We should add a logger here.
LGR.error('Currently unsupported file type.')
raise NotImplementedError('Currently unsupported file type.')

LGR.info(f'Reading the file {infile}')
phys_in = populate_phys_input(infile, options.chtrig)
Expand Down
2 changes: 1 addition & 1 deletion phys2bids/physio_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def is_valid(var, var_type, list_type=None):
If var is not of var_type
"""
if not isinstance(var, var_type):
LGR.error(f'The given variable is not a {var_type}')
raise AttributeError(f'The given variable is not a {var_type}')

if var_type is list and list_type is not None:
for element in var:
Expand Down
12 changes: 6 additions & 6 deletions phys2bids/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ def check_input_type(filename, indir):
LGR.warning('If both acq and txt files exist in the path, acq will be selected.')
return fname, ftype
else:
LGR.error(f'The file {filename} wasn\'t found in {indir}'
f' or {ftype} is not supported yet.\n'
f'phys2bids currently supports:'
f' {", ".join(SUPPORTED_FTYPES)}')
raise Exception(f'The file {filename} wasn\'t found in {indir}'
f' or {ftype} is not supported yet.\n'
f'phys2bids currently supports:'
f' {", ".join(SUPPORTED_FTYPES)}')


def path_exists_or_make_it(fldr):
Expand Down Expand Up @@ -144,7 +144,7 @@ def check_file_exists(filename):
If the file doesn't exists.
"""
if not os.path.isfile(filename) and filename is not None:
LGR.error(f'The file {filename} does not exist!')
raise FileNotFoundError(f'The file {filename} does not exist!')


def move_file(oldpath, newpath, ext=''):
Expand Down Expand Up @@ -279,5 +279,5 @@ def load_heuristic(heuristic):
# remove c or o from pyc/pyo
mod.filename = mod.__file__.rstrip('co')
except Exception as exc:
LGR.error(f'Failed to import heuristic {heuristic}: {exc}')
raise ImportError(f'Failed to import heuristic {heuristic}: {exc}')
return mod

0 comments on commit ec0a7fe

Please sign in to comment.