Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FSL
fslpy
Commits
8b19e449
Commit
8b19e449
authored
Apr 18, 2017
by
Paul McCarthy
Browse files
Fixes and adjustments to fixlabels.load/saveLabelFile - ability to specify
labels which correspond to 'signal'.
parent
358f7b24
Changes
2
Show whitespace changes
Inline
Side-by-side
fsl/data/fixlabels.py
View file @
8b19e449
...
...
@@ -62,8 +62,9 @@ def loadLabelFile(filename, includeLabel=None, excludeLabel=None):
- One or more labels for the component (multiple labels must be
comma-separated).
- ``'True'`` if the component has been classified as *bad*,
``'False'`` otherwise.
``'False'`` otherwise. This field is optional - if the last
comma-separated token on a line is not equal (case-insensitive)
to ``True`` or ``False``, it is interpreted as a component label.
The last line of the file contains the index (starting from 1) of all
*bad* components, i.e. those components which are not classified as
...
...
@@ -74,7 +75,7 @@ def loadLabelFile(filename, includeLabel=None, excludeLabel=None):
:arg includeLabel: If the file contains a single line containing a list
component indices, this label will be used for the
components in the list. Defaults to 'Unclassified
noise' for FIX-like files, and 'Mo
tion
' for
noise' for FIX-like files, and 'Mo
vement
' for
ICA-AROMA-like files.
:arg excludeLabel: If the file contains a single line containing component
...
...
@@ -88,6 +89,7 @@ def loadLabelFile(filename, includeLabel=None, excludeLabel=None):
the corresponding component.
"""
signalLabels
=
None
filename
=
op
.
abspath
(
filename
)
with
open
(
filename
,
'rt'
)
as
f
:
...
...
@@ -128,6 +130,8 @@ def loadLabelFile(filename, includeLabel=None, excludeLabel=None):
if
excludeLabel
is
None
:
if
line
[
0
]
==
'['
:
excludeLabel
=
'Signal'
else
:
excludeLabel
=
'Unknown'
else
:
signalLabels
=
[
excludeLabel
]
# Remove any leading/trailing
# whitespace or brackets.
...
...
@@ -177,7 +181,10 @@ def loadLabelFile(filename, includeLabel=None, excludeLabel=None):
'Invalid FIX classification file - '
'line {}: {}'
.
format
(
i
+
1
,
compLine
))
if
tokens
[
-
1
].
lower
()
in
(
'true'
,
'false'
):
compLabels
=
tokens
[
1
:
-
1
]
else
:
compLabels
=
tokens
[
1
:]
if
compIdx
!=
i
+
1
:
raise
InvalidLabelFileError
(
...
...
@@ -193,9 +200,10 @@ def loadLabelFile(filename, includeLabel=None, excludeLabel=None):
for
i
,
labels
in
enumerate
(
allLabels
):
comp
=
i
+
1
noise
=
isNoisyComponent
(
labels
)
noise
=
isNoisyComponent
(
labels
,
signalLabels
)
if
noise
and
(
comp
not
in
noisyComps
):
print
(
signalLabels
)
raise
InvalidLabelFileError
(
'Noisy component {} has invalid '
'labels: {}'
.
format
(
comp
,
labels
))
...
...
@@ -203,7 +211,7 @@ def loadLabelFile(filename, includeLabel=None, excludeLabel=None):
i
=
comp
-
1
labels
=
allLabels
[
i
]
noise
=
isNoisyComponent
(
labels
)
noise
=
isNoisyComponent
(
labels
,
signalLabels
)
if
not
noise
:
raise
InvalidLabelFileError
(
'Noisy component {} is missing '
...
...
@@ -212,7 +220,11 @@ def loadLabelFile(filename, includeLabel=None, excludeLabel=None):
return
melDir
,
allLabels
def
saveLabelFile
(
allLabels
,
filename
,
dirname
=
None
,
listBad
=
True
):
def
saveLabelFile
(
allLabels
,
filename
,
dirname
=
None
,
listBad
=
True
,
signalLabels
=
None
):
"""Saves the given classification labels to the specified file. The
classifications are saved in the format described in the
:func:`loadLabelFile` method.
...
...
@@ -230,6 +242,9 @@ def saveLabelFile(allLabels, filename, dirname=None, listBad=True):
:arg listBad: If ``True`` (the default), the last line of the file
will contain a comma separated list of components which
are deemed 'noisy' (see :func:`isNoisyComponent`).
:arg signalLabels: Labels which should be deemed 'signal' - see the
:func:`isNoisyComponent` function.
"""
lines
=
[]
...
...
@@ -243,7 +258,7 @@ def saveLabelFile(allLabels, filename, dirname=None, listBad=True):
for
i
,
labels
in
enumerate
(
allLabels
):
comp
=
i
+
1
noise
=
isNoisyComponent
(
labels
)
noise
=
isNoisyComponent
(
labels
,
signalLabels
)
# Make sure there are no
# commas in any label names
...
...
@@ -263,13 +278,20 @@ def saveLabelFile(allLabels, filename, dirname=None, listBad=True):
f
.
write
(
'
\n
'
.
join
(
lines
)
+
'
\n
'
)
def
isNoisyComponent
(
labels
):
def
isNoisyComponent
(
labels
,
signalLabels
=
None
):
"""Given a set of component labels, returns ``True`` if the component
is ultimately classified as noise, ``False`` otherwise.
:arg signalLabels: Labels which are deemed signal. If a component has
no labels in this list, it is deemed noise. Defaults
to ``['Signal', 'Unknown']`.
"""
if
signalLabels
is
None
:
signalLabels
=
[
'signal'
,
'unknown'
]
signalLabels
=
[
l
.
lower
()
for
l
in
signalLabels
]
labels
=
[
l
.
lower
()
for
l
in
labels
]
noise
=
(
'signal'
not
in
labels
)
and
(
'unknown'
not
in
l
abels
)
noise
=
not
any
([
sl
in
labels
for
sl
in
signalL
abels
]
)
return
noise
...
...
fsl/data/melodicimage.py
View file @
8b19e449
...
...
@@ -14,7 +14,6 @@ import os.path as op
from
.
import
image
as
fslimage
from
.
import
melodicanalysis
as
melanalysis
from
.
import
melodiclabels
as
mellabels
class
MelodicImage
(
fslimage
.
Image
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment