diff --git a/quantiphyse/data/nifti.py b/quantiphyse/data/nifti.py index c572c476..9b05ae99 100644 --- a/quantiphyse/data/nifti.py +++ b/quantiphyse/data/nifti.py @@ -65,13 +65,13 @@ def __init__(self, fname): QpData.__init__(self, fname, grid, nvols, vol_unit=vol_units, vol_scale=vol_scale, fname=fname, metadata=metadata) def raw(self): - # NB: np.asarray convert data to an in-memory array instead of a numpy file memmap. + # NB: copy() converts data to an in-memory array instead of a numpy file memmap. # Appears to improve speed drastically as well as stop a bug with accessing the subset of the array # memmap has been designed to save space on ram by keeping the array on the disk but does # horrible things with performance, and analysis especially when the data is on the network. if self.rawdata is None: nii = nib.load(self.fname) - self.rawdata = np.asarray(nii.get_data()) + self.rawdata = nii.get_data().copy() self.rawdata = self._correct_dims(self.rawdata) self.voldata = None diff --git a/quantiphyse/test/qpd_test.py b/quantiphyse/test/qpd_test.py index e07f6e89..8e983bb5 100644 --- a/quantiphyse/test/qpd_test.py +++ b/quantiphyse/test/qpd_test.py @@ -138,5 +138,15 @@ def testSaveLoadMetadata(self): self.assertTrue(key in nifti_data.metadata) self.assertEqual(nifti_data.metadata[key], value) + def testLoadSaveSameName(self): + qpd = NumpyData(self.floats4d, grid=self.grid, name="test") + + tempdir = tempfile.mkdtemp(prefix="qp") + fname = os.path.join(tempdir, "test.nii") + nifti.save(qpd, fname) + + nifti_data = nifti.NiftiData(fname) + nifti.save(nifti_data, fname) + if __name__ == '__main__': unittest.main()