From 1fbf8aaee70e24a51f9d08cba9c0df47b992018a Mon Sep 17 00:00:00 2001 From: "David C. Hansen" Date: Fri, 22 Apr 2022 09:55:13 +0200 Subject: [PATCH 1/3] Added support for relativeTablePosition --- schema/ismrmrd.xsd | 9 +++++++++ setup.py | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/schema/ismrmrd.xsd b/schema/ismrmrd.xsd index 7658c34..ab8efe1 100644 --- a/schema/ismrmrd.xsd +++ b/schema/ismrmrd.xsd @@ -65,6 +65,7 @@ + @@ -152,6 +153,14 @@ + + + + + + + + diff --git a/setup.py b/setup.py index 63f2bee..a9d2850 100644 --- a/setup.py +++ b/setup.py @@ -55,7 +55,7 @@ def to_uri(filename): setup( name='ismrmrd', - version='1.9.8', + version='1.10.0', author='ISMRMRD Developers', author_email='dchansen@gradientsoftware.net', description='Python implementation of the ISMRMRD', From 3ff47a8a24fa66e4cd093720ee279fd103eabb92 Mon Sep 17 00:00:00 2001 From: "David C. Hansen" Date: Mon, 10 Oct 2022 12:19:59 +0200 Subject: [PATCH 2/3] Added abillity to extend acquisitions and waveforms when using the File interface --- ismrmrd/file.py | 14 ++++++++++++-- setup.py | 2 +- tests/test_common.py | 2 +- tests/test_file.py | 45 ++++++++++++++++++++++++++++++++++++++++++-- tests/test_image.py | 15 ++++----------- 5 files changed, 61 insertions(+), 17 deletions(-) diff --git a/ismrmrd/file.py b/ismrmrd/file.py index 5db44a4..b08ed7d 100644 --- a/ismrmrd/file.py +++ b/ismrmrd/file.py @@ -37,6 +37,16 @@ def __setitem__(self, key, value): def __repr__(self): return type(self).__name__ + " containing " + self.data.__repr__() + def append(self,item): + self.extend([item]) + + def extend(self,iterable): + new_data = [self.to_numpy(v) for v in iterable] + old_size = self.data.shape[0] + new_size = old_size + len(new_data) + self.data.resize(new_size,axis=0) + self.data[old_size:] = new_data + @classmethod def from_numpy(cls, raw): raise NotImplemented() @@ -248,7 +258,7 @@ def __set_acquisitions(self, acquisitions): buffer = numpy.array([Acquisitions.to_numpy(a) for a in acquisitions], dtype=acquisition_dtype) self.__del_acquisitions() - self._contents['data'] = buffer + self._contents.create_dataset('data',data=buffer,maxshape=(None,),chunks=True) def __del_acquisitions(self): if 'data' in self._contents: @@ -271,7 +281,7 @@ def __set_waveforms(self, waveforms): buffer = numpy.array([converter.to_numpy(w) for w in waveforms], dtype=waveform_dtype) self.__del_waveforms() - self._contents['waveforms'] = buffer + self._contents.create_dataset('waveforms', data=buffer, maxshape=(None,),chunks=True) def __del_waveforms(self): if 'waveforms' in self._contents: diff --git a/setup.py b/setup.py index 4e336ce..67b904d 100644 --- a/setup.py +++ b/setup.py @@ -58,7 +58,7 @@ def to_uri(filename): setup( name='ismrmrd', - version='1.12.0', + version='1.13.0', author='ISMRMRD Developers', description='Python implementation of the ISMRMRD', license='Public Domain', diff --git a/tests/test_common.py b/tests/test_common.py index 53fb2ca..0bd96a5 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -121,7 +121,7 @@ def create_random_image(seed=42): header = create_random_image_properties() image = ismrmrd.Image.from_array(data, **header) - image.attribute_string = "This is a random attribute: {}".format(random.randint(0, 1000)) + image.meta = {"Random attribute": random.randint(0,1000)} return image diff --git a/tests/test_file.py b/tests/test_file.py index f82c74c..9bbc8d4 100644 --- a/tests/test_file.py +++ b/tests/test_file.py @@ -52,7 +52,7 @@ def test_file_returns_none_when_no_acquisitions_present(): dataset = file['dataset'] assert dataset.has_acquisitions() - assert dataset.acquisitions is not None + assert not (dataset.acquisitions is None) @nose.tools.with_setup(create_temp_dir, delete_temp_dir) @@ -85,7 +85,7 @@ def test_file_can_delete_acquisitions(): dataset.acquisitions = random_acquisitions(10) - assert dataset.acquisitions is not None + assert not (dataset.acquisitions is None) del dataset.acquisitions assert dataset.acquisitions is None @@ -138,6 +138,26 @@ def test_file_can_write_random_acquisition(): dataset = file['dataset'] assert acquisition == dataset.acquisitions[200] +@nose.tools.with_setup(create_temp_dir, delete_temp_dir) +def test_file_can_append_acquisitions(): + + filename = os.path.join(temp_dir, "acquisitions.h5") + acquisitions = list(random_acquisitions(10)) + acquisitions2 = list(random_acquisitions(10)) + acquisition3 = next(random_acquisitions(1)) + + combined = acquisitions + acquisitions2 + [acquisition3] + + with ismrmrd.File(filename) as file: + dataset = file['dataset'] + dataset.acquisitions = acquisitions + dataset.acquisitions.extend(acquisitions2) + dataset.acquisitions.append(acquisition3) + + with ismrmrd.File(filename) as file: + dataset = file['dataset'] + for a, b in zip(combined, dataset.acquisitions): + assert a == b @nose.tools.with_setup(create_temp_dir, delete_temp_dir) def test_file_can_write_random_acquisition_slice(): @@ -187,6 +207,27 @@ def test_file_can_read_and_write_waveforms(): for a, b in zip(waveforms, dataset.waveforms): assert a == b +@nose.tools.with_setup(create_temp_dir, delete_temp_dir) +def test_file_can_append_waveforms(): + + filename = os.path.join(temp_dir, "waveforms.h5") + waveforms = list(random_waveforms(10)) + waveforms2 = list(random_waveforms(10)) + waveform3 = next(random_waveforms(1)) + + combined = waveforms + waveforms2 + [waveform3] + + with ismrmrd.File(filename) as file: + dataset = file['dataset'] + dataset.waveforms = waveforms + dataset.waveforms.extend(waveforms2) + dataset.waveforms.append(waveform3) + + with ismrmrd.File(filename) as file: + dataset = file['dataset'] + for a, b in zip(combined, dataset.waveforms): + assert a == b + @nose.tools.with_setup(create_temp_dir, delete_temp_dir) def test_file_can_read_and_write_images(): diff --git a/tests/test_image.py b/tests/test_image.py index c2790d1..3839a8d 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -22,13 +22,6 @@ def test_new_instance(): eq_(type(img.data), np.ndarray) eq_(img.data.dtype, np.complex64) - attr = "this is a fake attribute string" - head = ismrmrd.ImageHeader() - head.attribute_string_len = len(attr) # must set attribute_string_len - head.data_type = ismrmrd.DATATYPE_CXFLOAT # must set data_type - img = ismrmrd.Image(head, attribute_string=attr) - eq_(img.attribute_string, attr) - def test_read_only_fields(): img = ismrmrd.Image() @@ -66,7 +59,7 @@ def test_initialization_sets_nonzero_version(): image = ismrmrd.Image.from_array(common.create_random_array((128, 128), dtype=np.float32)) - assert image.version is not 0, \ + assert image.version != 0, \ "Default image version should not be zero." @@ -133,7 +126,7 @@ def test_initialization_with_2d_image(): assert np.array_equal(image_data.transpose(), image.data.squeeze()), \ "Image data does not match data used to initialize image." - assert image.channels is 1, \ + assert image.channels == 1, \ "Unexpected number of channels: {}".format(image.channels) assert image.matrix_size == (1, 64, 128), \ @@ -149,7 +142,7 @@ def test_initialization_with_3d_image(): assert np.array_equal(image_data.transpose(), image.data.squeeze()), \ "Image data does not match data used to initialize image." - assert image.channels is 1, \ + assert image.channels == 1, \ "Unexpected number of channels: {}".format(image.channels) assert image.matrix_size == (32, 64, 128), \ @@ -165,7 +158,7 @@ def test_initialization_with_3d_image_and_channels(): assert np.array_equal(image_data.transpose(), image.data.squeeze()), \ "Image data does not match data used to initialize image." - assert image.channels is 16, \ + assert image.channels == 16, \ "Unexpected number of channels: {}".format(image.channels) assert image.matrix_size == (32, 64, 128), \ From cae4b892bf6cbc6ab57b715a2e154825319359b1 Mon Sep 17 00:00:00 2001 From: "David C. Hansen" Date: Mon, 10 Oct 2022 13:32:53 +0200 Subject: [PATCH 3/3] Merge --- setup.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/setup.py b/setup.py index 7384183..c5ee13d 100644 --- a/setup.py +++ b/setup.py @@ -58,11 +58,7 @@ def to_uri(filename): setup( name='ismrmrd', -<<<<<<< HEAD version='1.13.0', -======= - version='1.10.0', ->>>>>>> 1fbf8aaee70e24a51f9d08cba9c0df47b992018a author='ISMRMRD Developers', description='Python implementation of the ISMRMRD', license='Public Domain',