Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FSL
fslpy
Commits
98e181dc
Commit
98e181dc
authored
6 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
RF: Don't be lenient, error on bad components or confounds
parent
86ae7caa
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/scripts/extract_noise.py
+34
-42
34 additions, 42 deletions
fsl/scripts/extract_noise.py
with
34 additions
and
42 deletions
fsl/scripts/extract_noise.py
+
34
−
42
View file @
98e181dc
...
@@ -28,16 +28,16 @@ with warnings.catch_warnings():
...
@@ -28,16 +28,16 @@ with warnings.catch_warnings():
DTYPE
=
np
.
float64
DTYPE
=
np
.
float64
name
=
"
extract_noise
"
desc
=
'
Extract component time series from a MELODIC .ica directory
'
usage
=
"""
usage
=
"""
{name}: {desc}
Usage:
Usage:
extract_noise <.ica directory> [-o outfile] <fixfile>
{name} <.ica directory> [-o outfile] <fixfile>
extract_noise <.ica directory> [-o outfile] <component> [<component> ...]
{name} <.ica directory> [-o outfile] <component> [<component> ...]
"""
.
strip
()
{name} <.ica directory> [-o outfile] [-c conffile] [-c conffile] <fixfile>
{name} <.ica directory> [-o outfile] [-c conffile] [-c conffile] <component> [<component> ...]
"""
.
format
(
name
=
name
,
desc
=
desc
).
strip
()
# noqa
desc
=
'
Extract component time series from a MELODIC .ica directory
'
helps
=
{
helps
=
{
...
@@ -69,7 +69,7 @@ def parseArgs(args):
...
@@ -69,7 +69,7 @@ def parseArgs(args):
print
(
usage
)
print
(
usage
)
sys
.
exit
(
0
)
sys
.
exit
(
0
)
parser
=
argparse
.
ArgumentParser
(
prog
=
'
extract_noise
'
,
parser
=
argparse
.
ArgumentParser
(
prog
=
name
,
usage
=
usage
,
usage
=
usage
,
description
=
desc
)
description
=
desc
)
...
@@ -144,7 +144,6 @@ def genComponentIndexList(comps, ncomps):
...
@@ -144,7 +144,6 @@ def genComponentIndexList(comps, ncomps):
"""
"""
allcomps
=
[]
allcomps
=
[]
badcomps
=
[]
for
c
in
comps
:
for
c
in
comps
:
if
isinstance
(
c
,
int
):
if
isinstance
(
c
,
int
):
...
@@ -152,12 +151,10 @@ def genComponentIndexList(comps, ncomps):
...
@@ -152,12 +151,10 @@ def genComponentIndexList(comps, ncomps):
else
:
else
:
ccomps
=
fixlabels
.
loadLabelFile
(
c
,
returnIndices
=
True
)[
2
]
ccomps
=
fixlabels
.
loadLabelFile
(
c
,
returnIndices
=
True
)[
2
]
badcomps
.
extend
([
cc
for
cc
in
ccomps
if
cc
>=
ncomps
])
allcomps
.
extend
([
c
-
1
for
c
in
ccomps
])
allcomps
.
extend
([
cc
-
1
for
cc
in
ccomps
if
cc
<
ncomps
])
if
len
(
badcomps
)
>
0
:
if
any
([
cc
<
0
or
cc
>=
ncomps
for
cc
in
ccomps
]):
print
(
'
Warning: Ignoring components: {}
'
.
format
(
badcomps
),
raise
ValueError
(
'
Invalid component indices: {}
'
.
format
(
ccomps
))
file
=
sys
.
stderr
)
return
list
(
sorted
(
set
(
allcomps
)))
return
list
(
sorted
(
set
(
allcomps
)))
...
@@ -185,32 +182,21 @@ def loadConfoundFiles(conffiles, npts):
...
@@ -185,32 +182,21 @@ def loadConfoundFiles(conffiles, npts):
mat
=
np
.
atleast_2d
(
mat
).
T
mat
=
np
.
atleast_2d
(
mat
).
T
if
mat
.
shape
[
0
]
!=
npts
:
if
mat
.
shape
[
0
]
!=
npts
:
print
(
'
Warning: confound file {} does not have correct number of
'
raise
ValueError
(
'
Confound file {} does not have correct number
'
'
points (expected {}, has {}). Output will be truncated or
'
'
of points (expected {}, has {})
'
.
format
(
'
padded with NaNs.
'
.
format
(
cfile
,
npts
,
mat
.
shape
[
1
]),
cfile
,
npts
,
mat
.
shape
[
0
]))
file
=
sys
.
stderr
)
matrices
.
append
(
mat
)
totalcols
=
sum
([
m
.
shape
[
0
]
for
m
in
matrices
])
confounds
=
np
.
zeros
((
npts
,
totalcols
),
dtype
=
DTYPE
)
coli
=
0
matrices
.
append
(
mat
)
for
mat
in
matrices
:
ncols
=
mat
.
shape
[
1
]
# too many timepoints - truncate
ncols
=
sum
([
m
.
shape
[
1
]
for
m
in
matrices
])
if
mat
.
shape
[
0
]
>
npts
:
confounds
=
np
.
zeros
((
npts
,
ncols
),
dtype
=
DTYPE
)
mat
=
mat
[:
npts
,
:]
# too few timepoints - pad with NaN
coli
=
0
elif
mat
.
shape
[
0
]
<
npts
:
tmat
=
mat
mat
=
np
.
zeros
((
npts
,
ncols
),
dtype
=
DTYPE
)
mat
[:
npts
,
:]
=
tmat
mat
[
npts
:,
:]
=
np
.
nan
confounds
[:,
coli
:
coli
+
ncols
]
=
mat
for
mat
in
matrices
:
coli
=
coli
+
ncols
matcols
=
mat
.
shape
[
1
]
confounds
[:,
coli
:
coli
+
matcols
]
=
mat
coli
=
coli
+
matcols
return
confounds
return
confounds
...
@@ -226,12 +212,18 @@ def main(argv=None):
...
@@ -226,12 +212,18 @@ def main(argv=None):
argv
=
sys
.
argv
[
1
:]
argv
=
sys
.
argv
[
1
:]
args
=
parseArgs
(
argv
)
args
=
parseArgs
(
argv
)
comps
=
genComponentIndexList
(
args
.
components
)
ts
=
melanalysis
.
getComponentTimeSeries
(
args
.
icadir
)
ts
=
ts
[:,
comps
]
confs
=
loadConfoundFiles
(
args
.
conffiles
,
ts
.
shape
[
0
])
ts
=
np
.
hstack
((
ts
,
confs
))
try
:
comps
=
genComponentIndexList
(
args
.
components
)
ts
=
melanalysis
.
getComponentTimeSeries
(
args
.
icadir
)
ts
=
ts
[:,
comps
]
confs
=
loadConfoundFiles
(
args
.
conffiles
,
ts
.
shape
[
0
])
except
ValueError
as
e
:
print
(
e
)
sys
.
exit
(
1
)
ts
=
np
.
hstack
((
ts
,
confs
))
np
.
savetxt
(
args
.
outfile
,
ts
,
fmt
=
'
%10.5f
'
)
np
.
savetxt
(
args
.
outfile
,
ts
,
fmt
=
'
%10.5f
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment