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
e48b6ac2
Commit
e48b6ac2
authored
4 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Workings on some new vest functions to be used by Text2Vest/Vest2Text
parent
1c279f81
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/data/vest.py
+68
-0
68 additions, 0 deletions
fsl/data/vest.py
with
68 additions
and
0 deletions
fsl/data/vest.py
+
68
−
0
View file @
e48b6ac2
...
...
@@ -11,9 +11,14 @@
looksLikeVestLutFile
loadVestLutFile
loadVestFile
generateVest
"""
import
textwrap
as
tw
import
io
import
numpy
as
np
...
...
@@ -76,3 +81,66 @@ def loadVestLutFile(path, normalise=True):
else
:
return
colours
def
loadVestFile
(
path
,
ignoreHeader
=
True
):
"""
Loads numeric data from a VEST file, returning it as a ``numpy`` array.
:arg ignoreHeader: if ``True`` (the default), the matrix shape specified
in the VEST header information is ignored. Otherwise,
if the number of rows/columns specified in the VEST
header information does not match the matrix shape,
a ``ValueError`` is raised.
:returns: a ``numpy`` array containing the matrix data in the
VEST file.
"""
data
=
np
.
loadtxt
(
path
,
comments
=
[
'
#
'
,
'
/
'
])
if
not
ignoreHeader
:
nrows
,
ncols
=
None
,
None
with
open
(
path
,
'
rt
'
)
as
f
:
for
line
in
f
:
if
'
NumWaves
'
in
line
:
ncols
=
int
(
line
.
split
()[
1
])
elif
'
NumPoints
'
in
line
:
nrows
=
int
(
line
.
split
()[
1
])
else
:
continue
if
(
ncols
is
not
None
)
and
(
nrows
is
not
None
):
break
return
data
def
generateVest
(
data
):
"""
Generates VEST-formatted text for the given ``numpy`` array.
:arg data: A 1D or 2D numpy array.
:returns: A string containing a VEST header, and the ``data``.
"""
data
=
np
.
asanyarray
(
data
)
if
len
(
data
.
shape
)
not
in
(
1
,
2
):
raise
ValueError
(
f
'
unsupported number of dimensions:
{
data
.
shape
}
'
)
data
=
np
.
atleast_2d
(
data
)
if
np
.
issubdtype
(
data
.
dtype
,
np
.
integer
):
fmt
=
'
%d
'
else
:
fmt
=
'
%0.12f
'
sdata
=
io
.
StringIO
()
np
.
savetxt
(
sdata
,
data
,
fmt
=
fmt
)
sdata
=
sdata
.
getvalue
()
nrows
,
ncols
=
data
.
shape
vest
=
tw
.
dedent
(
f
"""
/NumWaves
{
ncols
}
/NumPoints
{
nrows
}
/Matrix
"""
).
strip
()
+
'
\n
'
+
sdata
return
vest
.
strip
()
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