Skip to content
Snippets Groups Projects
Commit d3dc4bac authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

Merge branch 'mnt/fixlabels' into 'main'

MNT: Accept more FIX label file formats

See merge request fsl/fslpy!425
parents f8ce5038 e10f2f5a
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,8 @@ Changed
* Adjusted the :func:`.loadLabelFile` function to accept files with missing
entries (!424).
entries, and files which only contain the MELODIC directory path and list of
noisy components (!424, !425).
3.15.2 (Wednesday 4th October 2023)
......
......@@ -131,13 +131,16 @@ def loadLabelFile(filename,
lines = [l.strip() for l in lines]
lines = [l for l in lines if l != '']
# If the file contains a single
# line, we assume that it is just
# a comma-separated list of noise
# components.
if len(lines) == 1:
# If the file contains one or two lines, we
# assume that it is just a comma-separated list
# of noise components (possibly preceeded by
# the MELODIC directory path)
if len(lines) <= 2:
line = lines[0]
noisyComps = lines[-1]
if len(lines) == 2: melDir = lines[0]
else: melDir = None
# if the list is contained in
# square brackets, we assume
......@@ -153,21 +156,19 @@ def loadLabelFile(filename,
# to motion, and excluded
# components unclassified.
if includeLabel is None:
if line[0] == '[': includeLabel = 'Unclassified noise'
else: includeLabel = 'Movement'
if noisyComps[0] == '[': includeLabel = 'Unclassified noise'
else: includeLabel = 'Movement'
if excludeLabel is None:
if line[0] == '[': excludeLabel = 'Signal'
else: excludeLabel = 'Unknown'
if noisyComps[0] == '[': excludeLabel = 'Signal'
else: excludeLabel = 'Unknown'
else:
signalLabels = [excludeLabel]
# Remove any leading/trailing
# whitespace or brackets.
line = lines[0].strip(' []')
melDir = None
noisyComps = [int(i) for i in line.split(',')]
noisyComps = noisyComps.strip(' []')
noisyComps = [int(i) for i in noisyComps.split(',')]
allLabels = []
for i in range(max(noisyComps)):
......@@ -183,21 +184,6 @@ def loadLabelFile(filename,
noisyComps = [c for c in noisyComps if c != '']
noisyComps = [int(c) for c in noisyComps]
# There's no way to validate
# the melodic directory path,
# but let's try anyway.
if len(melDir.split(',')) >= 3:
raise InvalidLabelFileError(
f'{filename}: First line does not look like '
f'a MELODIC directory path: {melDir}')
# The melodic directory path should
# either be an absolute path, or
# be specified relative to the location
# of the label file.
if not op.isabs(melDir):
melDir = op.join(op.dirname(filename), melDir)
# Parse the labels for every component.
# Initially store as a {comp : [labels]} dict.
allLabels = {}
......@@ -235,6 +221,22 @@ def loadLabelFile(filename,
allLabelsList.append(allLabels.get(i + 1, [missingLabel]))
allLabels = allLabelsList
# There's no way to validate
# the melodic directory path,
# but let's try anyway.
if melDir is not None:
if len(melDir.split(',')) >= 3:
raise InvalidLabelFileError(
f'{filename}: First line does not look like '
f'a MELODIC directory path: {melDir}')
# The melodic directory path should
# either be an absolute path, or
# be specified relative to the location
# of the label file.
if not op.isabs(melDir):
melDir = op.join(op.dirname(filename), melDir)
# Validate the labels against
# the noisy list - all components
# in the noisy list should not
......
......@@ -109,6 +109,20 @@ None,
['Unclassified noise']],
[2, 5, 6, 7]))
goodfiles.append(("""
path/to/analysis.ica
[2, 3, 5, 7]
""",
'path/to/analysis.ica',
[['Signal'],
['Unclassified noise'],
['Unclassified noise'],
['Signal'],
['Unclassified noise'],
['Signal'],
['Unclassified noise']],
[2, 3, 5, 7]))
goodfiles.append(("""
2, 5, 6, 7
""",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment