mrd-python 2.0.0rc4__tar.gz → 2.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mrd_python-2.0.0rc4 → mrd_python-2.1.0}/PKG-INFO +1 -1
- {mrd_python-2.0.0rc4 → mrd_python-2.1.0}/mrd/__init__.py +23 -3
- {mrd_python-2.0.0rc4 → mrd_python-2.1.0}/mrd/_binary.py +6 -0
- {mrd_python-2.0.0rc4 → mrd_python-2.1.0}/mrd/binary.py +216 -19
- {mrd_python-2.0.0rc4 → mrd_python-2.1.0}/mrd/ndjson.py +592 -80
- mrd_python-2.1.0/mrd/protocols.py +318 -0
- {mrd_python-2.0.0rc4 → mrd_python-2.1.0}/mrd/tools/phantom.py +20 -20
- {mrd_python-2.0.0rc4 → mrd_python-2.1.0}/mrd/tools/stream_recon.py +33 -25
- {mrd_python-2.0.0rc4 → mrd_python-2.1.0}/mrd/types.py +466 -105
- {mrd_python-2.0.0rc4 → mrd_python-2.1.0}/mrd_python.egg-info/PKG-INFO +1 -1
- mrd_python-2.0.0rc4/mrd/protocols.py +0 -180
- {mrd_python-2.0.0rc4 → mrd_python-2.1.0}/README.md +0 -0
- {mrd_python-2.0.0rc4 → mrd_python-2.1.0}/mrd/_dtypes.py +0 -0
- {mrd_python-2.0.0rc4 → mrd_python-2.1.0}/mrd/_ndjson.py +0 -0
- {mrd_python-2.0.0rc4 → mrd_python-2.1.0}/mrd/tools/export_png_images.py +0 -0
- {mrd_python-2.0.0rc4 → mrd_python-2.1.0}/mrd/tools/minimal_example.py +0 -0
- {mrd_python-2.0.0rc4 → mrd_python-2.1.0}/mrd/tools/simulation.py +0 -0
- {mrd_python-2.0.0rc4 → mrd_python-2.1.0}/mrd/tools/transform.py +0 -0
- {mrd_python-2.0.0rc4 → mrd_python-2.1.0}/mrd/yardl_types.py +0 -0
- {mrd_python-2.0.0rc4 → mrd_python-2.1.0}/mrd_python.egg-info/SOURCES.txt +0 -0
- {mrd_python-2.0.0rc4 → mrd_python-2.1.0}/mrd_python.egg-info/dependency_links.txt +0 -0
- {mrd_python-2.0.0rc4 → mrd_python-2.1.0}/mrd_python.egg-info/requires.txt +0 -0
- {mrd_python-2.0.0rc4 → mrd_python-2.1.0}/mrd_python.egg-info/top_level.txt +0 -0
- {mrd_python-2.0.0rc4 → mrd_python-2.1.0}/pyproject.toml +0 -0
- {mrd_python-2.0.0rc4 → mrd_python-2.1.0}/setup.cfg +0 -0
- {mrd_python-2.0.0rc4 → mrd_python-2.1.0}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: mrd-python
|
|
3
|
-
Version: 2.0
|
|
3
|
+
Version: 2.1.0
|
|
4
4
|
Summary: Library and tools for working with data in the ISMRM Raw Data (MRD) format.
|
|
5
5
|
Project-URL: Homepage, https://ismrmrd.github.io/mrd
|
|
6
6
|
Project-URL: Documentation, https://ismrmrd.github.io/mrd
|
|
@@ -22,9 +22,14 @@ from .yardl_types import *
|
|
|
22
22
|
from .types import (
|
|
23
23
|
AccelerationFactorType,
|
|
24
24
|
Acquisition,
|
|
25
|
+
AcquisitionBucket,
|
|
25
26
|
AcquisitionData,
|
|
26
27
|
AcquisitionFlags,
|
|
28
|
+
AcquisitionHeader,
|
|
27
29
|
AcquisitionSystemInformationType,
|
|
30
|
+
AnyImage,
|
|
31
|
+
Array,
|
|
32
|
+
ArrayComplexFloat,
|
|
28
33
|
Calibration,
|
|
29
34
|
CalibrationMode,
|
|
30
35
|
CoilLabelType,
|
|
@@ -39,18 +44,21 @@ from .types import (
|
|
|
39
44
|
GradientDirectionType,
|
|
40
45
|
Header,
|
|
41
46
|
Image,
|
|
47
|
+
ImageArray,
|
|
42
48
|
ImageComplexDouble,
|
|
43
49
|
ImageComplexFloat,
|
|
44
50
|
ImageData,
|
|
45
51
|
ImageDouble,
|
|
46
52
|
ImageFlags,
|
|
47
53
|
ImageFloat,
|
|
48
|
-
|
|
54
|
+
ImageHeader,
|
|
49
55
|
ImageInt16,
|
|
50
|
-
|
|
56
|
+
ImageInt32,
|
|
57
|
+
ImageMeta,
|
|
58
|
+
ImageMetaValue,
|
|
51
59
|
ImageType,
|
|
52
|
-
ImageUint,
|
|
53
60
|
ImageUint16,
|
|
61
|
+
ImageUint32,
|
|
54
62
|
InterleavingDimension,
|
|
55
63
|
LimitType,
|
|
56
64
|
MatrixSizeType,
|
|
@@ -58,10 +66,16 @@ from .types import (
|
|
|
58
66
|
MeasurementInformationType,
|
|
59
67
|
MultibandSpacingType,
|
|
60
68
|
MultibandType,
|
|
69
|
+
NoiseCovariance,
|
|
61
70
|
ParallelImagingType,
|
|
62
71
|
PatientGender,
|
|
63
72
|
PatientPosition,
|
|
73
|
+
ReconAssembly,
|
|
74
|
+
ReconBuffer,
|
|
75
|
+
ReconData,
|
|
64
76
|
ReferencedImageSequenceType,
|
|
77
|
+
SamplingDescription,
|
|
78
|
+
SamplingLimits,
|
|
65
79
|
SequenceParametersType,
|
|
66
80
|
StreamItem,
|
|
67
81
|
StudyInformationType,
|
|
@@ -83,14 +97,20 @@ from .types import (
|
|
|
83
97
|
get_dtype,
|
|
84
98
|
)
|
|
85
99
|
from .protocols import (
|
|
100
|
+
MrdNoiseCovarianceReaderBase,
|
|
101
|
+
MrdNoiseCovarianceWriterBase,
|
|
86
102
|
MrdReaderBase,
|
|
87
103
|
MrdWriterBase,
|
|
88
104
|
)
|
|
89
105
|
from .binary import (
|
|
106
|
+
BinaryMrdNoiseCovarianceReader,
|
|
107
|
+
BinaryMrdNoiseCovarianceWriter,
|
|
90
108
|
BinaryMrdReader,
|
|
91
109
|
BinaryMrdWriter,
|
|
92
110
|
)
|
|
93
111
|
from .ndjson import (
|
|
112
|
+
NDJsonMrdNoiseCovarianceReader,
|
|
113
|
+
NDJsonMrdNoiseCovarianceWriter,
|
|
94
114
|
NDJsonMrdReader,
|
|
95
115
|
NDJsonMrdWriter,
|
|
96
116
|
)
|
|
@@ -628,6 +628,9 @@ class Complex32Serializer(StructSerializer[ComplexFloat, np.complex64]):
|
|
|
628
628
|
def write(self, stream: CodedOutputStream, value: ComplexFloat) -> None:
|
|
629
629
|
stream.write(self._struct, value.real, value.imag)
|
|
630
630
|
|
|
631
|
+
def write_numpy(self, stream: CodedOutputStream, value: np.complex64) -> None:
|
|
632
|
+
stream.write(self._struct, value.real, value.imag)
|
|
633
|
+
|
|
631
634
|
def read(self, stream: CodedInputStream) -> ComplexFloat:
|
|
632
635
|
return ComplexFloat(*stream.read(self._struct))
|
|
633
636
|
|
|
@@ -649,6 +652,9 @@ class Complex64Serializer(StructSerializer[ComplexDouble, np.complex128]):
|
|
|
649
652
|
def write(self, stream: CodedOutputStream, value: ComplexDouble) -> None:
|
|
650
653
|
stream.write(self._struct, value.real, value.imag)
|
|
651
654
|
|
|
655
|
+
def write_numpy(self, stream: CodedOutputStream, value: np.complex128) -> None:
|
|
656
|
+
stream.write(self._struct, value.real, value.imag)
|
|
657
|
+
|
|
652
658
|
def read(self, stream: CodedInputStream) -> ComplexDouble:
|
|
653
659
|
return ComplexDouble(*stream.read(self._struct))
|
|
654
660
|
|
|
@@ -20,7 +20,10 @@ from . import _binary
|
|
|
20
20
|
from . import yardl_types as yardl
|
|
21
21
|
|
|
22
22
|
class BinaryMrdWriter(_binary.BinaryProtocolWriter, MrdWriterBase):
|
|
23
|
-
"""Binary writer for the Mrd protocol.
|
|
23
|
+
"""Binary writer for the Mrd protocol.
|
|
24
|
+
|
|
25
|
+
The MRD Protocol
|
|
26
|
+
"""
|
|
24
27
|
|
|
25
28
|
|
|
26
29
|
def __init__(self, stream: typing.Union[typing.BinaryIO, str]) -> None:
|
|
@@ -31,11 +34,14 @@ class BinaryMrdWriter(_binary.BinaryProtocolWriter, MrdWriterBase):
|
|
|
31
34
|
_binary.OptionalSerializer(HeaderSerializer()).write(self._stream, value)
|
|
32
35
|
|
|
33
36
|
def _write_data(self, value: collections.abc.Iterable[StreamItem]) -> None:
|
|
34
|
-
_binary.StreamSerializer(_binary.UnionSerializer(StreamItem, [(StreamItem.Acquisition, AcquisitionSerializer()), (StreamItem.WaveformUint32, WaveformSerializer(_binary.uint32_serializer)), (StreamItem.ImageUint16, ImageSerializer(_binary.uint16_serializer)), (StreamItem.ImageInt16, ImageSerializer(_binary.int16_serializer)), (StreamItem.
|
|
37
|
+
_binary.StreamSerializer(_binary.UnionSerializer(StreamItem, [(StreamItem.Acquisition, AcquisitionSerializer()), (StreamItem.WaveformUint32, WaveformSerializer(_binary.uint32_serializer)), (StreamItem.ImageUint16, ImageSerializer(_binary.uint16_serializer)), (StreamItem.ImageInt16, ImageSerializer(_binary.int16_serializer)), (StreamItem.ImageUint32, ImageSerializer(_binary.uint32_serializer)), (StreamItem.ImageInt32, ImageSerializer(_binary.int32_serializer)), (StreamItem.ImageFloat, ImageSerializer(_binary.float32_serializer)), (StreamItem.ImageDouble, ImageSerializer(_binary.float64_serializer)), (StreamItem.ImageComplexFloat, ImageSerializer(_binary.complexfloat32_serializer)), (StreamItem.ImageComplexDouble, ImageSerializer(_binary.complexfloat64_serializer)), (StreamItem.AcquisitionBucket, AcquisitionBucketSerializer()), (StreamItem.ReconData, ReconDataSerializer()), (StreamItem.ArrayComplexFloat, _binary.DynamicNDArraySerializer(_binary.complexfloat32_serializer)), (StreamItem.ImageArray, ImageArraySerializer())])).write(self._stream, value)
|
|
35
38
|
|
|
36
39
|
|
|
37
40
|
class BinaryMrdReader(_binary.BinaryProtocolReader, MrdReaderBase):
|
|
38
|
-
"""Binary writer for the Mrd protocol.
|
|
41
|
+
"""Binary writer for the Mrd protocol.
|
|
42
|
+
|
|
43
|
+
The MRD Protocol
|
|
44
|
+
"""
|
|
39
45
|
|
|
40
46
|
|
|
41
47
|
def __init__(self, stream: typing.Union[io.BufferedReader, io.BytesIO, typing.BinaryIO, str]) -> None:
|
|
@@ -46,7 +52,36 @@ class BinaryMrdReader(_binary.BinaryProtocolReader, MrdReaderBase):
|
|
|
46
52
|
return _binary.OptionalSerializer(HeaderSerializer()).read(self._stream)
|
|
47
53
|
|
|
48
54
|
def _read_data(self) -> collections.abc.Iterable[StreamItem]:
|
|
49
|
-
return _binary.StreamSerializer(_binary.UnionSerializer(StreamItem, [(StreamItem.Acquisition, AcquisitionSerializer()), (StreamItem.WaveformUint32, WaveformSerializer(_binary.uint32_serializer)), (StreamItem.ImageUint16, ImageSerializer(_binary.uint16_serializer)), (StreamItem.ImageInt16, ImageSerializer(_binary.int16_serializer)), (StreamItem.
|
|
55
|
+
return _binary.StreamSerializer(_binary.UnionSerializer(StreamItem, [(StreamItem.Acquisition, AcquisitionSerializer()), (StreamItem.WaveformUint32, WaveformSerializer(_binary.uint32_serializer)), (StreamItem.ImageUint16, ImageSerializer(_binary.uint16_serializer)), (StreamItem.ImageInt16, ImageSerializer(_binary.int16_serializer)), (StreamItem.ImageUint32, ImageSerializer(_binary.uint32_serializer)), (StreamItem.ImageInt32, ImageSerializer(_binary.int32_serializer)), (StreamItem.ImageFloat, ImageSerializer(_binary.float32_serializer)), (StreamItem.ImageDouble, ImageSerializer(_binary.float64_serializer)), (StreamItem.ImageComplexFloat, ImageSerializer(_binary.complexfloat32_serializer)), (StreamItem.ImageComplexDouble, ImageSerializer(_binary.complexfloat64_serializer)), (StreamItem.AcquisitionBucket, AcquisitionBucketSerializer()), (StreamItem.ReconData, ReconDataSerializer()), (StreamItem.ArrayComplexFloat, _binary.DynamicNDArraySerializer(_binary.complexfloat32_serializer)), (StreamItem.ImageArray, ImageArraySerializer())])).read(self._stream)
|
|
56
|
+
|
|
57
|
+
class BinaryMrdNoiseCovarianceWriter(_binary.BinaryProtocolWriter, MrdNoiseCovarianceWriterBase):
|
|
58
|
+
"""Binary writer for the MrdNoiseCovariance protocol.
|
|
59
|
+
|
|
60
|
+
Protocol for serializing a noise covariance matrix
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def __init__(self, stream: typing.Union[typing.BinaryIO, str]) -> None:
|
|
65
|
+
MrdNoiseCovarianceWriterBase.__init__(self)
|
|
66
|
+
_binary.BinaryProtocolWriter.__init__(self, stream, MrdNoiseCovarianceWriterBase.schema)
|
|
67
|
+
|
|
68
|
+
def _write_noise_covariance(self, value: NoiseCovariance) -> None:
|
|
69
|
+
NoiseCovarianceSerializer().write(self._stream, value)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class BinaryMrdNoiseCovarianceReader(_binary.BinaryProtocolReader, MrdNoiseCovarianceReaderBase):
|
|
73
|
+
"""Binary writer for the MrdNoiseCovariance protocol.
|
|
74
|
+
|
|
75
|
+
Protocol for serializing a noise covariance matrix
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def __init__(self, stream: typing.Union[io.BufferedReader, io.BytesIO, typing.BinaryIO, str]) -> None:
|
|
80
|
+
MrdNoiseCovarianceReaderBase.__init__(self)
|
|
81
|
+
_binary.BinaryProtocolReader.__init__(self, stream, MrdNoiseCovarianceReaderBase.schema)
|
|
82
|
+
|
|
83
|
+
def _read_noise_covariance(self) -> NoiseCovariance:
|
|
84
|
+
return NoiseCovarianceSerializer().read(self._stream)
|
|
50
85
|
|
|
51
86
|
class EncodingCountersSerializer(_binary.RecordSerializer[EncodingCounters]):
|
|
52
87
|
def __init__(self) -> None:
|
|
@@ -66,22 +101,40 @@ class EncodingCountersSerializer(_binary.RecordSerializer[EncodingCounters]):
|
|
|
66
101
|
return EncodingCounters(kspace_encode_step_1=field_values[0], kspace_encode_step_2=field_values[1], average=field_values[2], slice=field_values[3], contrast=field_values[4], phase=field_values[5], repetition=field_values[6], set=field_values[7], segment=field_values[8], user=field_values[9])
|
|
67
102
|
|
|
68
103
|
|
|
104
|
+
class AcquisitionHeaderSerializer(_binary.RecordSerializer[AcquisitionHeader]):
|
|
105
|
+
def __init__(self) -> None:
|
|
106
|
+
super().__init__([("flags", _binary.EnumSerializer(_binary.uint64_serializer, AcquisitionFlags)), ("idx", EncodingCountersSerializer()), ("measurement_uid", _binary.uint32_serializer), ("scan_counter", _binary.OptionalSerializer(_binary.uint32_serializer)), ("acquisition_time_stamp", _binary.OptionalSerializer(_binary.uint32_serializer)), ("physiology_time_stamp", _binary.VectorSerializer(_binary.uint32_serializer)), ("channel_order", _binary.VectorSerializer(_binary.uint32_serializer)), ("discard_pre", _binary.OptionalSerializer(_binary.uint32_serializer)), ("discard_post", _binary.OptionalSerializer(_binary.uint32_serializer)), ("center_sample", _binary.OptionalSerializer(_binary.uint32_serializer)), ("encoding_space_ref", _binary.OptionalSerializer(_binary.uint32_serializer)), ("sample_time_us", _binary.OptionalSerializer(_binary.float32_serializer)), ("position", _binary.FixedNDArraySerializer(_binary.float32_serializer, (3,))), ("read_dir", _binary.FixedNDArraySerializer(_binary.float32_serializer, (3,))), ("phase_dir", _binary.FixedNDArraySerializer(_binary.float32_serializer, (3,))), ("slice_dir", _binary.FixedNDArraySerializer(_binary.float32_serializer, (3,))), ("patient_table_position", _binary.FixedNDArraySerializer(_binary.float32_serializer, (3,))), ("user_int", _binary.VectorSerializer(_binary.int32_serializer)), ("user_float", _binary.VectorSerializer(_binary.float32_serializer))])
|
|
107
|
+
|
|
108
|
+
def write(self, stream: _binary.CodedOutputStream, value: AcquisitionHeader) -> None:
|
|
109
|
+
if isinstance(value, np.void):
|
|
110
|
+
self.write_numpy(stream, value)
|
|
111
|
+
return
|
|
112
|
+
self._write(stream, value.flags, value.idx, value.measurement_uid, value.scan_counter, value.acquisition_time_stamp, value.physiology_time_stamp, value.channel_order, value.discard_pre, value.discard_post, value.center_sample, value.encoding_space_ref, value.sample_time_us, value.position, value.read_dir, value.phase_dir, value.slice_dir, value.patient_table_position, value.user_int, value.user_float)
|
|
113
|
+
|
|
114
|
+
def write_numpy(self, stream: _binary.CodedOutputStream, value: np.void) -> None:
|
|
115
|
+
self._write(stream, value['flags'], value['idx'], value['measurement_uid'], value['scan_counter'], value['acquisition_time_stamp'], value['physiology_time_stamp'], value['channel_order'], value['discard_pre'], value['discard_post'], value['center_sample'], value['encoding_space_ref'], value['sample_time_us'], value['position'], value['read_dir'], value['phase_dir'], value['slice_dir'], value['patient_table_position'], value['user_int'], value['user_float'])
|
|
116
|
+
|
|
117
|
+
def read(self, stream: _binary.CodedInputStream) -> AcquisitionHeader:
|
|
118
|
+
field_values = self._read(stream)
|
|
119
|
+
return AcquisitionHeader(flags=field_values[0], idx=field_values[1], measurement_uid=field_values[2], scan_counter=field_values[3], acquisition_time_stamp=field_values[4], physiology_time_stamp=field_values[5], channel_order=field_values[6], discard_pre=field_values[7], discard_post=field_values[8], center_sample=field_values[9], encoding_space_ref=field_values[10], sample_time_us=field_values[11], position=field_values[12], read_dir=field_values[13], phase_dir=field_values[14], slice_dir=field_values[15], patient_table_position=field_values[16], user_int=field_values[17], user_float=field_values[18])
|
|
120
|
+
|
|
121
|
+
|
|
69
122
|
class AcquisitionSerializer(_binary.RecordSerializer[Acquisition]):
|
|
70
123
|
def __init__(self) -> None:
|
|
71
|
-
super().__init__([("
|
|
124
|
+
super().__init__([("head", AcquisitionHeaderSerializer()), ("data", _binary.NDArraySerializer(_binary.complexfloat32_serializer, 2)), ("trajectory", _binary.NDArraySerializer(_binary.float32_serializer, 2))])
|
|
72
125
|
|
|
73
126
|
def write(self, stream: _binary.CodedOutputStream, value: Acquisition) -> None:
|
|
74
127
|
if isinstance(value, np.void):
|
|
75
128
|
self.write_numpy(stream, value)
|
|
76
129
|
return
|
|
77
|
-
self._write(stream, value.
|
|
130
|
+
self._write(stream, value.head, value.data, value.trajectory)
|
|
78
131
|
|
|
79
132
|
def write_numpy(self, stream: _binary.CodedOutputStream, value: np.void) -> None:
|
|
80
|
-
self._write(stream, value['
|
|
133
|
+
self._write(stream, value['head'], value['data'], value['trajectory'])
|
|
81
134
|
|
|
82
135
|
def read(self, stream: _binary.CodedInputStream) -> Acquisition:
|
|
83
136
|
field_values = self._read(stream)
|
|
84
|
-
return Acquisition(
|
|
137
|
+
return Acquisition(head=field_values[0], data=field_values[1], trajectory=field_values[2])
|
|
85
138
|
|
|
86
139
|
|
|
87
140
|
class SubjectInformationTypeSerializer(_binary.RecordSerializer[SubjectInformationType]):
|
|
@@ -624,40 +677,58 @@ class HeaderSerializer(_binary.RecordSerializer[Header]):
|
|
|
624
677
|
return Header(version=field_values[0], subject_information=field_values[1], study_information=field_values[2], measurement_information=field_values[3], acquisition_system_information=field_values[4], experimental_conditions=field_values[5], encoding=field_values[6], sequence_parameters=field_values[7], user_parameters=field_values[8], waveform_information=field_values[9])
|
|
625
678
|
|
|
626
679
|
|
|
627
|
-
class
|
|
680
|
+
class ImageHeaderSerializer(_binary.RecordSerializer[ImageHeader]):
|
|
628
681
|
def __init__(self) -> None:
|
|
629
|
-
super().__init__([("
|
|
682
|
+
super().__init__([("flags", _binary.EnumSerializer(_binary.uint64_serializer, ImageFlags)), ("measurement_uid", _binary.uint32_serializer), ("field_of_view", _binary.FixedNDArraySerializer(_binary.float32_serializer, (3,))), ("position", _binary.FixedNDArraySerializer(_binary.float32_serializer, (3,))), ("col_dir", _binary.FixedNDArraySerializer(_binary.float32_serializer, (3,))), ("line_dir", _binary.FixedNDArraySerializer(_binary.float32_serializer, (3,))), ("slice_dir", _binary.FixedNDArraySerializer(_binary.float32_serializer, (3,))), ("patient_table_position", _binary.FixedNDArraySerializer(_binary.float32_serializer, (3,))), ("average", _binary.OptionalSerializer(_binary.uint32_serializer)), ("slice", _binary.OptionalSerializer(_binary.uint32_serializer)), ("contrast", _binary.OptionalSerializer(_binary.uint32_serializer)), ("phase", _binary.OptionalSerializer(_binary.uint32_serializer)), ("repetition", _binary.OptionalSerializer(_binary.uint32_serializer)), ("set", _binary.OptionalSerializer(_binary.uint32_serializer)), ("acquisition_time_stamp", _binary.OptionalSerializer(_binary.uint32_serializer)), ("physiology_time_stamp", _binary.VectorSerializer(_binary.uint32_serializer)), ("image_type", _binary.EnumSerializer(_binary.int32_serializer, ImageType)), ("image_index", _binary.OptionalSerializer(_binary.uint32_serializer)), ("image_series_index", _binary.OptionalSerializer(_binary.uint32_serializer)), ("user_int", _binary.VectorSerializer(_binary.int32_serializer)), ("user_float", _binary.VectorSerializer(_binary.float32_serializer))])
|
|
630
683
|
|
|
631
|
-
def write(self, stream: _binary.CodedOutputStream, value:
|
|
684
|
+
def write(self, stream: _binary.CodedOutputStream, value: ImageHeader) -> None:
|
|
632
685
|
if isinstance(value, np.void):
|
|
633
686
|
self.write_numpy(stream, value)
|
|
634
687
|
return
|
|
635
|
-
self._write(stream, value.
|
|
688
|
+
self._write(stream, value.flags, value.measurement_uid, value.field_of_view, value.position, value.col_dir, value.line_dir, value.slice_dir, value.patient_table_position, value.average, value.slice, value.contrast, value.phase, value.repetition, value.set, value.acquisition_time_stamp, value.physiology_time_stamp, value.image_type, value.image_index, value.image_series_index, value.user_int, value.user_float)
|
|
636
689
|
|
|
637
690
|
def write_numpy(self, stream: _binary.CodedOutputStream, value: np.void) -> None:
|
|
638
|
-
self._write(stream, value['
|
|
691
|
+
self._write(stream, value['flags'], value['measurement_uid'], value['field_of_view'], value['position'], value['col_dir'], value['line_dir'], value['slice_dir'], value['patient_table_position'], value['average'], value['slice'], value['contrast'], value['phase'], value['repetition'], value['set'], value['acquisition_time_stamp'], value['physiology_time_stamp'], value['image_type'], value['image_index'], value['image_series_index'], value['user_int'], value['user_float'])
|
|
639
692
|
|
|
640
|
-
def read(self, stream: _binary.CodedInputStream) ->
|
|
693
|
+
def read(self, stream: _binary.CodedInputStream) -> ImageHeader:
|
|
641
694
|
field_values = self._read(stream)
|
|
642
|
-
return
|
|
695
|
+
return ImageHeader(flags=field_values[0], measurement_uid=field_values[1], field_of_view=field_values[2], position=field_values[3], col_dir=field_values[4], line_dir=field_values[5], slice_dir=field_values[6], patient_table_position=field_values[7], average=field_values[8], slice=field_values[9], contrast=field_values[10], phase=field_values[11], repetition=field_values[12], set=field_values[13], acquisition_time_stamp=field_values[14], physiology_time_stamp=field_values[15], image_type=field_values[16], image_index=field_values[17], image_series_index=field_values[18], user_int=field_values[19], user_float=field_values[20])
|
|
643
696
|
|
|
644
697
|
|
|
645
698
|
class ImageSerializer(typing.Generic[T, T_NP], _binary.RecordSerializer[Image[T_NP]]):
|
|
646
699
|
def __init__(self, t_serializer: _binary.TypeSerializer[T, T_NP]) -> None:
|
|
647
|
-
super().__init__([("
|
|
700
|
+
super().__init__([("head", ImageHeaderSerializer()), ("data", _binary.NDArraySerializer(t_serializer, 4)), ("meta", _binary.MapSerializer(_binary.string_serializer, _binary.VectorSerializer(_binary.UnionSerializer(ImageMetaValue, [(ImageMetaValue.String, _binary.string_serializer), (ImageMetaValue.Int64, _binary.int64_serializer), (ImageMetaValue.Float64, _binary.float64_serializer)]))))])
|
|
648
701
|
|
|
649
702
|
def write(self, stream: _binary.CodedOutputStream, value: Image[T_NP]) -> None:
|
|
650
703
|
if isinstance(value, np.void):
|
|
651
704
|
self.write_numpy(stream, value)
|
|
652
705
|
return
|
|
653
|
-
self._write(stream, value.
|
|
706
|
+
self._write(stream, value.head, value.data, value.meta)
|
|
654
707
|
|
|
655
708
|
def write_numpy(self, stream: _binary.CodedOutputStream, value: np.void) -> None:
|
|
656
|
-
self._write(stream, value['
|
|
709
|
+
self._write(stream, value['head'], value['data'], value['meta'])
|
|
657
710
|
|
|
658
711
|
def read(self, stream: _binary.CodedInputStream) -> Image[T_NP]:
|
|
659
712
|
field_values = self._read(stream)
|
|
660
|
-
return Image[T_NP](
|
|
713
|
+
return Image[T_NP](head=field_values[0], data=field_values[1], meta=field_values[2])
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
class NoiseCovarianceSerializer(_binary.RecordSerializer[NoiseCovariance]):
|
|
717
|
+
def __init__(self) -> None:
|
|
718
|
+
super().__init__([("coil_labels", _binary.VectorSerializer(CoilLabelTypeSerializer())), ("receiver_noise_bandwidth", _binary.float32_serializer), ("noise_dwell_time_us", _binary.float32_serializer), ("sample_count", _binary.size_serializer), ("matrix", _binary.NDArraySerializer(_binary.complexfloat32_serializer, 2))])
|
|
719
|
+
|
|
720
|
+
def write(self, stream: _binary.CodedOutputStream, value: NoiseCovariance) -> None:
|
|
721
|
+
if isinstance(value, np.void):
|
|
722
|
+
self.write_numpy(stream, value)
|
|
723
|
+
return
|
|
724
|
+
self._write(stream, value.coil_labels, value.receiver_noise_bandwidth, value.noise_dwell_time_us, value.sample_count, value.matrix)
|
|
725
|
+
|
|
726
|
+
def write_numpy(self, stream: _binary.CodedOutputStream, value: np.void) -> None:
|
|
727
|
+
self._write(stream, value['coil_labels'], value['receiver_noise_bandwidth'], value['noise_dwell_time_us'], value['sample_count'], value['matrix'])
|
|
728
|
+
|
|
729
|
+
def read(self, stream: _binary.CodedInputStream) -> NoiseCovariance:
|
|
730
|
+
field_values = self._read(stream)
|
|
731
|
+
return NoiseCovariance(coil_labels=field_values[0], receiver_noise_bandwidth=field_values[1], noise_dwell_time_us=field_values[2], sample_count=field_values[3], matrix=field_values[4])
|
|
661
732
|
|
|
662
733
|
|
|
663
734
|
class WaveformSerializer(typing.Generic[T, T_NP], _binary.RecordSerializer[Waveform[T_NP]]):
|
|
@@ -678,3 +749,129 @@ class WaveformSerializer(typing.Generic[T, T_NP], _binary.RecordSerializer[Wavef
|
|
|
678
749
|
return Waveform[T_NP](flags=field_values[0], measurement_uid=field_values[1], scan_counter=field_values[2], time_stamp=field_values[3], sample_time_us=field_values[4], waveform_id=field_values[5], data=field_values[6])
|
|
679
750
|
|
|
680
751
|
|
|
752
|
+
class AcquisitionBucketSerializer(_binary.RecordSerializer[AcquisitionBucket]):
|
|
753
|
+
def __init__(self) -> None:
|
|
754
|
+
super().__init__([("data", _binary.VectorSerializer(AcquisitionSerializer())), ("ref", _binary.VectorSerializer(AcquisitionSerializer())), ("datastats", _binary.VectorSerializer(EncodingLimitsTypeSerializer())), ("refstats", _binary.VectorSerializer(EncodingLimitsTypeSerializer())), ("waveforms", _binary.VectorSerializer(WaveformSerializer(_binary.uint32_serializer)))])
|
|
755
|
+
|
|
756
|
+
def write(self, stream: _binary.CodedOutputStream, value: AcquisitionBucket) -> None:
|
|
757
|
+
if isinstance(value, np.void):
|
|
758
|
+
self.write_numpy(stream, value)
|
|
759
|
+
return
|
|
760
|
+
self._write(stream, value.data, value.ref, value.datastats, value.refstats, value.waveforms)
|
|
761
|
+
|
|
762
|
+
def write_numpy(self, stream: _binary.CodedOutputStream, value: np.void) -> None:
|
|
763
|
+
self._write(stream, value['data'], value['ref'], value['datastats'], value['refstats'], value['waveforms'])
|
|
764
|
+
|
|
765
|
+
def read(self, stream: _binary.CodedInputStream) -> AcquisitionBucket:
|
|
766
|
+
field_values = self._read(stream)
|
|
767
|
+
return AcquisitionBucket(data=field_values[0], ref=field_values[1], datastats=field_values[2], refstats=field_values[3], waveforms=field_values[4])
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
class SamplingLimitsSerializer(_binary.RecordSerializer[SamplingLimits]):
|
|
771
|
+
def __init__(self) -> None:
|
|
772
|
+
super().__init__([("kspace_encoding_step_0", LimitTypeSerializer()), ("kspace_encoding_step_1", LimitTypeSerializer()), ("kspace_encoding_step_2", LimitTypeSerializer())])
|
|
773
|
+
|
|
774
|
+
def write(self, stream: _binary.CodedOutputStream, value: SamplingLimits) -> None:
|
|
775
|
+
if isinstance(value, np.void):
|
|
776
|
+
self.write_numpy(stream, value)
|
|
777
|
+
return
|
|
778
|
+
self._write(stream, value.kspace_encoding_step_0, value.kspace_encoding_step_1, value.kspace_encoding_step_2)
|
|
779
|
+
|
|
780
|
+
def write_numpy(self, stream: _binary.CodedOutputStream, value: np.void) -> None:
|
|
781
|
+
self._write(stream, value['kspace_encoding_step_0'], value['kspace_encoding_step_1'], value['kspace_encoding_step_2'])
|
|
782
|
+
|
|
783
|
+
def read(self, stream: _binary.CodedInputStream) -> SamplingLimits:
|
|
784
|
+
field_values = self._read(stream)
|
|
785
|
+
return SamplingLimits(kspace_encoding_step_0=field_values[0], kspace_encoding_step_1=field_values[1], kspace_encoding_step_2=field_values[2])
|
|
786
|
+
|
|
787
|
+
|
|
788
|
+
class SamplingDescriptionSerializer(_binary.RecordSerializer[SamplingDescription]):
|
|
789
|
+
def __init__(self) -> None:
|
|
790
|
+
super().__init__([("encoded_fov", FieldOfViewMmSerializer()), ("recon_fov", FieldOfViewMmSerializer()), ("encoded_matrix", MatrixSizeTypeSerializer()), ("recon_matrix", MatrixSizeTypeSerializer()), ("sampling_limits", SamplingLimitsSerializer())])
|
|
791
|
+
|
|
792
|
+
def write(self, stream: _binary.CodedOutputStream, value: SamplingDescription) -> None:
|
|
793
|
+
if isinstance(value, np.void):
|
|
794
|
+
self.write_numpy(stream, value)
|
|
795
|
+
return
|
|
796
|
+
self._write(stream, value.encoded_fov, value.recon_fov, value.encoded_matrix, value.recon_matrix, value.sampling_limits)
|
|
797
|
+
|
|
798
|
+
def write_numpy(self, stream: _binary.CodedOutputStream, value: np.void) -> None:
|
|
799
|
+
self._write(stream, value['encoded_fov'], value['recon_fov'], value['encoded_matrix'], value['recon_matrix'], value['sampling_limits'])
|
|
800
|
+
|
|
801
|
+
def read(self, stream: _binary.CodedInputStream) -> SamplingDescription:
|
|
802
|
+
field_values = self._read(stream)
|
|
803
|
+
return SamplingDescription(encoded_fov=field_values[0], recon_fov=field_values[1], encoded_matrix=field_values[2], recon_matrix=field_values[3], sampling_limits=field_values[4])
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
class ReconBufferSerializer(_binary.RecordSerializer[ReconBuffer]):
|
|
807
|
+
def __init__(self) -> None:
|
|
808
|
+
super().__init__([("data", _binary.NDArraySerializer(_binary.complexfloat32_serializer, 7)), ("trajectory", _binary.NDArraySerializer(_binary.float32_serializer, 7)), ("density", _binary.OptionalSerializer(_binary.NDArraySerializer(_binary.float32_serializer, 6))), ("headers", _binary.NDArraySerializer(AcquisitionHeaderSerializer(), 5)), ("sampling", SamplingDescriptionSerializer())])
|
|
809
|
+
|
|
810
|
+
def write(self, stream: _binary.CodedOutputStream, value: ReconBuffer) -> None:
|
|
811
|
+
if isinstance(value, np.void):
|
|
812
|
+
self.write_numpy(stream, value)
|
|
813
|
+
return
|
|
814
|
+
self._write(stream, value.data, value.trajectory, value.density, value.headers, value.sampling)
|
|
815
|
+
|
|
816
|
+
def write_numpy(self, stream: _binary.CodedOutputStream, value: np.void) -> None:
|
|
817
|
+
self._write(stream, value['data'], value['trajectory'], value['density'], value['headers'], value['sampling'])
|
|
818
|
+
|
|
819
|
+
def read(self, stream: _binary.CodedInputStream) -> ReconBuffer:
|
|
820
|
+
field_values = self._read(stream)
|
|
821
|
+
return ReconBuffer(data=field_values[0], trajectory=field_values[1], density=field_values[2], headers=field_values[3], sampling=field_values[4])
|
|
822
|
+
|
|
823
|
+
|
|
824
|
+
class ReconAssemblySerializer(_binary.RecordSerializer[ReconAssembly]):
|
|
825
|
+
def __init__(self) -> None:
|
|
826
|
+
super().__init__([("data", ReconBufferSerializer()), ("ref", _binary.OptionalSerializer(ReconBufferSerializer()))])
|
|
827
|
+
|
|
828
|
+
def write(self, stream: _binary.CodedOutputStream, value: ReconAssembly) -> None:
|
|
829
|
+
if isinstance(value, np.void):
|
|
830
|
+
self.write_numpy(stream, value)
|
|
831
|
+
return
|
|
832
|
+
self._write(stream, value.data, value.ref)
|
|
833
|
+
|
|
834
|
+
def write_numpy(self, stream: _binary.CodedOutputStream, value: np.void) -> None:
|
|
835
|
+
self._write(stream, value['data'], value['ref'])
|
|
836
|
+
|
|
837
|
+
def read(self, stream: _binary.CodedInputStream) -> ReconAssembly:
|
|
838
|
+
field_values = self._read(stream)
|
|
839
|
+
return ReconAssembly(data=field_values[0], ref=field_values[1])
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
class ReconDataSerializer(_binary.RecordSerializer[ReconData]):
|
|
843
|
+
def __init__(self) -> None:
|
|
844
|
+
super().__init__([("buffers", _binary.VectorSerializer(ReconAssemblySerializer()))])
|
|
845
|
+
|
|
846
|
+
def write(self, stream: _binary.CodedOutputStream, value: ReconData) -> None:
|
|
847
|
+
if isinstance(value, np.void):
|
|
848
|
+
self.write_numpy(stream, value)
|
|
849
|
+
return
|
|
850
|
+
self._write(stream, value.buffers)
|
|
851
|
+
|
|
852
|
+
def write_numpy(self, stream: _binary.CodedOutputStream, value: np.void) -> None:
|
|
853
|
+
self._write(stream, value['buffers'])
|
|
854
|
+
|
|
855
|
+
def read(self, stream: _binary.CodedInputStream) -> ReconData:
|
|
856
|
+
field_values = self._read(stream)
|
|
857
|
+
return ReconData(buffers=field_values[0])
|
|
858
|
+
|
|
859
|
+
|
|
860
|
+
class ImageArraySerializer(_binary.RecordSerializer[ImageArray]):
|
|
861
|
+
def __init__(self) -> None:
|
|
862
|
+
super().__init__([("data", _binary.NDArraySerializer(_binary.complexfloat32_serializer, 7)), ("headers", _binary.NDArraySerializer(ImageHeaderSerializer(), 3)), ("meta", _binary.NDArraySerializer(_binary.MapSerializer(_binary.string_serializer, _binary.VectorSerializer(_binary.UnionSerializer(ImageMetaValue, [(ImageMetaValue.String, _binary.string_serializer), (ImageMetaValue.Int64, _binary.int64_serializer), (ImageMetaValue.Float64, _binary.float64_serializer)]))), 3)), ("waveforms", _binary.VectorSerializer(WaveformSerializer(_binary.uint32_serializer)))])
|
|
863
|
+
|
|
864
|
+
def write(self, stream: _binary.CodedOutputStream, value: ImageArray) -> None:
|
|
865
|
+
if isinstance(value, np.void):
|
|
866
|
+
self.write_numpy(stream, value)
|
|
867
|
+
return
|
|
868
|
+
self._write(stream, value.data, value.headers, value.meta, value.waveforms)
|
|
869
|
+
|
|
870
|
+
def write_numpy(self, stream: _binary.CodedOutputStream, value: np.void) -> None:
|
|
871
|
+
self._write(stream, value['data'], value['headers'], value['meta'], value['waveforms'])
|
|
872
|
+
|
|
873
|
+
def read(self, stream: _binary.CodedInputStream) -> ImageArray:
|
|
874
|
+
field_values = self._read(stream)
|
|
875
|
+
return ImageArray(data=field_values[0], headers=field_values[1], meta=field_values[2], waveforms=field_values[3])
|
|
876
|
+
|
|
877
|
+
|