diff --git a/conda/meta.yaml b/conda/meta.yaml index e33d45b..8ca46d1 100644 --- a/conda/meta.yaml +++ b/conda/meta.yaml @@ -14,8 +14,8 @@ requirements: - setuptools - wheel - jinja2 >=2.11.0 - - pip - + - pip + run: - python - numpy>=1.22.0 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 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 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, diff --git a/tests/test_file.py b/tests/test_file.py index 9bbc8d4..01e72b9 100644 --- a/tests/test_file.py +++ b/tests/test_file.py @@ -401,6 +401,20 @@ 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_context_manager(): + + filename = os.path.join(temp_dir, "acquisitions.h5") + + acq = create_random_acquisition(1) + + with ismrmrd.Dataset(filename) as dataset: + dataset.append_acquisition(acq) + + with ismrmrd.Dataset(filename) as dataset: + assert dataset.number_of_acquisitions() > 0 + assert not (dataset.read_acquisition(0) is None) + example_header = """