Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ requirements:
- setuptools
- wheel
- jinja2 >=2.11.0
- pip
- pip

run:
- python
- numpy>=1.22.0
Expand Down
1 change: 1 addition & 0 deletions ismrmrd/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
IMTYPE_REAL = 3
IMTYPE_IMAG = 4
IMTYPE_COMPLEX = 5
IMTYPE_RGB = 6

# Image flags
IMAGE_IS_NAVIGATION_DATA = 1
Expand Down
13 changes: 8 additions & 5 deletions ismrmrd/hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions ismrmrd/waveform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """<?xml version="1.0" encoding="utf-8"?>
<ismrmrdHeader xmlns="http://www.ismrm.org/ISMRMRD" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ismrm.org/ISMRMRD ismrmrd.xsd">
Expand Down
Loading