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
# 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 test --addopts="$TEST_OPTS -m 'longtest'"
python -m coverage report
python -m coverage report -i
......@@ -2,6 +2,16 @@ This document contains the ``fslpy`` release history in reverse chronological
2.8.3 (Friday 28th February 2020)
* Fixed a bug in the :meth:`` method.
2.8.2 (Thursday 27th February 2020)
......@@ -254,7 +254,7 @@ class Nifti(notifier.Notifier, meta.Meta):
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
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()
def header(self):
"""Return a reference to the ``nibabel`` header object. """
return self.__header
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
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
self.__nibImage = None
self.__imageWrapper = None
......@@ -1411,12 +1433,6 @@ class Image(Nifti):, 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