Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Michiel Cottaar
fslpy
Commits
767a4780
Commit
767a4780
authored
4 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
ENH: New replacement Text2Vest2Text scripts
parent
ac4abe63
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
fsl/data/vest.py
+10
-6
10 additions, 6 deletions
fsl/data/vest.py
fsl/scripts/Text2Vest.py
+43
-0
43 additions, 0 deletions
fsl/scripts/Text2Vest.py
fsl/scripts/Vest2Text.py
+44
-0
44 additions, 0 deletions
fsl/scripts/Vest2Text.py
with
97 additions
and
6 deletions
fsl/data/vest.py
+
10
−
6
View file @
767a4780
...
...
@@ -87,10 +87,12 @@ 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.
in the VEST header information is ignored, and the shape
inferred from the data. 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.
"""
...
...
@@ -108,8 +110,10 @@ def loadVestFile(path, ignoreHeader=True):
if
(
ncols
is
not
None
)
and
(
nrows
is
not
None
):
break
if
tuple
(
data
.
shape
)
!=
(
nrows
,
ncols
):
raise
ValueError
(
f
'
Invalid VEST file (
{
path
}
) - data shape
'
f
'
(
{
data
.
shape
}
) does not match header
'
f
'
(
{
nrows
}
,
{
ncols
}
)
'
)
return
data
...
...
This diff is collapsed.
Click to expand it.
fsl/scripts/Text2Vest.py
0 → 100644
+
43
−
0
View file @
767a4780
#!/usr/bin/env python
#
# Text2Vest.py - Convert an ASCII text matrix file into a VEST file.
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
"""
``Text2Vest`` simply takes a plain text ASCII text matrix file, and
adds a VEST header.
"""
import
sys
import
numpy
as
np
import
fsl.data.vest
as
fslvest
usage
=
"
Usage: Text2Vest <text_file> <vest_file>
"
def
main
(
argv
=
None
):
"""
Convert a plain text file to a VEST file.
"""
if
argv
is
None
:
argv
=
sys
.
argv
[
1
:]
if
len
(
argv
)
!=
2
:
print
(
usage
)
return
0
infile
,
outfile
=
argv
data
=
np
.
loadtxt
(
infile
)
vest
=
fslvest
.
generateVest
(
data
)
with
open
(
outfile
,
'
wt
'
)
as
f
:
f
.
write
(
vest
)
return
0
if
__name__
==
'
__main__
'
:
sys
.
exit
(
main
())
This diff is collapsed.
Click to expand it.
fsl/scripts/Vest2Text.py
0 → 100644
+
44
−
0
View file @
767a4780
#!/usr/bin/env python
#
# Vest2Text.py - Convert a VEST matrix file into a plain text ASCII file.
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
"""
``Vest2Text`` takes a VEST file containing a 2D matrix, and converts it
into a plain-text ASCII file.
"""
import
sys
import
numpy
as
np
import
fsl.data.vest
as
fslvest
usage
=
"
Usage: Vest2Text <vest_file> <text_file>
"
def
main
(
argv
=
None
):
"""
Convert a VEST file to a plain text file.
"""
if
argv
is
None
:
argv
=
sys
.
argv
[
1
:]
if
len
(
argv
)
!=
2
:
print
(
usage
)
return
0
infile
,
outfile
=
argv
data
=
fslvest
.
loadVestFile
(
infile
)
if
np
.
issubdtype
(
data
.
dtype
,
np
.
integer
):
fmt
=
'
%d
'
else
:
fmt
=
'
%0.12f
'
np
.
savetxt
(
outfile
,
data
,
fmt
=
fmt
)
return
0
if
__name__
==
'
__main__
'
:
sys
.
exit
(
main
())
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