From 0c7f79cf84a62cae4e05750a465abdad3b874acc Mon Sep 17 00:00:00 2001 From: Kelvin Chow Date: Mon, 12 Feb 2024 21:22:17 -0700 Subject: [PATCH 1/7] Add test for Dataset context manager --- tests/test_file.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test_file.py b/tests/test_file.py index 9bbc8d4..9cde6fa 100644 --- a/tests/test_file.py +++ b/tests/test_file.py @@ -401,6 +401,22 @@ def test_file_can_rewrite_data_and_images(): imageset.images = random_images(2) imageset.images = random_images(3) +@nose.tools.with_setup(create_temp_dir, delete_temp_dir) +def test_dataset_returns_none_when_no_acquisitions_present(): + + filename = os.path.join(temp_dir, "acquisitions.h5") + acquisitions = list(random_acquisitions(10)) + + with ismrmrd.Dataset(filename) as dataset: + assert not dataset.has_acquisitions() + assert dataset.acquisitions is None + + dataset.acquisitions = acquisitions + + with ismrmrd.Dataset(filename) as dataset: + assert dataset.has_acquisitions() + assert not (dataset.acquisitions is None) + example_header = """ From c1447e88d4ed9be4d619e57bce869ed4c7c11f0c Mon Sep 17 00:00:00 2001 From: Kelvin Chow Date: Tue, 13 Feb 2024 15:02:28 -0700 Subject: [PATCH 2/7] Bump version to 1.14.1 and limit xsdata to <23 --- conda/meta.yaml | 5 ++--- setup.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/conda/meta.yaml b/conda/meta.yaml index 022ef9d..2a518b8 100644 --- a/conda/meta.yaml +++ b/conda/meta.yaml @@ -14,14 +14,13 @@ requirements: - h5py>=2.3 - nose>=1.0 - docformatter<=1.4 - - xsdata>=22.2 + - xsdata>=22.2,<23 run: - python - - xsdata>=22.2 - numpy>=1.22.0 - h5py>=2.3 - - xsdata>=22.2 + - xsdata>=22.2,<23 test: source_files: diff --git a/setup.py b/setup.py index a104ca6..a7cd7d2 100644 --- a/setup.py +++ b/setup.py @@ -58,7 +58,7 @@ def to_uri(filename): setup( name='ismrmrd', - version='1.14.0', + version='1.14.1', author='ISMRMRD Developers', description='Python implementation of the ISMRMRD', license='Public Domain', From 21537e69be6585fe0186e4f1a20844e2074e1a29 Mon Sep 17 00:00:00 2001 From: Kelvin Chow Date: Tue, 13 Feb 2024 16:28:22 -0700 Subject: [PATCH 3/7] Update dataset context manager test --- tests/test_file.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tests/test_file.py b/tests/test_file.py index 9cde6fa..4c37fce 100644 --- a/tests/test_file.py +++ b/tests/test_file.py @@ -402,20 +402,17 @@ def test_file_can_rewrite_data_and_images(): imageset.images = random_images(3) @nose.tools.with_setup(create_temp_dir, delete_temp_dir) -def test_dataset_returns_none_when_no_acquisitions_present(): +def test_dataset_context_manager(): filename = os.path.join(temp_dir, "acquisitions.h5") - acquisitions = list(random_acquisitions(10)) + acq = random_acquisitions(1) with ismrmrd.Dataset(filename) as dataset: - assert not dataset.has_acquisitions() - assert dataset.acquisitions is None - - dataset.acquisitions = acquisitions + dataset.append_acquisition(acq) with ismrmrd.Dataset(filename) as dataset: - assert dataset.has_acquisitions() - assert not (dataset.acquisitions is None) + assert dataset.number_of_acquisitions() > 0 + assert not (dataset.read_acquisition(0) is None) example_header = """ From 32e2b068367661f9e74ddbbb91ef09907c243217 Mon Sep 17 00:00:00 2001 From: David Christoffer Hansen Date: Mon, 24 Jun 2024 19:09:17 +0200 Subject: [PATCH 4/7] Update test_file.py --- tests/test_file.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_file.py b/tests/test_file.py index 4c37fce..01e72b9 100644 --- a/tests/test_file.py +++ b/tests/test_file.py @@ -405,7 +405,8 @@ def test_file_can_rewrite_data_and_images(): def test_dataset_context_manager(): filename = os.path.join(temp_dir, "acquisitions.h5") - acq = random_acquisitions(1) + + acq = create_random_acquisition(1) with ismrmrd.Dataset(filename) as dataset: dataset.append_acquisition(acq) From 567d61cf34d85dbf10c7ebb6d787e110c0cfd774 Mon Sep 17 00:00:00 2001 From: Kelvin Chow Date: Thu, 3 Jul 2025 18:41:25 -0600 Subject: [PATCH 5/7] Add option to specify mode when opening h5 files to allow read-only access --- ismrmrd/hdf5.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ismrmrd/hdf5.py b/ismrmrd/hdf5.py index f391128..f0eb5ee 100644 --- a/ismrmrd/hdf5.py +++ b/ismrmrd/hdf5.py @@ -144,12 +144,15 @@ def fileinfo(fname): class Dataset(object): - def __init__(self, filename, dataset_name="dataset", create_if_needed=True): + def __init__(self, filename, dataset_name="dataset", create_if_needed=True, mode=None): # Open the file - if create_if_needed: - self._file = h5py.File(filename, 'a') - else: - self._file = h5py.File(filename, 'r+') + if mode is None: + if create_if_needed: + mode = 'a' + else: + mode = 'r+' + + self._file = h5py.File(filename, mode) self._dataset_name = dataset_name From bff898ed3fa1eee623134f8baad0a190471c7cb8 Mon Sep 17 00:00:00 2001 From: Kelvin Chow Date: Thu, 3 Jul 2025 18:42:30 -0600 Subject: [PATCH 6/7] Add definition of IMTYPE_RGB --- ismrmrd/constants.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ismrmrd/constants.py b/ismrmrd/constants.py index 451be1d..e22aef5 100644 --- a/ismrmrd/constants.py +++ b/ismrmrd/constants.py @@ -68,6 +68,7 @@ IMTYPE_REAL = 3 IMTYPE_IMAG = 4 IMTYPE_COMPLEX = 5 +IMTYPE_RGB = 6 # Image flags IMAGE_IS_NAVIGATION_DATA = 1 From 95488df123ca176a74a1e7d852261a60c28b4d09 Mon Sep 17 00:00:00 2001 From: Kelvin Chow Date: Thu, 3 Jul 2025 18:50:30 -0600 Subject: [PATCH 7/7] Raise exception if the the number of samples exceeds the limit for Waveforms --- ismrmrd/waveform.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ismrmrd/waveform.py b/ismrmrd/waveform.py index f128ffa..936f47f 100644 --- a/ismrmrd/waveform.py +++ b/ismrmrd/waveform.py @@ -69,6 +69,9 @@ def from_array(data, **kwargs): channels, nsamples = data.shape + if nsamples > np.iinfo(np.uint16).max: + raise TypeError(f"Array has {nsamples} samples, which is greater than the maximum of {np.iinfo(np.uint16).max}") + array_data = { 'version': 1, 'channels': channels,