diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 58760e7821f4b2715247041b454f0d49f6e6d518..731efdab4e92635d3a9da0cbc4d9799a50df205c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,16 @@ This document contains the ``fslpy`` release history in reverse chronological order. +XXX (Under development) +----------------------- + + +Fixed +^^^^^ + +* Adjusted the :func:`.featdesign.loadFEATDesignFile` function to handle missing + values (!469). + 3.22.0 (Monday 17th February 2025) ---------------------------------- diff --git a/fsl/data/featanalysis.py b/fsl/data/featanalysis.py index 94c776894c134aa53380aeb482d5815ce4e38002..fa9723725010c64b6d1ef658adf17e7db257d4f2 100644 --- a/fsl/data/featanalysis.py +++ b/fsl/data/featanalysis.py @@ -544,7 +544,12 @@ def loadFEATDesignFile(filename): if line == '': continue - name, value = line.split(maxsplit=1) + tokens = line.split(maxsplit=1) + if len(tokens) == 1: + name, value = tokens[0], '' + else: + name, value = tokens + fields[name] = value return fields diff --git a/fsl/tests/test_featdesign.py b/fsl/tests/test_featdesign.py index e8ffdecec98d373b40b03b9fa1dfa9983a5444c1..1855b56d432ce5798731b114624c7ab2fb25e16c 100644 --- a/fsl/tests/test_featdesign.py +++ b/fsl/tests/test_featdesign.py @@ -103,8 +103,9 @@ with the following commands: """ -import os.path as op -import numpy as np +import os.path as op +import textwrap as tw +import numpy as np import pytest @@ -400,6 +401,45 @@ def test_loadDesignMat(): featdesign.loadDesignMat(badfile) +# fsl/fslpy!469 +def test_loadFEATDesignFile(): + with tempdir(): + with open('design1.con', 'wt') as f: + f.write(tw.dedent(""" + /ContrastName1 mycontrast + /NumWaves 2 + /NumContrasts 1 + + /Matrix + 10 20 + """).strip()) + + with open('design2.con', 'wt') as f: + f.write(tw.dedent(""" + /ContrastName1 + /NumWaves 2 + /NumContrasts 1 + + /Matrix + 10 20 + """).strip()) + + des1 = featanalysis.loadFEATDesignFile('design1.con') + exp1 = {'ContrastName1': 'mycontrast', + 'NumWaves': '2', + 'NumContrasts': '1', + 'Matrix': '10 20'} + + des2 = featanalysis.loadFEATDesignFile('design2.con') + exp2 = {'ContrastName1': '', + 'NumWaves': '2', + 'NumContrasts': '1', + 'Matrix': '10 20'} + + assert des1 == exp1 + assert des2 == exp2 + + def test_VoxelwiseEVs(): with tempdir(): img = tests.make_random_image('image.nii.gz', (10, 10, 10, 10))