diff --git a/.ci/test_template.sh b/.ci/test_template.sh index 7880223dcaaa2198582cddbbbb04683eb442b6af..f0a8c7103e835411884441f2da6464c17af167c3 100644 --- a/.ci/test_template.sh +++ b/.ci/test_template.sh @@ -2,6 +2,13 @@ set -e +# Temporary: this should be done +# in docker image definition +apt install -y locales +locale-gen en_US.UTF-8 +locale-gen en_GB.UTF-8 +update-locale + # If running on a fork repository, we merge in the # upstream/master branch. This is done so that merge # requests from fork to the parent repository will @@ -59,4 +66,4 @@ if [[ $CI_COMMIT_REF_NAME == v* ]]; then python setup.py test --addopts="$TEST_OPTS -m 'longtest'" fi -python -m coverage report +python -m coverage report -i diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 498e60a9d23641266f9386ce1af5b0728deb5a3c..358df42f562fa469aecf40ad8344f9aeac07f340 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,16 @@ This document contains the ``fslpy`` release history in reverse chronological order. +2.8.3 (Friday 28th February 2020) +--------------------------------- + + +Fixed +^^^^^ + + +* Fixed a bug in the :meth:`.Image.save` method. + 2.8.2 (Thursday 27th February 2020) ----------------------------------- diff --git a/fsl/data/image.py b/fsl/data/image.py index 2060aad046a95f998625ac0f2520240a500b845c..97fe2d72259864a9890f571ea91671e43a56659b 100644 --- a/fsl/data/image.py +++ b/fsl/data/image.py @@ -254,7 +254,7 @@ class Nifti(notifier.Notifier, meta.Meta): shape, pixdim) - self.header = header + self.__header = header self.__shape = shape self.__origShape = origShape self.__pixdim = pixdim @@ -262,6 +262,11 @@ class Nifti(notifier.Notifier, meta.Meta): self.__isNeurological = isneuro + def __del__(self): + """Clears the reference to the ``nibabel`` header object. """ + self.__header = None + + @staticmethod def determineShape(header): """This method is called by :meth:`__init__`. It figures out the actual @@ -492,6 +497,24 @@ class Nifti(notifier.Notifier, meta.Meta): return ''.join([c for c in val if c in string.printable]).strip() + @property + def header(self): + """Return a reference to the ``nibabel`` header object. """ + return self.__header + + + @header.setter + def header(self, header): + """Replace the ``nibabel`` header object managed by this ``Nifti`` + with a new header. The new header must have the same dimensions, + voxel size, and orientation as the old one. + """ + new = Nifti(header) + if not (self.sameSpace(new) and self.ndim == new.ndim): + raise ValueError('Incompatible header') + self.__header = header + + @property def niftiVersion(self): """Returns the NIFTI file version: @@ -1180,8 +1203,7 @@ class Image(Nifti): def __del__(self): """Closes any open file handles, and clears some references. """ - - self.header = None + Nifti.__del__(self) self.__nibImage = None self.__imageWrapper = None @@ -1411,12 +1433,6 @@ class Image(Nifti): nib.save(self.__nibImage, tmpfname) - # nibabel should close any old - # file handles when the image/ - # header refs are deleted - self.__nibImage = None - self.header = None - # Copy to final destination, # and reload from there imcp.imcp(tmpfname, filename, overwrite=True)