Commit d5b35844 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

Merge branch 'rf/protect_nifti_header' into 'master'

Rf/protect nifti header

See merge request fsl/fslpy!200
parents 1b56bbc5 8217bd86
Pipeline #5061 passed with stages
in 20 minutes and 11 seconds
......@@ -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
......@@ -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)
-----------------------------------
......
......@@ -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)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment