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
a55a39e0
Commit
a55a39e0
authored
Oct 27, 2021
by
Paul McCarthy
🚵
Browse files
Merge branch 'rf/strict-json' into 'master'
Rf/strict json See merge request fsl/fslpy!312
parents
48984e01
8aa30d0e
Pipeline
#11387
canceled with stages
in 2 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
a55a39e0
...
...
@@ -171,6 +171,12 @@ test:3.9:
<<
:
*test_template
test:3.10:
stage
:
test
image
:
pauldmccarthy/fsleyes-py310-wxpy4-gtk3
<<
:
*test_template
test:build-pypi-dist:
stage
:
test
image
:
pauldmccarthy/fsleyes-py37-wxpy4-gtk3
...
...
CHANGELOG.rst
View file @
a55a39e0
...
...
@@ -2,6 +2,18 @@ This document contains the ``fslpy`` release history in reverse chronological
order.
3.8.0 (Under development)
-------------------------
Changed
^^^^^^^
* BIDS and ``dcm2niix`` ``.json`` sidecar files with control characters
are now accepted.
3.7.0 (Friday 20th August 2021)
-------------------------------
...
...
README.rst
View file @
a55a39e0
...
...
@@ -19,7 +19,7 @@ programming library written in Python. It is used by `FSLeyes
<https://git.fmrib.ox.ac.uk/fsl/fsleyes/fsleyes/>`_.
``fslpy`` is tested against Python versions 3.7, 3.8 and 3.
9
.
``fslpy`` is tested against Python versions 3.7, 3.8
, 3.9,
and 3.
10
.
Installation
...
...
fsl/data/image.py
View file @
a55a39e0
...
...
@@ -1569,7 +1569,7 @@ def loadMetadata(image):
jsonfile
=
op
.
join
(
dirname
,
'{}.json'
.
format
(
basename
))
if
op
.
exists
(
jsonfile
):
with
open
(
jsonfile
,
'rt'
)
as
f
:
return
json
.
load
(
f
)
return
json
.
load
(
f
,
strict
=
False
)
return
{}
...
...
fsl/utils/bids.py
View file @
a55a39e0
...
...
@@ -187,7 +187,7 @@ def isBIDSFile(filename, strict=True):
def
loadMetadataFile
(
filename
):
"""Load ``filename`` (assumed to be JSON), returning its contents. """
with
open
(
filename
,
'rt'
)
as
f
:
return
json
.
load
(
f
)
return
json
.
load
(
f
,
strict
=
False
)
def
loadMetadata
(
filename
):
...
...
tests/test_bids.py
View file @
a55a39e0
...
...
@@ -110,6 +110,21 @@ def test_loadMetadata():
assert
fslbids
.
loadMetadata
(
t1
)
==
{
**
meta4
,
**
meta2
,
**
meta1
}
def
test_loadMetadata_control_characters
():
dd
=
Path
(
'dataset_description.json'
)
t1
=
Path
(
'sub-01/func/sub-01_task-stim_bold.nii.gz'
)
json1
=
Path
(
'sub-01/func/sub-01_task-stim_bold.json'
)
meta1
=
{
"a"
:
"1"
,
"b"
:
"2
\x19\x20
"
}
smeta1
=
'{"a" : "1", "b" : "2
\x19\x20
"}'
with
tempdir
():
dd
.
touch
()
Path
(
op
.
dirname
(
t1
)).
mkdir
(
parents
=
True
)
t1
.
touch
()
assert
fslbids
.
loadMetadata
(
t1
)
==
{}
json1
.
write_text
(
smeta1
)
assert
fslbids
.
loadMetadata
(
t1
)
==
meta1
def
test_loadMetadata_symlinked
():
ddreal
=
Path
(
'a'
)
...
...
tests/test_image.py
View file @
a55a39e0
...
...
@@ -1484,6 +1484,21 @@ def test_loadMeta_badJSON():
assert
list
(
img
.
metaKeys
())
==
[]
def
test_loadMeta_control_characters
():
with
tempdir
():
make_image
(
'image.nii.gz'
)
with
open
(
'image.json'
,
'wt'
)
as
f
:
f
.
write
(
'{"a" : 1, "b" : "abc
\x19\x1b
"}'
)
# bad json should not cause failure
img
=
fslimage
.
Image
(
'image.nii.gz'
,
loadMeta
=
True
)
assert
list
(
img
.
metaKeys
())
==
[
'a'
,
'b'
]
assert
img
.
getMeta
(
'a'
)
==
1
assert
img
.
getMeta
(
'b'
)
==
'abc
\x19\x1b
'
def
test_loadMetadata
():
with
tempdir
():
make_image
(
'image.nii.gz'
)
...
...
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