mrd-python 2.0.0__py3-none-any.whl
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/__init__.py +96 -0
- mrd/_binary.py +1339 -0
- mrd/_dtypes.py +89 -0
- mrd/_ndjson.py +1194 -0
- mrd/binary.py +680 -0
- mrd/ndjson.py +2716 -0
- mrd/protocols.py +180 -0
- mrd/tools/export_png_images.py +39 -0
- mrd/tools/minimal_example.py +27 -0
- mrd/tools/phantom.py +161 -0
- mrd/tools/simulation.py +173 -0
- mrd/tools/stream_recon.py +184 -0
- mrd/tools/transform.py +37 -0
- mrd/types.py +1840 -0
- mrd/yardl_types.py +303 -0
- mrd_python-2.0.0.dist-info/METADATA +19 -0
- mrd_python-2.0.0.dist-info/RECORD +19 -0
- mrd_python-2.0.0.dist-info/WHEEL +5 -0
- mrd_python-2.0.0.dist-info/top_level.txt +1 -0
mrd/ndjson.py
ADDED
|
@@ -0,0 +1,2716 @@
|
|
|
1
|
+
# This file was generated by the "yardl" tool. DO NOT EDIT.
|
|
2
|
+
|
|
3
|
+
# pyright: reportUnusedClass=false
|
|
4
|
+
# pyright: reportUnusedImport=false
|
|
5
|
+
# pyright: reportUnknownArgumentType=false
|
|
6
|
+
# pyright: reportUnknownMemberType=false
|
|
7
|
+
# pyright: reportUnknownVariableType=false
|
|
8
|
+
|
|
9
|
+
import collections.abc
|
|
10
|
+
import io
|
|
11
|
+
import typing
|
|
12
|
+
|
|
13
|
+
import numpy as np
|
|
14
|
+
import numpy.typing as npt
|
|
15
|
+
|
|
16
|
+
from .types import *
|
|
17
|
+
|
|
18
|
+
from .protocols import *
|
|
19
|
+
from . import _ndjson
|
|
20
|
+
from . import yardl_types as yardl
|
|
21
|
+
|
|
22
|
+
acquisition_flags_name_to_value_map = {
|
|
23
|
+
"firstInEncodeStep1": AcquisitionFlags.FIRST_IN_ENCODE_STEP_1,
|
|
24
|
+
"lastInEncodeStep1": AcquisitionFlags.LAST_IN_ENCODE_STEP_1,
|
|
25
|
+
"firstInEncodeStep2": AcquisitionFlags.FIRST_IN_ENCODE_STEP_2,
|
|
26
|
+
"lastInEncodeStep2": AcquisitionFlags.LAST_IN_ENCODE_STEP_2,
|
|
27
|
+
"firstInAverage": AcquisitionFlags.FIRST_IN_AVERAGE,
|
|
28
|
+
"lastInAverage": AcquisitionFlags.LAST_IN_AVERAGE,
|
|
29
|
+
"firstInSlice": AcquisitionFlags.FIRST_IN_SLICE,
|
|
30
|
+
"lastInSlice": AcquisitionFlags.LAST_IN_SLICE,
|
|
31
|
+
"firstInContrast": AcquisitionFlags.FIRST_IN_CONTRAST,
|
|
32
|
+
"lastInContrast": AcquisitionFlags.LAST_IN_CONTRAST,
|
|
33
|
+
"firstInPhase": AcquisitionFlags.FIRST_IN_PHASE,
|
|
34
|
+
"lastInPhase": AcquisitionFlags.LAST_IN_PHASE,
|
|
35
|
+
"firstInRepetition": AcquisitionFlags.FIRST_IN_REPETITION,
|
|
36
|
+
"lastInRepetition": AcquisitionFlags.LAST_IN_REPETITION,
|
|
37
|
+
"firstInSet": AcquisitionFlags.FIRST_IN_SET,
|
|
38
|
+
"lastInSet": AcquisitionFlags.LAST_IN_SET,
|
|
39
|
+
"firstInSegment": AcquisitionFlags.FIRST_IN_SEGMENT,
|
|
40
|
+
"lastInSegment": AcquisitionFlags.LAST_IN_SEGMENT,
|
|
41
|
+
"isNoiseMeasurement": AcquisitionFlags.IS_NOISE_MEASUREMENT,
|
|
42
|
+
"isParallelCalibration": AcquisitionFlags.IS_PARALLEL_CALIBRATION,
|
|
43
|
+
"isParallelCalibrationAndImaging": AcquisitionFlags.IS_PARALLEL_CALIBRATION_AND_IMAGING,
|
|
44
|
+
"isReverse": AcquisitionFlags.IS_REVERSE,
|
|
45
|
+
"isNavigationData": AcquisitionFlags.IS_NAVIGATION_DATA,
|
|
46
|
+
"isPhasecorrData": AcquisitionFlags.IS_PHASECORR_DATA,
|
|
47
|
+
"lastInMeasurement": AcquisitionFlags.LAST_IN_MEASUREMENT,
|
|
48
|
+
"isHpfeedbackData": AcquisitionFlags.IS_HPFEEDBACK_DATA,
|
|
49
|
+
"isDummyscanData": AcquisitionFlags.IS_DUMMYSCAN_DATA,
|
|
50
|
+
"isRtfeedbackData": AcquisitionFlags.IS_RTFEEDBACK_DATA,
|
|
51
|
+
"isSurfacecoilcorrectionscanData": AcquisitionFlags.IS_SURFACECOILCORRECTIONSCAN_DATA,
|
|
52
|
+
"isPhaseStabilizationReference": AcquisitionFlags.IS_PHASE_STABILIZATION_REFERENCE,
|
|
53
|
+
"isPhaseStabilization": AcquisitionFlags.IS_PHASE_STABILIZATION,
|
|
54
|
+
}
|
|
55
|
+
acquisition_flags_value_to_name_map = {v: n for n, v in acquisition_flags_name_to_value_map.items()}
|
|
56
|
+
|
|
57
|
+
class EncodingCountersConverter(_ndjson.JsonConverter[EncodingCounters, np.void]):
|
|
58
|
+
def __init__(self) -> None:
|
|
59
|
+
self._kspace_encode_step_1_converter = _ndjson.OptionalConverter(_ndjson.uint32_converter)
|
|
60
|
+
self._kspace_encode_step_2_converter = _ndjson.OptionalConverter(_ndjson.uint32_converter)
|
|
61
|
+
self._average_converter = _ndjson.OptionalConverter(_ndjson.uint32_converter)
|
|
62
|
+
self._slice_converter = _ndjson.OptionalConverter(_ndjson.uint32_converter)
|
|
63
|
+
self._contrast_converter = _ndjson.OptionalConverter(_ndjson.uint32_converter)
|
|
64
|
+
self._phase_converter = _ndjson.OptionalConverter(_ndjson.uint32_converter)
|
|
65
|
+
self._repetition_converter = _ndjson.OptionalConverter(_ndjson.uint32_converter)
|
|
66
|
+
self._set_converter = _ndjson.OptionalConverter(_ndjson.uint32_converter)
|
|
67
|
+
self._segment_converter = _ndjson.OptionalConverter(_ndjson.uint32_converter)
|
|
68
|
+
self._user_converter = _ndjson.VectorConverter(_ndjson.uint32_converter)
|
|
69
|
+
super().__init__(np.dtype([
|
|
70
|
+
("kspace_encode_step_1", self._kspace_encode_step_1_converter.overall_dtype()),
|
|
71
|
+
("kspace_encode_step_2", self._kspace_encode_step_2_converter.overall_dtype()),
|
|
72
|
+
("average", self._average_converter.overall_dtype()),
|
|
73
|
+
("slice", self._slice_converter.overall_dtype()),
|
|
74
|
+
("contrast", self._contrast_converter.overall_dtype()),
|
|
75
|
+
("phase", self._phase_converter.overall_dtype()),
|
|
76
|
+
("repetition", self._repetition_converter.overall_dtype()),
|
|
77
|
+
("set", self._set_converter.overall_dtype()),
|
|
78
|
+
("segment", self._segment_converter.overall_dtype()),
|
|
79
|
+
("user", self._user_converter.overall_dtype()),
|
|
80
|
+
]))
|
|
81
|
+
|
|
82
|
+
def to_json(self, value: EncodingCounters) -> object:
|
|
83
|
+
if not isinstance(value, EncodingCounters): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
84
|
+
raise TypeError("Expected 'EncodingCounters' instance")
|
|
85
|
+
json_object = {}
|
|
86
|
+
|
|
87
|
+
if value.kspace_encode_step_1 is not None:
|
|
88
|
+
json_object["kspaceEncodeStep1"] = self._kspace_encode_step_1_converter.to_json(value.kspace_encode_step_1)
|
|
89
|
+
if value.kspace_encode_step_2 is not None:
|
|
90
|
+
json_object["kspaceEncodeStep2"] = self._kspace_encode_step_2_converter.to_json(value.kspace_encode_step_2)
|
|
91
|
+
if value.average is not None:
|
|
92
|
+
json_object["average"] = self._average_converter.to_json(value.average)
|
|
93
|
+
if value.slice is not None:
|
|
94
|
+
json_object["slice"] = self._slice_converter.to_json(value.slice)
|
|
95
|
+
if value.contrast is not None:
|
|
96
|
+
json_object["contrast"] = self._contrast_converter.to_json(value.contrast)
|
|
97
|
+
if value.phase is not None:
|
|
98
|
+
json_object["phase"] = self._phase_converter.to_json(value.phase)
|
|
99
|
+
if value.repetition is not None:
|
|
100
|
+
json_object["repetition"] = self._repetition_converter.to_json(value.repetition)
|
|
101
|
+
if value.set is not None:
|
|
102
|
+
json_object["set"] = self._set_converter.to_json(value.set)
|
|
103
|
+
if value.segment is not None:
|
|
104
|
+
json_object["segment"] = self._segment_converter.to_json(value.segment)
|
|
105
|
+
json_object["user"] = self._user_converter.to_json(value.user)
|
|
106
|
+
return json_object
|
|
107
|
+
|
|
108
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
109
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
110
|
+
raise TypeError("Expected 'np.void' instance")
|
|
111
|
+
json_object = {}
|
|
112
|
+
|
|
113
|
+
if (field_val := value["kspace_encode_step_1"]) is not None:
|
|
114
|
+
json_object["kspaceEncodeStep1"] = self._kspace_encode_step_1_converter.numpy_to_json(field_val)
|
|
115
|
+
if (field_val := value["kspace_encode_step_2"]) is not None:
|
|
116
|
+
json_object["kspaceEncodeStep2"] = self._kspace_encode_step_2_converter.numpy_to_json(field_val)
|
|
117
|
+
if (field_val := value["average"]) is not None:
|
|
118
|
+
json_object["average"] = self._average_converter.numpy_to_json(field_val)
|
|
119
|
+
if (field_val := value["slice"]) is not None:
|
|
120
|
+
json_object["slice"] = self._slice_converter.numpy_to_json(field_val)
|
|
121
|
+
if (field_val := value["contrast"]) is not None:
|
|
122
|
+
json_object["contrast"] = self._contrast_converter.numpy_to_json(field_val)
|
|
123
|
+
if (field_val := value["phase"]) is not None:
|
|
124
|
+
json_object["phase"] = self._phase_converter.numpy_to_json(field_val)
|
|
125
|
+
if (field_val := value["repetition"]) is not None:
|
|
126
|
+
json_object["repetition"] = self._repetition_converter.numpy_to_json(field_val)
|
|
127
|
+
if (field_val := value["set"]) is not None:
|
|
128
|
+
json_object["set"] = self._set_converter.numpy_to_json(field_val)
|
|
129
|
+
if (field_val := value["segment"]) is not None:
|
|
130
|
+
json_object["segment"] = self._segment_converter.numpy_to_json(field_val)
|
|
131
|
+
json_object["user"] = self._user_converter.numpy_to_json(value["user"])
|
|
132
|
+
return json_object
|
|
133
|
+
|
|
134
|
+
def from_json(self, json_object: object) -> EncodingCounters:
|
|
135
|
+
if not isinstance(json_object, dict):
|
|
136
|
+
raise TypeError("Expected 'dict' instance")
|
|
137
|
+
return EncodingCounters(
|
|
138
|
+
kspace_encode_step_1=self._kspace_encode_step_1_converter.from_json(json_object.get("kspaceEncodeStep1")),
|
|
139
|
+
kspace_encode_step_2=self._kspace_encode_step_2_converter.from_json(json_object.get("kspaceEncodeStep2")),
|
|
140
|
+
average=self._average_converter.from_json(json_object.get("average")),
|
|
141
|
+
slice=self._slice_converter.from_json(json_object.get("slice")),
|
|
142
|
+
contrast=self._contrast_converter.from_json(json_object.get("contrast")),
|
|
143
|
+
phase=self._phase_converter.from_json(json_object.get("phase")),
|
|
144
|
+
repetition=self._repetition_converter.from_json(json_object.get("repetition")),
|
|
145
|
+
set=self._set_converter.from_json(json_object.get("set")),
|
|
146
|
+
segment=self._segment_converter.from_json(json_object.get("segment")),
|
|
147
|
+
user=self._user_converter.from_json(json_object["user"],),
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
151
|
+
if not isinstance(json_object, dict):
|
|
152
|
+
raise TypeError("Expected 'dict' instance")
|
|
153
|
+
return (
|
|
154
|
+
self._kspace_encode_step_1_converter.from_json_to_numpy(json_object.get("kspaceEncodeStep1")),
|
|
155
|
+
self._kspace_encode_step_2_converter.from_json_to_numpy(json_object.get("kspaceEncodeStep2")),
|
|
156
|
+
self._average_converter.from_json_to_numpy(json_object.get("average")),
|
|
157
|
+
self._slice_converter.from_json_to_numpy(json_object.get("slice")),
|
|
158
|
+
self._contrast_converter.from_json_to_numpy(json_object.get("contrast")),
|
|
159
|
+
self._phase_converter.from_json_to_numpy(json_object.get("phase")),
|
|
160
|
+
self._repetition_converter.from_json_to_numpy(json_object.get("repetition")),
|
|
161
|
+
self._set_converter.from_json_to_numpy(json_object.get("set")),
|
|
162
|
+
self._segment_converter.from_json_to_numpy(json_object.get("segment")),
|
|
163
|
+
self._user_converter.from_json_to_numpy(json_object["user"]),
|
|
164
|
+
) # type:ignore
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
class AcquisitionConverter(_ndjson.JsonConverter[Acquisition, np.void]):
|
|
168
|
+
def __init__(self) -> None:
|
|
169
|
+
self._flags_converter = _ndjson.FlagsConverter(AcquisitionFlags, np.uint64, acquisition_flags_name_to_value_map, acquisition_flags_value_to_name_map)
|
|
170
|
+
self._idx_converter = EncodingCountersConverter()
|
|
171
|
+
self._measurement_uid_converter = _ndjson.uint32_converter
|
|
172
|
+
self._scan_counter_converter = _ndjson.OptionalConverter(_ndjson.uint32_converter)
|
|
173
|
+
self._acquisition_time_stamp_converter = _ndjson.OptionalConverter(_ndjson.uint32_converter)
|
|
174
|
+
self._physiology_time_stamp_converter = _ndjson.VectorConverter(_ndjson.uint32_converter)
|
|
175
|
+
self._channel_order_converter = _ndjson.VectorConverter(_ndjson.uint32_converter)
|
|
176
|
+
self._discard_pre_converter = _ndjson.OptionalConverter(_ndjson.uint32_converter)
|
|
177
|
+
self._discard_post_converter = _ndjson.OptionalConverter(_ndjson.uint32_converter)
|
|
178
|
+
self._center_sample_converter = _ndjson.OptionalConverter(_ndjson.uint32_converter)
|
|
179
|
+
self._encoding_space_ref_converter = _ndjson.OptionalConverter(_ndjson.uint32_converter)
|
|
180
|
+
self._sample_time_us_converter = _ndjson.OptionalConverter(_ndjson.float32_converter)
|
|
181
|
+
self._position_converter = _ndjson.FixedNDArrayConverter(_ndjson.float32_converter, (3,))
|
|
182
|
+
self._read_dir_converter = _ndjson.FixedNDArrayConverter(_ndjson.float32_converter, (3,))
|
|
183
|
+
self._phase_dir_converter = _ndjson.FixedNDArrayConverter(_ndjson.float32_converter, (3,))
|
|
184
|
+
self._slice_dir_converter = _ndjson.FixedNDArrayConverter(_ndjson.float32_converter, (3,))
|
|
185
|
+
self._patient_table_position_converter = _ndjson.FixedNDArrayConverter(_ndjson.float32_converter, (3,))
|
|
186
|
+
self._user_int_converter = _ndjson.VectorConverter(_ndjson.int32_converter)
|
|
187
|
+
self._user_float_converter = _ndjson.VectorConverter(_ndjson.float32_converter)
|
|
188
|
+
self._data_converter = _ndjson.NDArrayConverter(_ndjson.complexfloat32_converter, 2)
|
|
189
|
+
self._trajectory_converter = _ndjson.NDArrayConverter(_ndjson.float32_converter, 2)
|
|
190
|
+
super().__init__(np.dtype([
|
|
191
|
+
("flags", self._flags_converter.overall_dtype()),
|
|
192
|
+
("idx", self._idx_converter.overall_dtype()),
|
|
193
|
+
("measurement_uid", self._measurement_uid_converter.overall_dtype()),
|
|
194
|
+
("scan_counter", self._scan_counter_converter.overall_dtype()),
|
|
195
|
+
("acquisition_time_stamp", self._acquisition_time_stamp_converter.overall_dtype()),
|
|
196
|
+
("physiology_time_stamp", self._physiology_time_stamp_converter.overall_dtype()),
|
|
197
|
+
("channel_order", self._channel_order_converter.overall_dtype()),
|
|
198
|
+
("discard_pre", self._discard_pre_converter.overall_dtype()),
|
|
199
|
+
("discard_post", self._discard_post_converter.overall_dtype()),
|
|
200
|
+
("center_sample", self._center_sample_converter.overall_dtype()),
|
|
201
|
+
("encoding_space_ref", self._encoding_space_ref_converter.overall_dtype()),
|
|
202
|
+
("sample_time_us", self._sample_time_us_converter.overall_dtype()),
|
|
203
|
+
("position", self._position_converter.overall_dtype()),
|
|
204
|
+
("read_dir", self._read_dir_converter.overall_dtype()),
|
|
205
|
+
("phase_dir", self._phase_dir_converter.overall_dtype()),
|
|
206
|
+
("slice_dir", self._slice_dir_converter.overall_dtype()),
|
|
207
|
+
("patient_table_position", self._patient_table_position_converter.overall_dtype()),
|
|
208
|
+
("user_int", self._user_int_converter.overall_dtype()),
|
|
209
|
+
("user_float", self._user_float_converter.overall_dtype()),
|
|
210
|
+
("data", self._data_converter.overall_dtype()),
|
|
211
|
+
("trajectory", self._trajectory_converter.overall_dtype()),
|
|
212
|
+
]))
|
|
213
|
+
|
|
214
|
+
def to_json(self, value: Acquisition) -> object:
|
|
215
|
+
if not isinstance(value, Acquisition): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
216
|
+
raise TypeError("Expected 'Acquisition' instance")
|
|
217
|
+
json_object = {}
|
|
218
|
+
|
|
219
|
+
json_object["flags"] = self._flags_converter.to_json(value.flags)
|
|
220
|
+
json_object["idx"] = self._idx_converter.to_json(value.idx)
|
|
221
|
+
json_object["measurementUid"] = self._measurement_uid_converter.to_json(value.measurement_uid)
|
|
222
|
+
if value.scan_counter is not None:
|
|
223
|
+
json_object["scanCounter"] = self._scan_counter_converter.to_json(value.scan_counter)
|
|
224
|
+
if value.acquisition_time_stamp is not None:
|
|
225
|
+
json_object["acquisitionTimeStamp"] = self._acquisition_time_stamp_converter.to_json(value.acquisition_time_stamp)
|
|
226
|
+
json_object["physiologyTimeStamp"] = self._physiology_time_stamp_converter.to_json(value.physiology_time_stamp)
|
|
227
|
+
json_object["channelOrder"] = self._channel_order_converter.to_json(value.channel_order)
|
|
228
|
+
if value.discard_pre is not None:
|
|
229
|
+
json_object["discardPre"] = self._discard_pre_converter.to_json(value.discard_pre)
|
|
230
|
+
if value.discard_post is not None:
|
|
231
|
+
json_object["discardPost"] = self._discard_post_converter.to_json(value.discard_post)
|
|
232
|
+
if value.center_sample is not None:
|
|
233
|
+
json_object["centerSample"] = self._center_sample_converter.to_json(value.center_sample)
|
|
234
|
+
if value.encoding_space_ref is not None:
|
|
235
|
+
json_object["encodingSpaceRef"] = self._encoding_space_ref_converter.to_json(value.encoding_space_ref)
|
|
236
|
+
if value.sample_time_us is not None:
|
|
237
|
+
json_object["sampleTimeUs"] = self._sample_time_us_converter.to_json(value.sample_time_us)
|
|
238
|
+
json_object["position"] = self._position_converter.to_json(value.position)
|
|
239
|
+
json_object["readDir"] = self._read_dir_converter.to_json(value.read_dir)
|
|
240
|
+
json_object["phaseDir"] = self._phase_dir_converter.to_json(value.phase_dir)
|
|
241
|
+
json_object["sliceDir"] = self._slice_dir_converter.to_json(value.slice_dir)
|
|
242
|
+
json_object["patientTablePosition"] = self._patient_table_position_converter.to_json(value.patient_table_position)
|
|
243
|
+
json_object["userInt"] = self._user_int_converter.to_json(value.user_int)
|
|
244
|
+
json_object["userFloat"] = self._user_float_converter.to_json(value.user_float)
|
|
245
|
+
json_object["data"] = self._data_converter.to_json(value.data)
|
|
246
|
+
json_object["trajectory"] = self._trajectory_converter.to_json(value.trajectory)
|
|
247
|
+
return json_object
|
|
248
|
+
|
|
249
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
250
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
251
|
+
raise TypeError("Expected 'np.void' instance")
|
|
252
|
+
json_object = {}
|
|
253
|
+
|
|
254
|
+
json_object["flags"] = self._flags_converter.numpy_to_json(value["flags"])
|
|
255
|
+
json_object["idx"] = self._idx_converter.numpy_to_json(value["idx"])
|
|
256
|
+
json_object["measurementUid"] = self._measurement_uid_converter.numpy_to_json(value["measurement_uid"])
|
|
257
|
+
if (field_val := value["scan_counter"]) is not None:
|
|
258
|
+
json_object["scanCounter"] = self._scan_counter_converter.numpy_to_json(field_val)
|
|
259
|
+
if (field_val := value["acquisition_time_stamp"]) is not None:
|
|
260
|
+
json_object["acquisitionTimeStamp"] = self._acquisition_time_stamp_converter.numpy_to_json(field_val)
|
|
261
|
+
json_object["physiologyTimeStamp"] = self._physiology_time_stamp_converter.numpy_to_json(value["physiology_time_stamp"])
|
|
262
|
+
json_object["channelOrder"] = self._channel_order_converter.numpy_to_json(value["channel_order"])
|
|
263
|
+
if (field_val := value["discard_pre"]) is not None:
|
|
264
|
+
json_object["discardPre"] = self._discard_pre_converter.numpy_to_json(field_val)
|
|
265
|
+
if (field_val := value["discard_post"]) is not None:
|
|
266
|
+
json_object["discardPost"] = self._discard_post_converter.numpy_to_json(field_val)
|
|
267
|
+
if (field_val := value["center_sample"]) is not None:
|
|
268
|
+
json_object["centerSample"] = self._center_sample_converter.numpy_to_json(field_val)
|
|
269
|
+
if (field_val := value["encoding_space_ref"]) is not None:
|
|
270
|
+
json_object["encodingSpaceRef"] = self._encoding_space_ref_converter.numpy_to_json(field_val)
|
|
271
|
+
if (field_val := value["sample_time_us"]) is not None:
|
|
272
|
+
json_object["sampleTimeUs"] = self._sample_time_us_converter.numpy_to_json(field_val)
|
|
273
|
+
json_object["position"] = self._position_converter.numpy_to_json(value["position"])
|
|
274
|
+
json_object["readDir"] = self._read_dir_converter.numpy_to_json(value["read_dir"])
|
|
275
|
+
json_object["phaseDir"] = self._phase_dir_converter.numpy_to_json(value["phase_dir"])
|
|
276
|
+
json_object["sliceDir"] = self._slice_dir_converter.numpy_to_json(value["slice_dir"])
|
|
277
|
+
json_object["patientTablePosition"] = self._patient_table_position_converter.numpy_to_json(value["patient_table_position"])
|
|
278
|
+
json_object["userInt"] = self._user_int_converter.numpy_to_json(value["user_int"])
|
|
279
|
+
json_object["userFloat"] = self._user_float_converter.numpy_to_json(value["user_float"])
|
|
280
|
+
json_object["data"] = self._data_converter.numpy_to_json(value["data"])
|
|
281
|
+
json_object["trajectory"] = self._trajectory_converter.numpy_to_json(value["trajectory"])
|
|
282
|
+
return json_object
|
|
283
|
+
|
|
284
|
+
def from_json(self, json_object: object) -> Acquisition:
|
|
285
|
+
if not isinstance(json_object, dict):
|
|
286
|
+
raise TypeError("Expected 'dict' instance")
|
|
287
|
+
return Acquisition(
|
|
288
|
+
flags=self._flags_converter.from_json(json_object["flags"],),
|
|
289
|
+
idx=self._idx_converter.from_json(json_object["idx"],),
|
|
290
|
+
measurement_uid=self._measurement_uid_converter.from_json(json_object["measurementUid"],),
|
|
291
|
+
scan_counter=self._scan_counter_converter.from_json(json_object.get("scanCounter")),
|
|
292
|
+
acquisition_time_stamp=self._acquisition_time_stamp_converter.from_json(json_object.get("acquisitionTimeStamp")),
|
|
293
|
+
physiology_time_stamp=self._physiology_time_stamp_converter.from_json(json_object["physiologyTimeStamp"],),
|
|
294
|
+
channel_order=self._channel_order_converter.from_json(json_object["channelOrder"],),
|
|
295
|
+
discard_pre=self._discard_pre_converter.from_json(json_object.get("discardPre")),
|
|
296
|
+
discard_post=self._discard_post_converter.from_json(json_object.get("discardPost")),
|
|
297
|
+
center_sample=self._center_sample_converter.from_json(json_object.get("centerSample")),
|
|
298
|
+
encoding_space_ref=self._encoding_space_ref_converter.from_json(json_object.get("encodingSpaceRef")),
|
|
299
|
+
sample_time_us=self._sample_time_us_converter.from_json(json_object.get("sampleTimeUs")),
|
|
300
|
+
position=self._position_converter.from_json(json_object["position"],),
|
|
301
|
+
read_dir=self._read_dir_converter.from_json(json_object["readDir"],),
|
|
302
|
+
phase_dir=self._phase_dir_converter.from_json(json_object["phaseDir"],),
|
|
303
|
+
slice_dir=self._slice_dir_converter.from_json(json_object["sliceDir"],),
|
|
304
|
+
patient_table_position=self._patient_table_position_converter.from_json(json_object["patientTablePosition"],),
|
|
305
|
+
user_int=self._user_int_converter.from_json(json_object["userInt"],),
|
|
306
|
+
user_float=self._user_float_converter.from_json(json_object["userFloat"],),
|
|
307
|
+
data=self._data_converter.from_json(json_object["data"],),
|
|
308
|
+
trajectory=self._trajectory_converter.from_json(json_object["trajectory"],),
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
312
|
+
if not isinstance(json_object, dict):
|
|
313
|
+
raise TypeError("Expected 'dict' instance")
|
|
314
|
+
return (
|
|
315
|
+
self._flags_converter.from_json_to_numpy(json_object["flags"]),
|
|
316
|
+
self._idx_converter.from_json_to_numpy(json_object["idx"]),
|
|
317
|
+
self._measurement_uid_converter.from_json_to_numpy(json_object["measurementUid"]),
|
|
318
|
+
self._scan_counter_converter.from_json_to_numpy(json_object.get("scanCounter")),
|
|
319
|
+
self._acquisition_time_stamp_converter.from_json_to_numpy(json_object.get("acquisitionTimeStamp")),
|
|
320
|
+
self._physiology_time_stamp_converter.from_json_to_numpy(json_object["physiologyTimeStamp"]),
|
|
321
|
+
self._channel_order_converter.from_json_to_numpy(json_object["channelOrder"]),
|
|
322
|
+
self._discard_pre_converter.from_json_to_numpy(json_object.get("discardPre")),
|
|
323
|
+
self._discard_post_converter.from_json_to_numpy(json_object.get("discardPost")),
|
|
324
|
+
self._center_sample_converter.from_json_to_numpy(json_object.get("centerSample")),
|
|
325
|
+
self._encoding_space_ref_converter.from_json_to_numpy(json_object.get("encodingSpaceRef")),
|
|
326
|
+
self._sample_time_us_converter.from_json_to_numpy(json_object.get("sampleTimeUs")),
|
|
327
|
+
self._position_converter.from_json_to_numpy(json_object["position"]),
|
|
328
|
+
self._read_dir_converter.from_json_to_numpy(json_object["readDir"]),
|
|
329
|
+
self._phase_dir_converter.from_json_to_numpy(json_object["phaseDir"]),
|
|
330
|
+
self._slice_dir_converter.from_json_to_numpy(json_object["sliceDir"]),
|
|
331
|
+
self._patient_table_position_converter.from_json_to_numpy(json_object["patientTablePosition"]),
|
|
332
|
+
self._user_int_converter.from_json_to_numpy(json_object["userInt"]),
|
|
333
|
+
self._user_float_converter.from_json_to_numpy(json_object["userFloat"]),
|
|
334
|
+
self._data_converter.from_json_to_numpy(json_object["data"]),
|
|
335
|
+
self._trajectory_converter.from_json_to_numpy(json_object["trajectory"]),
|
|
336
|
+
) # type:ignore
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
patient_gender_name_to_value_map = {
|
|
340
|
+
"m": PatientGender.M,
|
|
341
|
+
"f": PatientGender.F,
|
|
342
|
+
"o": PatientGender.O,
|
|
343
|
+
}
|
|
344
|
+
patient_gender_value_to_name_map = {v: n for n, v in patient_gender_name_to_value_map.items()}
|
|
345
|
+
|
|
346
|
+
class SubjectInformationTypeConverter(_ndjson.JsonConverter[SubjectInformationType, np.void]):
|
|
347
|
+
def __init__(self) -> None:
|
|
348
|
+
self._patient_name_converter = _ndjson.OptionalConverter(_ndjson.string_converter)
|
|
349
|
+
self._patient_weight_kg_converter = _ndjson.OptionalConverter(_ndjson.float32_converter)
|
|
350
|
+
self._patient_height_m_converter = _ndjson.OptionalConverter(_ndjson.float32_converter)
|
|
351
|
+
self._patient_id_converter = _ndjson.OptionalConverter(_ndjson.string_converter)
|
|
352
|
+
self._patient_birthdate_converter = _ndjson.OptionalConverter(_ndjson.date_converter)
|
|
353
|
+
self._patient_gender_converter = _ndjson.OptionalConverter(_ndjson.EnumConverter(PatientGender, np.int32, patient_gender_name_to_value_map, patient_gender_value_to_name_map))
|
|
354
|
+
super().__init__(np.dtype([
|
|
355
|
+
("patient_name", self._patient_name_converter.overall_dtype()),
|
|
356
|
+
("patient_weight_kg", self._patient_weight_kg_converter.overall_dtype()),
|
|
357
|
+
("patient_height_m", self._patient_height_m_converter.overall_dtype()),
|
|
358
|
+
("patient_id", self._patient_id_converter.overall_dtype()),
|
|
359
|
+
("patient_birthdate", self._patient_birthdate_converter.overall_dtype()),
|
|
360
|
+
("patient_gender", self._patient_gender_converter.overall_dtype()),
|
|
361
|
+
]))
|
|
362
|
+
|
|
363
|
+
def to_json(self, value: SubjectInformationType) -> object:
|
|
364
|
+
if not isinstance(value, SubjectInformationType): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
365
|
+
raise TypeError("Expected 'SubjectInformationType' instance")
|
|
366
|
+
json_object = {}
|
|
367
|
+
|
|
368
|
+
if value.patient_name is not None:
|
|
369
|
+
json_object["patientName"] = self._patient_name_converter.to_json(value.patient_name)
|
|
370
|
+
if value.patient_weight_kg is not None:
|
|
371
|
+
json_object["patientWeightKg"] = self._patient_weight_kg_converter.to_json(value.patient_weight_kg)
|
|
372
|
+
if value.patient_height_m is not None:
|
|
373
|
+
json_object["patientHeightM"] = self._patient_height_m_converter.to_json(value.patient_height_m)
|
|
374
|
+
if value.patient_id is not None:
|
|
375
|
+
json_object["patientID"] = self._patient_id_converter.to_json(value.patient_id)
|
|
376
|
+
if value.patient_birthdate is not None:
|
|
377
|
+
json_object["patientBirthdate"] = self._patient_birthdate_converter.to_json(value.patient_birthdate)
|
|
378
|
+
if value.patient_gender is not None:
|
|
379
|
+
json_object["patientGender"] = self._patient_gender_converter.to_json(value.patient_gender)
|
|
380
|
+
return json_object
|
|
381
|
+
|
|
382
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
383
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
384
|
+
raise TypeError("Expected 'np.void' instance")
|
|
385
|
+
json_object = {}
|
|
386
|
+
|
|
387
|
+
if (field_val := value["patient_name"]) is not None:
|
|
388
|
+
json_object["patientName"] = self._patient_name_converter.numpy_to_json(field_val)
|
|
389
|
+
if (field_val := value["patient_weight_kg"]) is not None:
|
|
390
|
+
json_object["patientWeightKg"] = self._patient_weight_kg_converter.numpy_to_json(field_val)
|
|
391
|
+
if (field_val := value["patient_height_m"]) is not None:
|
|
392
|
+
json_object["patientHeightM"] = self._patient_height_m_converter.numpy_to_json(field_val)
|
|
393
|
+
if (field_val := value["patient_id"]) is not None:
|
|
394
|
+
json_object["patientID"] = self._patient_id_converter.numpy_to_json(field_val)
|
|
395
|
+
if (field_val := value["patient_birthdate"]) is not None:
|
|
396
|
+
json_object["patientBirthdate"] = self._patient_birthdate_converter.numpy_to_json(field_val)
|
|
397
|
+
if (field_val := value["patient_gender"]) is not None:
|
|
398
|
+
json_object["patientGender"] = self._patient_gender_converter.numpy_to_json(field_val)
|
|
399
|
+
return json_object
|
|
400
|
+
|
|
401
|
+
def from_json(self, json_object: object) -> SubjectInformationType:
|
|
402
|
+
if not isinstance(json_object, dict):
|
|
403
|
+
raise TypeError("Expected 'dict' instance")
|
|
404
|
+
return SubjectInformationType(
|
|
405
|
+
patient_name=self._patient_name_converter.from_json(json_object.get("patientName")),
|
|
406
|
+
patient_weight_kg=self._patient_weight_kg_converter.from_json(json_object.get("patientWeightKg")),
|
|
407
|
+
patient_height_m=self._patient_height_m_converter.from_json(json_object.get("patientHeightM")),
|
|
408
|
+
patient_id=self._patient_id_converter.from_json(json_object.get("patientID")),
|
|
409
|
+
patient_birthdate=self._patient_birthdate_converter.from_json(json_object.get("patientBirthdate")),
|
|
410
|
+
patient_gender=self._patient_gender_converter.from_json(json_object.get("patientGender")),
|
|
411
|
+
)
|
|
412
|
+
|
|
413
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
414
|
+
if not isinstance(json_object, dict):
|
|
415
|
+
raise TypeError("Expected 'dict' instance")
|
|
416
|
+
return (
|
|
417
|
+
self._patient_name_converter.from_json_to_numpy(json_object.get("patientName")),
|
|
418
|
+
self._patient_weight_kg_converter.from_json_to_numpy(json_object.get("patientWeightKg")),
|
|
419
|
+
self._patient_height_m_converter.from_json_to_numpy(json_object.get("patientHeightM")),
|
|
420
|
+
self._patient_id_converter.from_json_to_numpy(json_object.get("patientID")),
|
|
421
|
+
self._patient_birthdate_converter.from_json_to_numpy(json_object.get("patientBirthdate")),
|
|
422
|
+
self._patient_gender_converter.from_json_to_numpy(json_object.get("patientGender")),
|
|
423
|
+
) # type:ignore
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
class StudyInformationTypeConverter(_ndjson.JsonConverter[StudyInformationType, np.void]):
|
|
427
|
+
def __init__(self) -> None:
|
|
428
|
+
self._study_date_converter = _ndjson.OptionalConverter(_ndjson.date_converter)
|
|
429
|
+
self._study_time_converter = _ndjson.OptionalConverter(_ndjson.time_converter)
|
|
430
|
+
self._study_id_converter = _ndjson.OptionalConverter(_ndjson.string_converter)
|
|
431
|
+
self._accession_number_converter = _ndjson.OptionalConverter(_ndjson.int64_converter)
|
|
432
|
+
self._referring_physician_name_converter = _ndjson.OptionalConverter(_ndjson.string_converter)
|
|
433
|
+
self._study_description_converter = _ndjson.OptionalConverter(_ndjson.string_converter)
|
|
434
|
+
self._study_instance_uid_converter = _ndjson.OptionalConverter(_ndjson.string_converter)
|
|
435
|
+
self._body_part_examined_converter = _ndjson.OptionalConverter(_ndjson.string_converter)
|
|
436
|
+
super().__init__(np.dtype([
|
|
437
|
+
("study_date", self._study_date_converter.overall_dtype()),
|
|
438
|
+
("study_time", self._study_time_converter.overall_dtype()),
|
|
439
|
+
("study_id", self._study_id_converter.overall_dtype()),
|
|
440
|
+
("accession_number", self._accession_number_converter.overall_dtype()),
|
|
441
|
+
("referring_physician_name", self._referring_physician_name_converter.overall_dtype()),
|
|
442
|
+
("study_description", self._study_description_converter.overall_dtype()),
|
|
443
|
+
("study_instance_uid", self._study_instance_uid_converter.overall_dtype()),
|
|
444
|
+
("body_part_examined", self._body_part_examined_converter.overall_dtype()),
|
|
445
|
+
]))
|
|
446
|
+
|
|
447
|
+
def to_json(self, value: StudyInformationType) -> object:
|
|
448
|
+
if not isinstance(value, StudyInformationType): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
449
|
+
raise TypeError("Expected 'StudyInformationType' instance")
|
|
450
|
+
json_object = {}
|
|
451
|
+
|
|
452
|
+
if value.study_date is not None:
|
|
453
|
+
json_object["studyDate"] = self._study_date_converter.to_json(value.study_date)
|
|
454
|
+
if value.study_time is not None:
|
|
455
|
+
json_object["studyTime"] = self._study_time_converter.to_json(value.study_time)
|
|
456
|
+
if value.study_id is not None:
|
|
457
|
+
json_object["studyID"] = self._study_id_converter.to_json(value.study_id)
|
|
458
|
+
if value.accession_number is not None:
|
|
459
|
+
json_object["accessionNumber"] = self._accession_number_converter.to_json(value.accession_number)
|
|
460
|
+
if value.referring_physician_name is not None:
|
|
461
|
+
json_object["referringPhysicianName"] = self._referring_physician_name_converter.to_json(value.referring_physician_name)
|
|
462
|
+
if value.study_description is not None:
|
|
463
|
+
json_object["studyDescription"] = self._study_description_converter.to_json(value.study_description)
|
|
464
|
+
if value.study_instance_uid is not None:
|
|
465
|
+
json_object["studyInstanceUID"] = self._study_instance_uid_converter.to_json(value.study_instance_uid)
|
|
466
|
+
if value.body_part_examined is not None:
|
|
467
|
+
json_object["bodyPartExamined"] = self._body_part_examined_converter.to_json(value.body_part_examined)
|
|
468
|
+
return json_object
|
|
469
|
+
|
|
470
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
471
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
472
|
+
raise TypeError("Expected 'np.void' instance")
|
|
473
|
+
json_object = {}
|
|
474
|
+
|
|
475
|
+
if (field_val := value["study_date"]) is not None:
|
|
476
|
+
json_object["studyDate"] = self._study_date_converter.numpy_to_json(field_val)
|
|
477
|
+
if (field_val := value["study_time"]) is not None:
|
|
478
|
+
json_object["studyTime"] = self._study_time_converter.numpy_to_json(field_val)
|
|
479
|
+
if (field_val := value["study_id"]) is not None:
|
|
480
|
+
json_object["studyID"] = self._study_id_converter.numpy_to_json(field_val)
|
|
481
|
+
if (field_val := value["accession_number"]) is not None:
|
|
482
|
+
json_object["accessionNumber"] = self._accession_number_converter.numpy_to_json(field_val)
|
|
483
|
+
if (field_val := value["referring_physician_name"]) is not None:
|
|
484
|
+
json_object["referringPhysicianName"] = self._referring_physician_name_converter.numpy_to_json(field_val)
|
|
485
|
+
if (field_val := value["study_description"]) is not None:
|
|
486
|
+
json_object["studyDescription"] = self._study_description_converter.numpy_to_json(field_val)
|
|
487
|
+
if (field_val := value["study_instance_uid"]) is not None:
|
|
488
|
+
json_object["studyInstanceUID"] = self._study_instance_uid_converter.numpy_to_json(field_val)
|
|
489
|
+
if (field_val := value["body_part_examined"]) is not None:
|
|
490
|
+
json_object["bodyPartExamined"] = self._body_part_examined_converter.numpy_to_json(field_val)
|
|
491
|
+
return json_object
|
|
492
|
+
|
|
493
|
+
def from_json(self, json_object: object) -> StudyInformationType:
|
|
494
|
+
if not isinstance(json_object, dict):
|
|
495
|
+
raise TypeError("Expected 'dict' instance")
|
|
496
|
+
return StudyInformationType(
|
|
497
|
+
study_date=self._study_date_converter.from_json(json_object.get("studyDate")),
|
|
498
|
+
study_time=self._study_time_converter.from_json(json_object.get("studyTime")),
|
|
499
|
+
study_id=self._study_id_converter.from_json(json_object.get("studyID")),
|
|
500
|
+
accession_number=self._accession_number_converter.from_json(json_object.get("accessionNumber")),
|
|
501
|
+
referring_physician_name=self._referring_physician_name_converter.from_json(json_object.get("referringPhysicianName")),
|
|
502
|
+
study_description=self._study_description_converter.from_json(json_object.get("studyDescription")),
|
|
503
|
+
study_instance_uid=self._study_instance_uid_converter.from_json(json_object.get("studyInstanceUID")),
|
|
504
|
+
body_part_examined=self._body_part_examined_converter.from_json(json_object.get("bodyPartExamined")),
|
|
505
|
+
)
|
|
506
|
+
|
|
507
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
508
|
+
if not isinstance(json_object, dict):
|
|
509
|
+
raise TypeError("Expected 'dict' instance")
|
|
510
|
+
return (
|
|
511
|
+
self._study_date_converter.from_json_to_numpy(json_object.get("studyDate")),
|
|
512
|
+
self._study_time_converter.from_json_to_numpy(json_object.get("studyTime")),
|
|
513
|
+
self._study_id_converter.from_json_to_numpy(json_object.get("studyID")),
|
|
514
|
+
self._accession_number_converter.from_json_to_numpy(json_object.get("accessionNumber")),
|
|
515
|
+
self._referring_physician_name_converter.from_json_to_numpy(json_object.get("referringPhysicianName")),
|
|
516
|
+
self._study_description_converter.from_json_to_numpy(json_object.get("studyDescription")),
|
|
517
|
+
self._study_instance_uid_converter.from_json_to_numpy(json_object.get("studyInstanceUID")),
|
|
518
|
+
self._body_part_examined_converter.from_json_to_numpy(json_object.get("bodyPartExamined")),
|
|
519
|
+
) # type:ignore
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
patient_position_name_to_value_map = {
|
|
523
|
+
"hFP": PatientPosition.H_FP,
|
|
524
|
+
"hFS": PatientPosition.H_FS,
|
|
525
|
+
"hFDR": PatientPosition.H_FDR,
|
|
526
|
+
"hFDL": PatientPosition.H_FDL,
|
|
527
|
+
"fFP": PatientPosition.F_FP,
|
|
528
|
+
"fFS": PatientPosition.F_FS,
|
|
529
|
+
"fFDR": PatientPosition.F_FDR,
|
|
530
|
+
"fFDL": PatientPosition.F_FDL,
|
|
531
|
+
}
|
|
532
|
+
patient_position_value_to_name_map = {v: n for n, v in patient_position_name_to_value_map.items()}
|
|
533
|
+
|
|
534
|
+
class ThreeDimensionalFloatConverter(_ndjson.JsonConverter[ThreeDimensionalFloat, np.void]):
|
|
535
|
+
def __init__(self) -> None:
|
|
536
|
+
self._x_converter = _ndjson.float32_converter
|
|
537
|
+
self._y_converter = _ndjson.float32_converter
|
|
538
|
+
self._z_converter = _ndjson.float32_converter
|
|
539
|
+
super().__init__(np.dtype([
|
|
540
|
+
("x", self._x_converter.overall_dtype()),
|
|
541
|
+
("y", self._y_converter.overall_dtype()),
|
|
542
|
+
("z", self._z_converter.overall_dtype()),
|
|
543
|
+
]))
|
|
544
|
+
|
|
545
|
+
def to_json(self, value: ThreeDimensionalFloat) -> object:
|
|
546
|
+
if not isinstance(value, ThreeDimensionalFloat): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
547
|
+
raise TypeError("Expected 'ThreeDimensionalFloat' instance")
|
|
548
|
+
json_object = {}
|
|
549
|
+
|
|
550
|
+
json_object["x"] = self._x_converter.to_json(value.x)
|
|
551
|
+
json_object["y"] = self._y_converter.to_json(value.y)
|
|
552
|
+
json_object["z"] = self._z_converter.to_json(value.z)
|
|
553
|
+
return json_object
|
|
554
|
+
|
|
555
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
556
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
557
|
+
raise TypeError("Expected 'np.void' instance")
|
|
558
|
+
json_object = {}
|
|
559
|
+
|
|
560
|
+
json_object["x"] = self._x_converter.numpy_to_json(value["x"])
|
|
561
|
+
json_object["y"] = self._y_converter.numpy_to_json(value["y"])
|
|
562
|
+
json_object["z"] = self._z_converter.numpy_to_json(value["z"])
|
|
563
|
+
return json_object
|
|
564
|
+
|
|
565
|
+
def from_json(self, json_object: object) -> ThreeDimensionalFloat:
|
|
566
|
+
if not isinstance(json_object, dict):
|
|
567
|
+
raise TypeError("Expected 'dict' instance")
|
|
568
|
+
return ThreeDimensionalFloat(
|
|
569
|
+
x=self._x_converter.from_json(json_object["x"],),
|
|
570
|
+
y=self._y_converter.from_json(json_object["y"],),
|
|
571
|
+
z=self._z_converter.from_json(json_object["z"],),
|
|
572
|
+
)
|
|
573
|
+
|
|
574
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
575
|
+
if not isinstance(json_object, dict):
|
|
576
|
+
raise TypeError("Expected 'dict' instance")
|
|
577
|
+
return (
|
|
578
|
+
self._x_converter.from_json_to_numpy(json_object["x"]),
|
|
579
|
+
self._y_converter.from_json_to_numpy(json_object["y"]),
|
|
580
|
+
self._z_converter.from_json_to_numpy(json_object["z"]),
|
|
581
|
+
) # type:ignore
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
class MeasurementDependencyTypeConverter(_ndjson.JsonConverter[MeasurementDependencyType, np.void]):
|
|
585
|
+
def __init__(self) -> None:
|
|
586
|
+
self._dependency_type_converter = _ndjson.string_converter
|
|
587
|
+
self._measurement_id_converter = _ndjson.string_converter
|
|
588
|
+
super().__init__(np.dtype([
|
|
589
|
+
("dependency_type", self._dependency_type_converter.overall_dtype()),
|
|
590
|
+
("measurement_id", self._measurement_id_converter.overall_dtype()),
|
|
591
|
+
]))
|
|
592
|
+
|
|
593
|
+
def to_json(self, value: MeasurementDependencyType) -> object:
|
|
594
|
+
if not isinstance(value, MeasurementDependencyType): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
595
|
+
raise TypeError("Expected 'MeasurementDependencyType' instance")
|
|
596
|
+
json_object = {}
|
|
597
|
+
|
|
598
|
+
json_object["dependencyType"] = self._dependency_type_converter.to_json(value.dependency_type)
|
|
599
|
+
json_object["measurementID"] = self._measurement_id_converter.to_json(value.measurement_id)
|
|
600
|
+
return json_object
|
|
601
|
+
|
|
602
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
603
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
604
|
+
raise TypeError("Expected 'np.void' instance")
|
|
605
|
+
json_object = {}
|
|
606
|
+
|
|
607
|
+
json_object["dependencyType"] = self._dependency_type_converter.numpy_to_json(value["dependency_type"])
|
|
608
|
+
json_object["measurementID"] = self._measurement_id_converter.numpy_to_json(value["measurement_id"])
|
|
609
|
+
return json_object
|
|
610
|
+
|
|
611
|
+
def from_json(self, json_object: object) -> MeasurementDependencyType:
|
|
612
|
+
if not isinstance(json_object, dict):
|
|
613
|
+
raise TypeError("Expected 'dict' instance")
|
|
614
|
+
return MeasurementDependencyType(
|
|
615
|
+
dependency_type=self._dependency_type_converter.from_json(json_object["dependencyType"],),
|
|
616
|
+
measurement_id=self._measurement_id_converter.from_json(json_object["measurementID"],),
|
|
617
|
+
)
|
|
618
|
+
|
|
619
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
620
|
+
if not isinstance(json_object, dict):
|
|
621
|
+
raise TypeError("Expected 'dict' instance")
|
|
622
|
+
return (
|
|
623
|
+
self._dependency_type_converter.from_json_to_numpy(json_object["dependencyType"]),
|
|
624
|
+
self._measurement_id_converter.from_json_to_numpy(json_object["measurementID"]),
|
|
625
|
+
) # type:ignore
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
class ReferencedImageSequenceTypeConverter(_ndjson.JsonConverter[ReferencedImageSequenceType, np.void]):
|
|
629
|
+
def __init__(self) -> None:
|
|
630
|
+
self._referenced_sop_instance_uid_converter = _ndjson.VectorConverter(_ndjson.string_converter)
|
|
631
|
+
super().__init__(np.dtype([
|
|
632
|
+
("referenced_sop_instance_uid", self._referenced_sop_instance_uid_converter.overall_dtype()),
|
|
633
|
+
]))
|
|
634
|
+
|
|
635
|
+
def to_json(self, value: ReferencedImageSequenceType) -> object:
|
|
636
|
+
if not isinstance(value, ReferencedImageSequenceType): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
637
|
+
raise TypeError("Expected 'ReferencedImageSequenceType' instance")
|
|
638
|
+
json_object = {}
|
|
639
|
+
|
|
640
|
+
json_object["referencedSOPInstanceUID"] = self._referenced_sop_instance_uid_converter.to_json(value.referenced_sop_instance_uid)
|
|
641
|
+
return json_object
|
|
642
|
+
|
|
643
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
644
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
645
|
+
raise TypeError("Expected 'np.void' instance")
|
|
646
|
+
json_object = {}
|
|
647
|
+
|
|
648
|
+
json_object["referencedSOPInstanceUID"] = self._referenced_sop_instance_uid_converter.numpy_to_json(value["referenced_sop_instance_uid"])
|
|
649
|
+
return json_object
|
|
650
|
+
|
|
651
|
+
def from_json(self, json_object: object) -> ReferencedImageSequenceType:
|
|
652
|
+
if not isinstance(json_object, dict):
|
|
653
|
+
raise TypeError("Expected 'dict' instance")
|
|
654
|
+
return ReferencedImageSequenceType(
|
|
655
|
+
referenced_sop_instance_uid=self._referenced_sop_instance_uid_converter.from_json(json_object["referencedSOPInstanceUID"],),
|
|
656
|
+
)
|
|
657
|
+
|
|
658
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
659
|
+
if not isinstance(json_object, dict):
|
|
660
|
+
raise TypeError("Expected 'dict' instance")
|
|
661
|
+
return (
|
|
662
|
+
self._referenced_sop_instance_uid_converter.from_json_to_numpy(json_object["referencedSOPInstanceUID"]),
|
|
663
|
+
) # type:ignore
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
class MeasurementInformationTypeConverter(_ndjson.JsonConverter[MeasurementInformationType, np.void]):
|
|
667
|
+
def __init__(self) -> None:
|
|
668
|
+
self._measurement_id_converter = _ndjson.OptionalConverter(_ndjson.string_converter)
|
|
669
|
+
self._series_date_converter = _ndjson.OptionalConverter(_ndjson.date_converter)
|
|
670
|
+
self._series_time_converter = _ndjson.OptionalConverter(_ndjson.time_converter)
|
|
671
|
+
self._patient_position_converter = _ndjson.EnumConverter(PatientPosition, np.int32, patient_position_name_to_value_map, patient_position_value_to_name_map)
|
|
672
|
+
self._relative_table_position_converter = _ndjson.OptionalConverter(ThreeDimensionalFloatConverter())
|
|
673
|
+
self._initial_series_number_converter = _ndjson.OptionalConverter(_ndjson.int64_converter)
|
|
674
|
+
self._protocol_name_converter = _ndjson.OptionalConverter(_ndjson.string_converter)
|
|
675
|
+
self._sequence_name_converter = _ndjson.OptionalConverter(_ndjson.string_converter)
|
|
676
|
+
self._series_description_converter = _ndjson.OptionalConverter(_ndjson.string_converter)
|
|
677
|
+
self._measurement_dependency_converter = _ndjson.VectorConverter(MeasurementDependencyTypeConverter())
|
|
678
|
+
self._series_instance_uid_root_converter = _ndjson.OptionalConverter(_ndjson.string_converter)
|
|
679
|
+
self._frame_of_reference_uid_converter = _ndjson.OptionalConverter(_ndjson.string_converter)
|
|
680
|
+
self._referenced_image_sequence_converter = _ndjson.OptionalConverter(ReferencedImageSequenceTypeConverter())
|
|
681
|
+
super().__init__(np.dtype([
|
|
682
|
+
("measurement_id", self._measurement_id_converter.overall_dtype()),
|
|
683
|
+
("series_date", self._series_date_converter.overall_dtype()),
|
|
684
|
+
("series_time", self._series_time_converter.overall_dtype()),
|
|
685
|
+
("patient_position", self._patient_position_converter.overall_dtype()),
|
|
686
|
+
("relative_table_position", self._relative_table_position_converter.overall_dtype()),
|
|
687
|
+
("initial_series_number", self._initial_series_number_converter.overall_dtype()),
|
|
688
|
+
("protocol_name", self._protocol_name_converter.overall_dtype()),
|
|
689
|
+
("sequence_name", self._sequence_name_converter.overall_dtype()),
|
|
690
|
+
("series_description", self._series_description_converter.overall_dtype()),
|
|
691
|
+
("measurement_dependency", self._measurement_dependency_converter.overall_dtype()),
|
|
692
|
+
("series_instance_uid_root", self._series_instance_uid_root_converter.overall_dtype()),
|
|
693
|
+
("frame_of_reference_uid", self._frame_of_reference_uid_converter.overall_dtype()),
|
|
694
|
+
("referenced_image_sequence", self._referenced_image_sequence_converter.overall_dtype()),
|
|
695
|
+
]))
|
|
696
|
+
|
|
697
|
+
def to_json(self, value: MeasurementInformationType) -> object:
|
|
698
|
+
if not isinstance(value, MeasurementInformationType): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
699
|
+
raise TypeError("Expected 'MeasurementInformationType' instance")
|
|
700
|
+
json_object = {}
|
|
701
|
+
|
|
702
|
+
if value.measurement_id is not None:
|
|
703
|
+
json_object["measurementID"] = self._measurement_id_converter.to_json(value.measurement_id)
|
|
704
|
+
if value.series_date is not None:
|
|
705
|
+
json_object["seriesDate"] = self._series_date_converter.to_json(value.series_date)
|
|
706
|
+
if value.series_time is not None:
|
|
707
|
+
json_object["seriesTime"] = self._series_time_converter.to_json(value.series_time)
|
|
708
|
+
json_object["patientPosition"] = self._patient_position_converter.to_json(value.patient_position)
|
|
709
|
+
if value.relative_table_position is not None:
|
|
710
|
+
json_object["relativeTablePosition"] = self._relative_table_position_converter.to_json(value.relative_table_position)
|
|
711
|
+
if value.initial_series_number is not None:
|
|
712
|
+
json_object["initialSeriesNumber"] = self._initial_series_number_converter.to_json(value.initial_series_number)
|
|
713
|
+
if value.protocol_name is not None:
|
|
714
|
+
json_object["protocolName"] = self._protocol_name_converter.to_json(value.protocol_name)
|
|
715
|
+
if value.sequence_name is not None:
|
|
716
|
+
json_object["sequenceName"] = self._sequence_name_converter.to_json(value.sequence_name)
|
|
717
|
+
if value.series_description is not None:
|
|
718
|
+
json_object["seriesDescription"] = self._series_description_converter.to_json(value.series_description)
|
|
719
|
+
json_object["measurementDependency"] = self._measurement_dependency_converter.to_json(value.measurement_dependency)
|
|
720
|
+
if value.series_instance_uid_root is not None:
|
|
721
|
+
json_object["seriesInstanceUIDRoot"] = self._series_instance_uid_root_converter.to_json(value.series_instance_uid_root)
|
|
722
|
+
if value.frame_of_reference_uid is not None:
|
|
723
|
+
json_object["frameOfReferenceUID"] = self._frame_of_reference_uid_converter.to_json(value.frame_of_reference_uid)
|
|
724
|
+
if value.referenced_image_sequence is not None:
|
|
725
|
+
json_object["referencedImageSequence"] = self._referenced_image_sequence_converter.to_json(value.referenced_image_sequence)
|
|
726
|
+
return json_object
|
|
727
|
+
|
|
728
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
729
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
730
|
+
raise TypeError("Expected 'np.void' instance")
|
|
731
|
+
json_object = {}
|
|
732
|
+
|
|
733
|
+
if (field_val := value["measurement_id"]) is not None:
|
|
734
|
+
json_object["measurementID"] = self._measurement_id_converter.numpy_to_json(field_val)
|
|
735
|
+
if (field_val := value["series_date"]) is not None:
|
|
736
|
+
json_object["seriesDate"] = self._series_date_converter.numpy_to_json(field_val)
|
|
737
|
+
if (field_val := value["series_time"]) is not None:
|
|
738
|
+
json_object["seriesTime"] = self._series_time_converter.numpy_to_json(field_val)
|
|
739
|
+
json_object["patientPosition"] = self._patient_position_converter.numpy_to_json(value["patient_position"])
|
|
740
|
+
if (field_val := value["relative_table_position"]) is not None:
|
|
741
|
+
json_object["relativeTablePosition"] = self._relative_table_position_converter.numpy_to_json(field_val)
|
|
742
|
+
if (field_val := value["initial_series_number"]) is not None:
|
|
743
|
+
json_object["initialSeriesNumber"] = self._initial_series_number_converter.numpy_to_json(field_val)
|
|
744
|
+
if (field_val := value["protocol_name"]) is not None:
|
|
745
|
+
json_object["protocolName"] = self._protocol_name_converter.numpy_to_json(field_val)
|
|
746
|
+
if (field_val := value["sequence_name"]) is not None:
|
|
747
|
+
json_object["sequenceName"] = self._sequence_name_converter.numpy_to_json(field_val)
|
|
748
|
+
if (field_val := value["series_description"]) is not None:
|
|
749
|
+
json_object["seriesDescription"] = self._series_description_converter.numpy_to_json(field_val)
|
|
750
|
+
json_object["measurementDependency"] = self._measurement_dependency_converter.numpy_to_json(value["measurement_dependency"])
|
|
751
|
+
if (field_val := value["series_instance_uid_root"]) is not None:
|
|
752
|
+
json_object["seriesInstanceUIDRoot"] = self._series_instance_uid_root_converter.numpy_to_json(field_val)
|
|
753
|
+
if (field_val := value["frame_of_reference_uid"]) is not None:
|
|
754
|
+
json_object["frameOfReferenceUID"] = self._frame_of_reference_uid_converter.numpy_to_json(field_val)
|
|
755
|
+
if (field_val := value["referenced_image_sequence"]) is not None:
|
|
756
|
+
json_object["referencedImageSequence"] = self._referenced_image_sequence_converter.numpy_to_json(field_val)
|
|
757
|
+
return json_object
|
|
758
|
+
|
|
759
|
+
def from_json(self, json_object: object) -> MeasurementInformationType:
|
|
760
|
+
if not isinstance(json_object, dict):
|
|
761
|
+
raise TypeError("Expected 'dict' instance")
|
|
762
|
+
return MeasurementInformationType(
|
|
763
|
+
measurement_id=self._measurement_id_converter.from_json(json_object.get("measurementID")),
|
|
764
|
+
series_date=self._series_date_converter.from_json(json_object.get("seriesDate")),
|
|
765
|
+
series_time=self._series_time_converter.from_json(json_object.get("seriesTime")),
|
|
766
|
+
patient_position=self._patient_position_converter.from_json(json_object["patientPosition"],),
|
|
767
|
+
relative_table_position=self._relative_table_position_converter.from_json(json_object.get("relativeTablePosition")),
|
|
768
|
+
initial_series_number=self._initial_series_number_converter.from_json(json_object.get("initialSeriesNumber")),
|
|
769
|
+
protocol_name=self._protocol_name_converter.from_json(json_object.get("protocolName")),
|
|
770
|
+
sequence_name=self._sequence_name_converter.from_json(json_object.get("sequenceName")),
|
|
771
|
+
series_description=self._series_description_converter.from_json(json_object.get("seriesDescription")),
|
|
772
|
+
measurement_dependency=self._measurement_dependency_converter.from_json(json_object["measurementDependency"],),
|
|
773
|
+
series_instance_uid_root=self._series_instance_uid_root_converter.from_json(json_object.get("seriesInstanceUIDRoot")),
|
|
774
|
+
frame_of_reference_uid=self._frame_of_reference_uid_converter.from_json(json_object.get("frameOfReferenceUID")),
|
|
775
|
+
referenced_image_sequence=self._referenced_image_sequence_converter.from_json(json_object.get("referencedImageSequence")),
|
|
776
|
+
)
|
|
777
|
+
|
|
778
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
779
|
+
if not isinstance(json_object, dict):
|
|
780
|
+
raise TypeError("Expected 'dict' instance")
|
|
781
|
+
return (
|
|
782
|
+
self._measurement_id_converter.from_json_to_numpy(json_object.get("measurementID")),
|
|
783
|
+
self._series_date_converter.from_json_to_numpy(json_object.get("seriesDate")),
|
|
784
|
+
self._series_time_converter.from_json_to_numpy(json_object.get("seriesTime")),
|
|
785
|
+
self._patient_position_converter.from_json_to_numpy(json_object["patientPosition"]),
|
|
786
|
+
self._relative_table_position_converter.from_json_to_numpy(json_object.get("relativeTablePosition")),
|
|
787
|
+
self._initial_series_number_converter.from_json_to_numpy(json_object.get("initialSeriesNumber")),
|
|
788
|
+
self._protocol_name_converter.from_json_to_numpy(json_object.get("protocolName")),
|
|
789
|
+
self._sequence_name_converter.from_json_to_numpy(json_object.get("sequenceName")),
|
|
790
|
+
self._series_description_converter.from_json_to_numpy(json_object.get("seriesDescription")),
|
|
791
|
+
self._measurement_dependency_converter.from_json_to_numpy(json_object["measurementDependency"]),
|
|
792
|
+
self._series_instance_uid_root_converter.from_json_to_numpy(json_object.get("seriesInstanceUIDRoot")),
|
|
793
|
+
self._frame_of_reference_uid_converter.from_json_to_numpy(json_object.get("frameOfReferenceUID")),
|
|
794
|
+
self._referenced_image_sequence_converter.from_json_to_numpy(json_object.get("referencedImageSequence")),
|
|
795
|
+
) # type:ignore
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+
class CoilLabelTypeConverter(_ndjson.JsonConverter[CoilLabelType, np.void]):
|
|
799
|
+
def __init__(self) -> None:
|
|
800
|
+
self._coil_number_converter = _ndjson.uint32_converter
|
|
801
|
+
self._coil_name_converter = _ndjson.string_converter
|
|
802
|
+
super().__init__(np.dtype([
|
|
803
|
+
("coil_number", self._coil_number_converter.overall_dtype()),
|
|
804
|
+
("coil_name", self._coil_name_converter.overall_dtype()),
|
|
805
|
+
]))
|
|
806
|
+
|
|
807
|
+
def to_json(self, value: CoilLabelType) -> object:
|
|
808
|
+
if not isinstance(value, CoilLabelType): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
809
|
+
raise TypeError("Expected 'CoilLabelType' instance")
|
|
810
|
+
json_object = {}
|
|
811
|
+
|
|
812
|
+
json_object["coilNumber"] = self._coil_number_converter.to_json(value.coil_number)
|
|
813
|
+
json_object["coilName"] = self._coil_name_converter.to_json(value.coil_name)
|
|
814
|
+
return json_object
|
|
815
|
+
|
|
816
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
817
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
818
|
+
raise TypeError("Expected 'np.void' instance")
|
|
819
|
+
json_object = {}
|
|
820
|
+
|
|
821
|
+
json_object["coilNumber"] = self._coil_number_converter.numpy_to_json(value["coil_number"])
|
|
822
|
+
json_object["coilName"] = self._coil_name_converter.numpy_to_json(value["coil_name"])
|
|
823
|
+
return json_object
|
|
824
|
+
|
|
825
|
+
def from_json(self, json_object: object) -> CoilLabelType:
|
|
826
|
+
if not isinstance(json_object, dict):
|
|
827
|
+
raise TypeError("Expected 'dict' instance")
|
|
828
|
+
return CoilLabelType(
|
|
829
|
+
coil_number=self._coil_number_converter.from_json(json_object["coilNumber"],),
|
|
830
|
+
coil_name=self._coil_name_converter.from_json(json_object["coilName"],),
|
|
831
|
+
)
|
|
832
|
+
|
|
833
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
834
|
+
if not isinstance(json_object, dict):
|
|
835
|
+
raise TypeError("Expected 'dict' instance")
|
|
836
|
+
return (
|
|
837
|
+
self._coil_number_converter.from_json_to_numpy(json_object["coilNumber"]),
|
|
838
|
+
self._coil_name_converter.from_json_to_numpy(json_object["coilName"]),
|
|
839
|
+
) # type:ignore
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
class AcquisitionSystemInformationTypeConverter(_ndjson.JsonConverter[AcquisitionSystemInformationType, np.void]):
|
|
843
|
+
def __init__(self) -> None:
|
|
844
|
+
self._system_vendor_converter = _ndjson.OptionalConverter(_ndjson.string_converter)
|
|
845
|
+
self._system_model_converter = _ndjson.OptionalConverter(_ndjson.string_converter)
|
|
846
|
+
self._system_field_strength_t_converter = _ndjson.OptionalConverter(_ndjson.float32_converter)
|
|
847
|
+
self._relative_receiver_noise_bandwidth_converter = _ndjson.OptionalConverter(_ndjson.float32_converter)
|
|
848
|
+
self._receiver_channels_converter = _ndjson.OptionalConverter(_ndjson.uint32_converter)
|
|
849
|
+
self._coil_label_converter = _ndjson.VectorConverter(CoilLabelTypeConverter())
|
|
850
|
+
self._institution_name_converter = _ndjson.OptionalConverter(_ndjson.string_converter)
|
|
851
|
+
self._station_name_converter = _ndjson.OptionalConverter(_ndjson.string_converter)
|
|
852
|
+
self._device_id_converter = _ndjson.OptionalConverter(_ndjson.string_converter)
|
|
853
|
+
self._device_serial_number_converter = _ndjson.OptionalConverter(_ndjson.string_converter)
|
|
854
|
+
super().__init__(np.dtype([
|
|
855
|
+
("system_vendor", self._system_vendor_converter.overall_dtype()),
|
|
856
|
+
("system_model", self._system_model_converter.overall_dtype()),
|
|
857
|
+
("system_field_strength_t", self._system_field_strength_t_converter.overall_dtype()),
|
|
858
|
+
("relative_receiver_noise_bandwidth", self._relative_receiver_noise_bandwidth_converter.overall_dtype()),
|
|
859
|
+
("receiver_channels", self._receiver_channels_converter.overall_dtype()),
|
|
860
|
+
("coil_label", self._coil_label_converter.overall_dtype()),
|
|
861
|
+
("institution_name", self._institution_name_converter.overall_dtype()),
|
|
862
|
+
("station_name", self._station_name_converter.overall_dtype()),
|
|
863
|
+
("device_id", self._device_id_converter.overall_dtype()),
|
|
864
|
+
("device_serial_number", self._device_serial_number_converter.overall_dtype()),
|
|
865
|
+
]))
|
|
866
|
+
|
|
867
|
+
def to_json(self, value: AcquisitionSystemInformationType) -> object:
|
|
868
|
+
if not isinstance(value, AcquisitionSystemInformationType): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
869
|
+
raise TypeError("Expected 'AcquisitionSystemInformationType' instance")
|
|
870
|
+
json_object = {}
|
|
871
|
+
|
|
872
|
+
if value.system_vendor is not None:
|
|
873
|
+
json_object["systemVendor"] = self._system_vendor_converter.to_json(value.system_vendor)
|
|
874
|
+
if value.system_model is not None:
|
|
875
|
+
json_object["systemModel"] = self._system_model_converter.to_json(value.system_model)
|
|
876
|
+
if value.system_field_strength_t is not None:
|
|
877
|
+
json_object["systemFieldStrengthT"] = self._system_field_strength_t_converter.to_json(value.system_field_strength_t)
|
|
878
|
+
if value.relative_receiver_noise_bandwidth is not None:
|
|
879
|
+
json_object["relativeReceiverNoiseBandwidth"] = self._relative_receiver_noise_bandwidth_converter.to_json(value.relative_receiver_noise_bandwidth)
|
|
880
|
+
if value.receiver_channels is not None:
|
|
881
|
+
json_object["receiverChannels"] = self._receiver_channels_converter.to_json(value.receiver_channels)
|
|
882
|
+
json_object["coilLabel"] = self._coil_label_converter.to_json(value.coil_label)
|
|
883
|
+
if value.institution_name is not None:
|
|
884
|
+
json_object["institutionName"] = self._institution_name_converter.to_json(value.institution_name)
|
|
885
|
+
if value.station_name is not None:
|
|
886
|
+
json_object["stationName"] = self._station_name_converter.to_json(value.station_name)
|
|
887
|
+
if value.device_id is not None:
|
|
888
|
+
json_object["deviceID"] = self._device_id_converter.to_json(value.device_id)
|
|
889
|
+
if value.device_serial_number is not None:
|
|
890
|
+
json_object["deviceSerialNumber"] = self._device_serial_number_converter.to_json(value.device_serial_number)
|
|
891
|
+
return json_object
|
|
892
|
+
|
|
893
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
894
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
895
|
+
raise TypeError("Expected 'np.void' instance")
|
|
896
|
+
json_object = {}
|
|
897
|
+
|
|
898
|
+
if (field_val := value["system_vendor"]) is not None:
|
|
899
|
+
json_object["systemVendor"] = self._system_vendor_converter.numpy_to_json(field_val)
|
|
900
|
+
if (field_val := value["system_model"]) is not None:
|
|
901
|
+
json_object["systemModel"] = self._system_model_converter.numpy_to_json(field_val)
|
|
902
|
+
if (field_val := value["system_field_strength_t"]) is not None:
|
|
903
|
+
json_object["systemFieldStrengthT"] = self._system_field_strength_t_converter.numpy_to_json(field_val)
|
|
904
|
+
if (field_val := value["relative_receiver_noise_bandwidth"]) is not None:
|
|
905
|
+
json_object["relativeReceiverNoiseBandwidth"] = self._relative_receiver_noise_bandwidth_converter.numpy_to_json(field_val)
|
|
906
|
+
if (field_val := value["receiver_channels"]) is not None:
|
|
907
|
+
json_object["receiverChannels"] = self._receiver_channels_converter.numpy_to_json(field_val)
|
|
908
|
+
json_object["coilLabel"] = self._coil_label_converter.numpy_to_json(value["coil_label"])
|
|
909
|
+
if (field_val := value["institution_name"]) is not None:
|
|
910
|
+
json_object["institutionName"] = self._institution_name_converter.numpy_to_json(field_val)
|
|
911
|
+
if (field_val := value["station_name"]) is not None:
|
|
912
|
+
json_object["stationName"] = self._station_name_converter.numpy_to_json(field_val)
|
|
913
|
+
if (field_val := value["device_id"]) is not None:
|
|
914
|
+
json_object["deviceID"] = self._device_id_converter.numpy_to_json(field_val)
|
|
915
|
+
if (field_val := value["device_serial_number"]) is not None:
|
|
916
|
+
json_object["deviceSerialNumber"] = self._device_serial_number_converter.numpy_to_json(field_val)
|
|
917
|
+
return json_object
|
|
918
|
+
|
|
919
|
+
def from_json(self, json_object: object) -> AcquisitionSystemInformationType:
|
|
920
|
+
if not isinstance(json_object, dict):
|
|
921
|
+
raise TypeError("Expected 'dict' instance")
|
|
922
|
+
return AcquisitionSystemInformationType(
|
|
923
|
+
system_vendor=self._system_vendor_converter.from_json(json_object.get("systemVendor")),
|
|
924
|
+
system_model=self._system_model_converter.from_json(json_object.get("systemModel")),
|
|
925
|
+
system_field_strength_t=self._system_field_strength_t_converter.from_json(json_object.get("systemFieldStrengthT")),
|
|
926
|
+
relative_receiver_noise_bandwidth=self._relative_receiver_noise_bandwidth_converter.from_json(json_object.get("relativeReceiverNoiseBandwidth")),
|
|
927
|
+
receiver_channels=self._receiver_channels_converter.from_json(json_object.get("receiverChannels")),
|
|
928
|
+
coil_label=self._coil_label_converter.from_json(json_object["coilLabel"],),
|
|
929
|
+
institution_name=self._institution_name_converter.from_json(json_object.get("institutionName")),
|
|
930
|
+
station_name=self._station_name_converter.from_json(json_object.get("stationName")),
|
|
931
|
+
device_id=self._device_id_converter.from_json(json_object.get("deviceID")),
|
|
932
|
+
device_serial_number=self._device_serial_number_converter.from_json(json_object.get("deviceSerialNumber")),
|
|
933
|
+
)
|
|
934
|
+
|
|
935
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
936
|
+
if not isinstance(json_object, dict):
|
|
937
|
+
raise TypeError("Expected 'dict' instance")
|
|
938
|
+
return (
|
|
939
|
+
self._system_vendor_converter.from_json_to_numpy(json_object.get("systemVendor")),
|
|
940
|
+
self._system_model_converter.from_json_to_numpy(json_object.get("systemModel")),
|
|
941
|
+
self._system_field_strength_t_converter.from_json_to_numpy(json_object.get("systemFieldStrengthT")),
|
|
942
|
+
self._relative_receiver_noise_bandwidth_converter.from_json_to_numpy(json_object.get("relativeReceiverNoiseBandwidth")),
|
|
943
|
+
self._receiver_channels_converter.from_json_to_numpy(json_object.get("receiverChannels")),
|
|
944
|
+
self._coil_label_converter.from_json_to_numpy(json_object["coilLabel"]),
|
|
945
|
+
self._institution_name_converter.from_json_to_numpy(json_object.get("institutionName")),
|
|
946
|
+
self._station_name_converter.from_json_to_numpy(json_object.get("stationName")),
|
|
947
|
+
self._device_id_converter.from_json_to_numpy(json_object.get("deviceID")),
|
|
948
|
+
self._device_serial_number_converter.from_json_to_numpy(json_object.get("deviceSerialNumber")),
|
|
949
|
+
) # type:ignore
|
|
950
|
+
|
|
951
|
+
|
|
952
|
+
class ExperimentalConditionsTypeConverter(_ndjson.JsonConverter[ExperimentalConditionsType, np.void]):
|
|
953
|
+
def __init__(self) -> None:
|
|
954
|
+
self._h1resonance_frequency_hz_converter = _ndjson.int64_converter
|
|
955
|
+
super().__init__(np.dtype([
|
|
956
|
+
("h1resonance_frequency_hz", self._h1resonance_frequency_hz_converter.overall_dtype()),
|
|
957
|
+
]))
|
|
958
|
+
|
|
959
|
+
def to_json(self, value: ExperimentalConditionsType) -> object:
|
|
960
|
+
if not isinstance(value, ExperimentalConditionsType): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
961
|
+
raise TypeError("Expected 'ExperimentalConditionsType' instance")
|
|
962
|
+
json_object = {}
|
|
963
|
+
|
|
964
|
+
json_object["h1resonanceFrequencyHz"] = self._h1resonance_frequency_hz_converter.to_json(value.h1resonance_frequency_hz)
|
|
965
|
+
return json_object
|
|
966
|
+
|
|
967
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
968
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
969
|
+
raise TypeError("Expected 'np.void' instance")
|
|
970
|
+
json_object = {}
|
|
971
|
+
|
|
972
|
+
json_object["h1resonanceFrequencyHz"] = self._h1resonance_frequency_hz_converter.numpy_to_json(value["h1resonance_frequency_hz"])
|
|
973
|
+
return json_object
|
|
974
|
+
|
|
975
|
+
def from_json(self, json_object: object) -> ExperimentalConditionsType:
|
|
976
|
+
if not isinstance(json_object, dict):
|
|
977
|
+
raise TypeError("Expected 'dict' instance")
|
|
978
|
+
return ExperimentalConditionsType(
|
|
979
|
+
h1resonance_frequency_hz=self._h1resonance_frequency_hz_converter.from_json(json_object["h1resonanceFrequencyHz"],),
|
|
980
|
+
)
|
|
981
|
+
|
|
982
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
983
|
+
if not isinstance(json_object, dict):
|
|
984
|
+
raise TypeError("Expected 'dict' instance")
|
|
985
|
+
return (
|
|
986
|
+
self._h1resonance_frequency_hz_converter.from_json_to_numpy(json_object["h1resonanceFrequencyHz"]),
|
|
987
|
+
) # type:ignore
|
|
988
|
+
|
|
989
|
+
|
|
990
|
+
class MatrixSizeTypeConverter(_ndjson.JsonConverter[MatrixSizeType, np.void]):
|
|
991
|
+
def __init__(self) -> None:
|
|
992
|
+
self._x_converter = _ndjson.uint32_converter
|
|
993
|
+
self._y_converter = _ndjson.uint32_converter
|
|
994
|
+
self._z_converter = _ndjson.uint32_converter
|
|
995
|
+
super().__init__(np.dtype([
|
|
996
|
+
("x", self._x_converter.overall_dtype()),
|
|
997
|
+
("y", self._y_converter.overall_dtype()),
|
|
998
|
+
("z", self._z_converter.overall_dtype()),
|
|
999
|
+
]))
|
|
1000
|
+
|
|
1001
|
+
def to_json(self, value: MatrixSizeType) -> object:
|
|
1002
|
+
if not isinstance(value, MatrixSizeType): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1003
|
+
raise TypeError("Expected 'MatrixSizeType' instance")
|
|
1004
|
+
json_object = {}
|
|
1005
|
+
|
|
1006
|
+
json_object["x"] = self._x_converter.to_json(value.x)
|
|
1007
|
+
json_object["y"] = self._y_converter.to_json(value.y)
|
|
1008
|
+
json_object["z"] = self._z_converter.to_json(value.z)
|
|
1009
|
+
return json_object
|
|
1010
|
+
|
|
1011
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
1012
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1013
|
+
raise TypeError("Expected 'np.void' instance")
|
|
1014
|
+
json_object = {}
|
|
1015
|
+
|
|
1016
|
+
json_object["x"] = self._x_converter.numpy_to_json(value["x"])
|
|
1017
|
+
json_object["y"] = self._y_converter.numpy_to_json(value["y"])
|
|
1018
|
+
json_object["z"] = self._z_converter.numpy_to_json(value["z"])
|
|
1019
|
+
return json_object
|
|
1020
|
+
|
|
1021
|
+
def from_json(self, json_object: object) -> MatrixSizeType:
|
|
1022
|
+
if not isinstance(json_object, dict):
|
|
1023
|
+
raise TypeError("Expected 'dict' instance")
|
|
1024
|
+
return MatrixSizeType(
|
|
1025
|
+
x=self._x_converter.from_json(json_object["x"],),
|
|
1026
|
+
y=self._y_converter.from_json(json_object["y"],),
|
|
1027
|
+
z=self._z_converter.from_json(json_object["z"],),
|
|
1028
|
+
)
|
|
1029
|
+
|
|
1030
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
1031
|
+
if not isinstance(json_object, dict):
|
|
1032
|
+
raise TypeError("Expected 'dict' instance")
|
|
1033
|
+
return (
|
|
1034
|
+
self._x_converter.from_json_to_numpy(json_object["x"]),
|
|
1035
|
+
self._y_converter.from_json_to_numpy(json_object["y"]),
|
|
1036
|
+
self._z_converter.from_json_to_numpy(json_object["z"]),
|
|
1037
|
+
) # type:ignore
|
|
1038
|
+
|
|
1039
|
+
|
|
1040
|
+
class FieldOfViewMmConverter(_ndjson.JsonConverter[FieldOfViewMm, np.void]):
|
|
1041
|
+
def __init__(self) -> None:
|
|
1042
|
+
self._x_converter = _ndjson.float32_converter
|
|
1043
|
+
self._y_converter = _ndjson.float32_converter
|
|
1044
|
+
self._z_converter = _ndjson.float32_converter
|
|
1045
|
+
super().__init__(np.dtype([
|
|
1046
|
+
("x", self._x_converter.overall_dtype()),
|
|
1047
|
+
("y", self._y_converter.overall_dtype()),
|
|
1048
|
+
("z", self._z_converter.overall_dtype()),
|
|
1049
|
+
]))
|
|
1050
|
+
|
|
1051
|
+
def to_json(self, value: FieldOfViewMm) -> object:
|
|
1052
|
+
if not isinstance(value, FieldOfViewMm): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1053
|
+
raise TypeError("Expected 'FieldOfViewMm' instance")
|
|
1054
|
+
json_object = {}
|
|
1055
|
+
|
|
1056
|
+
json_object["x"] = self._x_converter.to_json(value.x)
|
|
1057
|
+
json_object["y"] = self._y_converter.to_json(value.y)
|
|
1058
|
+
json_object["z"] = self._z_converter.to_json(value.z)
|
|
1059
|
+
return json_object
|
|
1060
|
+
|
|
1061
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
1062
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1063
|
+
raise TypeError("Expected 'np.void' instance")
|
|
1064
|
+
json_object = {}
|
|
1065
|
+
|
|
1066
|
+
json_object["x"] = self._x_converter.numpy_to_json(value["x"])
|
|
1067
|
+
json_object["y"] = self._y_converter.numpy_to_json(value["y"])
|
|
1068
|
+
json_object["z"] = self._z_converter.numpy_to_json(value["z"])
|
|
1069
|
+
return json_object
|
|
1070
|
+
|
|
1071
|
+
def from_json(self, json_object: object) -> FieldOfViewMm:
|
|
1072
|
+
if not isinstance(json_object, dict):
|
|
1073
|
+
raise TypeError("Expected 'dict' instance")
|
|
1074
|
+
return FieldOfViewMm(
|
|
1075
|
+
x=self._x_converter.from_json(json_object["x"],),
|
|
1076
|
+
y=self._y_converter.from_json(json_object["y"],),
|
|
1077
|
+
z=self._z_converter.from_json(json_object["z"],),
|
|
1078
|
+
)
|
|
1079
|
+
|
|
1080
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
1081
|
+
if not isinstance(json_object, dict):
|
|
1082
|
+
raise TypeError("Expected 'dict' instance")
|
|
1083
|
+
return (
|
|
1084
|
+
self._x_converter.from_json_to_numpy(json_object["x"]),
|
|
1085
|
+
self._y_converter.from_json_to_numpy(json_object["y"]),
|
|
1086
|
+
self._z_converter.from_json_to_numpy(json_object["z"]),
|
|
1087
|
+
) # type:ignore
|
|
1088
|
+
|
|
1089
|
+
|
|
1090
|
+
class EncodingSpaceTypeConverter(_ndjson.JsonConverter[EncodingSpaceType, np.void]):
|
|
1091
|
+
def __init__(self) -> None:
|
|
1092
|
+
self._matrix_size_converter = MatrixSizeTypeConverter()
|
|
1093
|
+
self._field_of_view_mm_converter = FieldOfViewMmConverter()
|
|
1094
|
+
super().__init__(np.dtype([
|
|
1095
|
+
("matrix_size", self._matrix_size_converter.overall_dtype()),
|
|
1096
|
+
("field_of_view_mm", self._field_of_view_mm_converter.overall_dtype()),
|
|
1097
|
+
]))
|
|
1098
|
+
|
|
1099
|
+
def to_json(self, value: EncodingSpaceType) -> object:
|
|
1100
|
+
if not isinstance(value, EncodingSpaceType): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1101
|
+
raise TypeError("Expected 'EncodingSpaceType' instance")
|
|
1102
|
+
json_object = {}
|
|
1103
|
+
|
|
1104
|
+
json_object["matrixSize"] = self._matrix_size_converter.to_json(value.matrix_size)
|
|
1105
|
+
json_object["fieldOfViewMm"] = self._field_of_view_mm_converter.to_json(value.field_of_view_mm)
|
|
1106
|
+
return json_object
|
|
1107
|
+
|
|
1108
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
1109
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1110
|
+
raise TypeError("Expected 'np.void' instance")
|
|
1111
|
+
json_object = {}
|
|
1112
|
+
|
|
1113
|
+
json_object["matrixSize"] = self._matrix_size_converter.numpy_to_json(value["matrix_size"])
|
|
1114
|
+
json_object["fieldOfViewMm"] = self._field_of_view_mm_converter.numpy_to_json(value["field_of_view_mm"])
|
|
1115
|
+
return json_object
|
|
1116
|
+
|
|
1117
|
+
def from_json(self, json_object: object) -> EncodingSpaceType:
|
|
1118
|
+
if not isinstance(json_object, dict):
|
|
1119
|
+
raise TypeError("Expected 'dict' instance")
|
|
1120
|
+
return EncodingSpaceType(
|
|
1121
|
+
matrix_size=self._matrix_size_converter.from_json(json_object["matrixSize"],),
|
|
1122
|
+
field_of_view_mm=self._field_of_view_mm_converter.from_json(json_object["fieldOfViewMm"],),
|
|
1123
|
+
)
|
|
1124
|
+
|
|
1125
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
1126
|
+
if not isinstance(json_object, dict):
|
|
1127
|
+
raise TypeError("Expected 'dict' instance")
|
|
1128
|
+
return (
|
|
1129
|
+
self._matrix_size_converter.from_json_to_numpy(json_object["matrixSize"]),
|
|
1130
|
+
self._field_of_view_mm_converter.from_json_to_numpy(json_object["fieldOfViewMm"]),
|
|
1131
|
+
) # type:ignore
|
|
1132
|
+
|
|
1133
|
+
|
|
1134
|
+
class LimitTypeConverter(_ndjson.JsonConverter[LimitType, np.void]):
|
|
1135
|
+
def __init__(self) -> None:
|
|
1136
|
+
self._minimum_converter = _ndjson.uint32_converter
|
|
1137
|
+
self._maximum_converter = _ndjson.uint32_converter
|
|
1138
|
+
self._center_converter = _ndjson.uint32_converter
|
|
1139
|
+
super().__init__(np.dtype([
|
|
1140
|
+
("minimum", self._minimum_converter.overall_dtype()),
|
|
1141
|
+
("maximum", self._maximum_converter.overall_dtype()),
|
|
1142
|
+
("center", self._center_converter.overall_dtype()),
|
|
1143
|
+
]))
|
|
1144
|
+
|
|
1145
|
+
def to_json(self, value: LimitType) -> object:
|
|
1146
|
+
if not isinstance(value, LimitType): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1147
|
+
raise TypeError("Expected 'LimitType' instance")
|
|
1148
|
+
json_object = {}
|
|
1149
|
+
|
|
1150
|
+
json_object["minimum"] = self._minimum_converter.to_json(value.minimum)
|
|
1151
|
+
json_object["maximum"] = self._maximum_converter.to_json(value.maximum)
|
|
1152
|
+
json_object["center"] = self._center_converter.to_json(value.center)
|
|
1153
|
+
return json_object
|
|
1154
|
+
|
|
1155
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
1156
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1157
|
+
raise TypeError("Expected 'np.void' instance")
|
|
1158
|
+
json_object = {}
|
|
1159
|
+
|
|
1160
|
+
json_object["minimum"] = self._minimum_converter.numpy_to_json(value["minimum"])
|
|
1161
|
+
json_object["maximum"] = self._maximum_converter.numpy_to_json(value["maximum"])
|
|
1162
|
+
json_object["center"] = self._center_converter.numpy_to_json(value["center"])
|
|
1163
|
+
return json_object
|
|
1164
|
+
|
|
1165
|
+
def from_json(self, json_object: object) -> LimitType:
|
|
1166
|
+
if not isinstance(json_object, dict):
|
|
1167
|
+
raise TypeError("Expected 'dict' instance")
|
|
1168
|
+
return LimitType(
|
|
1169
|
+
minimum=self._minimum_converter.from_json(json_object["minimum"],),
|
|
1170
|
+
maximum=self._maximum_converter.from_json(json_object["maximum"],),
|
|
1171
|
+
center=self._center_converter.from_json(json_object["center"],),
|
|
1172
|
+
)
|
|
1173
|
+
|
|
1174
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
1175
|
+
if not isinstance(json_object, dict):
|
|
1176
|
+
raise TypeError("Expected 'dict' instance")
|
|
1177
|
+
return (
|
|
1178
|
+
self._minimum_converter.from_json_to_numpy(json_object["minimum"]),
|
|
1179
|
+
self._maximum_converter.from_json_to_numpy(json_object["maximum"]),
|
|
1180
|
+
self._center_converter.from_json_to_numpy(json_object["center"]),
|
|
1181
|
+
) # type:ignore
|
|
1182
|
+
|
|
1183
|
+
|
|
1184
|
+
class EncodingLimitsTypeConverter(_ndjson.JsonConverter[EncodingLimitsType, np.void]):
|
|
1185
|
+
def __init__(self) -> None:
|
|
1186
|
+
self._kspace_encoding_step_0_converter = _ndjson.OptionalConverter(LimitTypeConverter())
|
|
1187
|
+
self._kspace_encoding_step_1_converter = _ndjson.OptionalConverter(LimitTypeConverter())
|
|
1188
|
+
self._kspace_encoding_step_2_converter = _ndjson.OptionalConverter(LimitTypeConverter())
|
|
1189
|
+
self._average_converter = _ndjson.OptionalConverter(LimitTypeConverter())
|
|
1190
|
+
self._slice_converter = _ndjson.OptionalConverter(LimitTypeConverter())
|
|
1191
|
+
self._contrast_converter = _ndjson.OptionalConverter(LimitTypeConverter())
|
|
1192
|
+
self._phase_converter = _ndjson.OptionalConverter(LimitTypeConverter())
|
|
1193
|
+
self._repetition_converter = _ndjson.OptionalConverter(LimitTypeConverter())
|
|
1194
|
+
self._set_converter = _ndjson.OptionalConverter(LimitTypeConverter())
|
|
1195
|
+
self._segment_converter = _ndjson.OptionalConverter(LimitTypeConverter())
|
|
1196
|
+
self._user_0_converter = _ndjson.OptionalConverter(LimitTypeConverter())
|
|
1197
|
+
self._user_1_converter = _ndjson.OptionalConverter(LimitTypeConverter())
|
|
1198
|
+
self._user_2_converter = _ndjson.OptionalConverter(LimitTypeConverter())
|
|
1199
|
+
self._user_3_converter = _ndjson.OptionalConverter(LimitTypeConverter())
|
|
1200
|
+
self._user_4_converter = _ndjson.OptionalConverter(LimitTypeConverter())
|
|
1201
|
+
self._user_5_converter = _ndjson.OptionalConverter(LimitTypeConverter())
|
|
1202
|
+
self._user_6_converter = _ndjson.OptionalConverter(LimitTypeConverter())
|
|
1203
|
+
self._user_7_converter = _ndjson.OptionalConverter(LimitTypeConverter())
|
|
1204
|
+
super().__init__(np.dtype([
|
|
1205
|
+
("kspace_encoding_step_0", self._kspace_encoding_step_0_converter.overall_dtype()),
|
|
1206
|
+
("kspace_encoding_step_1", self._kspace_encoding_step_1_converter.overall_dtype()),
|
|
1207
|
+
("kspace_encoding_step_2", self._kspace_encoding_step_2_converter.overall_dtype()),
|
|
1208
|
+
("average", self._average_converter.overall_dtype()),
|
|
1209
|
+
("slice", self._slice_converter.overall_dtype()),
|
|
1210
|
+
("contrast", self._contrast_converter.overall_dtype()),
|
|
1211
|
+
("phase", self._phase_converter.overall_dtype()),
|
|
1212
|
+
("repetition", self._repetition_converter.overall_dtype()),
|
|
1213
|
+
("set", self._set_converter.overall_dtype()),
|
|
1214
|
+
("segment", self._segment_converter.overall_dtype()),
|
|
1215
|
+
("user_0", self._user_0_converter.overall_dtype()),
|
|
1216
|
+
("user_1", self._user_1_converter.overall_dtype()),
|
|
1217
|
+
("user_2", self._user_2_converter.overall_dtype()),
|
|
1218
|
+
("user_3", self._user_3_converter.overall_dtype()),
|
|
1219
|
+
("user_4", self._user_4_converter.overall_dtype()),
|
|
1220
|
+
("user_5", self._user_5_converter.overall_dtype()),
|
|
1221
|
+
("user_6", self._user_6_converter.overall_dtype()),
|
|
1222
|
+
("user_7", self._user_7_converter.overall_dtype()),
|
|
1223
|
+
]))
|
|
1224
|
+
|
|
1225
|
+
def to_json(self, value: EncodingLimitsType) -> object:
|
|
1226
|
+
if not isinstance(value, EncodingLimitsType): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1227
|
+
raise TypeError("Expected 'EncodingLimitsType' instance")
|
|
1228
|
+
json_object = {}
|
|
1229
|
+
|
|
1230
|
+
if value.kspace_encoding_step_0 is not None:
|
|
1231
|
+
json_object["kspaceEncodingStep0"] = self._kspace_encoding_step_0_converter.to_json(value.kspace_encoding_step_0)
|
|
1232
|
+
if value.kspace_encoding_step_1 is not None:
|
|
1233
|
+
json_object["kspaceEncodingStep1"] = self._kspace_encoding_step_1_converter.to_json(value.kspace_encoding_step_1)
|
|
1234
|
+
if value.kspace_encoding_step_2 is not None:
|
|
1235
|
+
json_object["kspaceEncodingStep2"] = self._kspace_encoding_step_2_converter.to_json(value.kspace_encoding_step_2)
|
|
1236
|
+
if value.average is not None:
|
|
1237
|
+
json_object["average"] = self._average_converter.to_json(value.average)
|
|
1238
|
+
if value.slice is not None:
|
|
1239
|
+
json_object["slice"] = self._slice_converter.to_json(value.slice)
|
|
1240
|
+
if value.contrast is not None:
|
|
1241
|
+
json_object["contrast"] = self._contrast_converter.to_json(value.contrast)
|
|
1242
|
+
if value.phase is not None:
|
|
1243
|
+
json_object["phase"] = self._phase_converter.to_json(value.phase)
|
|
1244
|
+
if value.repetition is not None:
|
|
1245
|
+
json_object["repetition"] = self._repetition_converter.to_json(value.repetition)
|
|
1246
|
+
if value.set is not None:
|
|
1247
|
+
json_object["set"] = self._set_converter.to_json(value.set)
|
|
1248
|
+
if value.segment is not None:
|
|
1249
|
+
json_object["segment"] = self._segment_converter.to_json(value.segment)
|
|
1250
|
+
if value.user_0 is not None:
|
|
1251
|
+
json_object["user0"] = self._user_0_converter.to_json(value.user_0)
|
|
1252
|
+
if value.user_1 is not None:
|
|
1253
|
+
json_object["user1"] = self._user_1_converter.to_json(value.user_1)
|
|
1254
|
+
if value.user_2 is not None:
|
|
1255
|
+
json_object["user2"] = self._user_2_converter.to_json(value.user_2)
|
|
1256
|
+
if value.user_3 is not None:
|
|
1257
|
+
json_object["user3"] = self._user_3_converter.to_json(value.user_3)
|
|
1258
|
+
if value.user_4 is not None:
|
|
1259
|
+
json_object["user4"] = self._user_4_converter.to_json(value.user_4)
|
|
1260
|
+
if value.user_5 is not None:
|
|
1261
|
+
json_object["user5"] = self._user_5_converter.to_json(value.user_5)
|
|
1262
|
+
if value.user_6 is not None:
|
|
1263
|
+
json_object["user6"] = self._user_6_converter.to_json(value.user_6)
|
|
1264
|
+
if value.user_7 is not None:
|
|
1265
|
+
json_object["user7"] = self._user_7_converter.to_json(value.user_7)
|
|
1266
|
+
return json_object
|
|
1267
|
+
|
|
1268
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
1269
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1270
|
+
raise TypeError("Expected 'np.void' instance")
|
|
1271
|
+
json_object = {}
|
|
1272
|
+
|
|
1273
|
+
if (field_val := value["kspace_encoding_step_0"]) is not None:
|
|
1274
|
+
json_object["kspaceEncodingStep0"] = self._kspace_encoding_step_0_converter.numpy_to_json(field_val)
|
|
1275
|
+
if (field_val := value["kspace_encoding_step_1"]) is not None:
|
|
1276
|
+
json_object["kspaceEncodingStep1"] = self._kspace_encoding_step_1_converter.numpy_to_json(field_val)
|
|
1277
|
+
if (field_val := value["kspace_encoding_step_2"]) is not None:
|
|
1278
|
+
json_object["kspaceEncodingStep2"] = self._kspace_encoding_step_2_converter.numpy_to_json(field_val)
|
|
1279
|
+
if (field_val := value["average"]) is not None:
|
|
1280
|
+
json_object["average"] = self._average_converter.numpy_to_json(field_val)
|
|
1281
|
+
if (field_val := value["slice"]) is not None:
|
|
1282
|
+
json_object["slice"] = self._slice_converter.numpy_to_json(field_val)
|
|
1283
|
+
if (field_val := value["contrast"]) is not None:
|
|
1284
|
+
json_object["contrast"] = self._contrast_converter.numpy_to_json(field_val)
|
|
1285
|
+
if (field_val := value["phase"]) is not None:
|
|
1286
|
+
json_object["phase"] = self._phase_converter.numpy_to_json(field_val)
|
|
1287
|
+
if (field_val := value["repetition"]) is not None:
|
|
1288
|
+
json_object["repetition"] = self._repetition_converter.numpy_to_json(field_val)
|
|
1289
|
+
if (field_val := value["set"]) is not None:
|
|
1290
|
+
json_object["set"] = self._set_converter.numpy_to_json(field_val)
|
|
1291
|
+
if (field_val := value["segment"]) is not None:
|
|
1292
|
+
json_object["segment"] = self._segment_converter.numpy_to_json(field_val)
|
|
1293
|
+
if (field_val := value["user_0"]) is not None:
|
|
1294
|
+
json_object["user0"] = self._user_0_converter.numpy_to_json(field_val)
|
|
1295
|
+
if (field_val := value["user_1"]) is not None:
|
|
1296
|
+
json_object["user1"] = self._user_1_converter.numpy_to_json(field_val)
|
|
1297
|
+
if (field_val := value["user_2"]) is not None:
|
|
1298
|
+
json_object["user2"] = self._user_2_converter.numpy_to_json(field_val)
|
|
1299
|
+
if (field_val := value["user_3"]) is not None:
|
|
1300
|
+
json_object["user3"] = self._user_3_converter.numpy_to_json(field_val)
|
|
1301
|
+
if (field_val := value["user_4"]) is not None:
|
|
1302
|
+
json_object["user4"] = self._user_4_converter.numpy_to_json(field_val)
|
|
1303
|
+
if (field_val := value["user_5"]) is not None:
|
|
1304
|
+
json_object["user5"] = self._user_5_converter.numpy_to_json(field_val)
|
|
1305
|
+
if (field_val := value["user_6"]) is not None:
|
|
1306
|
+
json_object["user6"] = self._user_6_converter.numpy_to_json(field_val)
|
|
1307
|
+
if (field_val := value["user_7"]) is not None:
|
|
1308
|
+
json_object["user7"] = self._user_7_converter.numpy_to_json(field_val)
|
|
1309
|
+
return json_object
|
|
1310
|
+
|
|
1311
|
+
def from_json(self, json_object: object) -> EncodingLimitsType:
|
|
1312
|
+
if not isinstance(json_object, dict):
|
|
1313
|
+
raise TypeError("Expected 'dict' instance")
|
|
1314
|
+
return EncodingLimitsType(
|
|
1315
|
+
kspace_encoding_step_0=self._kspace_encoding_step_0_converter.from_json(json_object.get("kspaceEncodingStep0")),
|
|
1316
|
+
kspace_encoding_step_1=self._kspace_encoding_step_1_converter.from_json(json_object.get("kspaceEncodingStep1")),
|
|
1317
|
+
kspace_encoding_step_2=self._kspace_encoding_step_2_converter.from_json(json_object.get("kspaceEncodingStep2")),
|
|
1318
|
+
average=self._average_converter.from_json(json_object.get("average")),
|
|
1319
|
+
slice=self._slice_converter.from_json(json_object.get("slice")),
|
|
1320
|
+
contrast=self._contrast_converter.from_json(json_object.get("contrast")),
|
|
1321
|
+
phase=self._phase_converter.from_json(json_object.get("phase")),
|
|
1322
|
+
repetition=self._repetition_converter.from_json(json_object.get("repetition")),
|
|
1323
|
+
set=self._set_converter.from_json(json_object.get("set")),
|
|
1324
|
+
segment=self._segment_converter.from_json(json_object.get("segment")),
|
|
1325
|
+
user_0=self._user_0_converter.from_json(json_object.get("user0")),
|
|
1326
|
+
user_1=self._user_1_converter.from_json(json_object.get("user1")),
|
|
1327
|
+
user_2=self._user_2_converter.from_json(json_object.get("user2")),
|
|
1328
|
+
user_3=self._user_3_converter.from_json(json_object.get("user3")),
|
|
1329
|
+
user_4=self._user_4_converter.from_json(json_object.get("user4")),
|
|
1330
|
+
user_5=self._user_5_converter.from_json(json_object.get("user5")),
|
|
1331
|
+
user_6=self._user_6_converter.from_json(json_object.get("user6")),
|
|
1332
|
+
user_7=self._user_7_converter.from_json(json_object.get("user7")),
|
|
1333
|
+
)
|
|
1334
|
+
|
|
1335
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
1336
|
+
if not isinstance(json_object, dict):
|
|
1337
|
+
raise TypeError("Expected 'dict' instance")
|
|
1338
|
+
return (
|
|
1339
|
+
self._kspace_encoding_step_0_converter.from_json_to_numpy(json_object.get("kspaceEncodingStep0")),
|
|
1340
|
+
self._kspace_encoding_step_1_converter.from_json_to_numpy(json_object.get("kspaceEncodingStep1")),
|
|
1341
|
+
self._kspace_encoding_step_2_converter.from_json_to_numpy(json_object.get("kspaceEncodingStep2")),
|
|
1342
|
+
self._average_converter.from_json_to_numpy(json_object.get("average")),
|
|
1343
|
+
self._slice_converter.from_json_to_numpy(json_object.get("slice")),
|
|
1344
|
+
self._contrast_converter.from_json_to_numpy(json_object.get("contrast")),
|
|
1345
|
+
self._phase_converter.from_json_to_numpy(json_object.get("phase")),
|
|
1346
|
+
self._repetition_converter.from_json_to_numpy(json_object.get("repetition")),
|
|
1347
|
+
self._set_converter.from_json_to_numpy(json_object.get("set")),
|
|
1348
|
+
self._segment_converter.from_json_to_numpy(json_object.get("segment")),
|
|
1349
|
+
self._user_0_converter.from_json_to_numpy(json_object.get("user0")),
|
|
1350
|
+
self._user_1_converter.from_json_to_numpy(json_object.get("user1")),
|
|
1351
|
+
self._user_2_converter.from_json_to_numpy(json_object.get("user2")),
|
|
1352
|
+
self._user_3_converter.from_json_to_numpy(json_object.get("user3")),
|
|
1353
|
+
self._user_4_converter.from_json_to_numpy(json_object.get("user4")),
|
|
1354
|
+
self._user_5_converter.from_json_to_numpy(json_object.get("user5")),
|
|
1355
|
+
self._user_6_converter.from_json_to_numpy(json_object.get("user6")),
|
|
1356
|
+
self._user_7_converter.from_json_to_numpy(json_object.get("user7")),
|
|
1357
|
+
) # type:ignore
|
|
1358
|
+
|
|
1359
|
+
|
|
1360
|
+
trajectory_name_to_value_map = {
|
|
1361
|
+
"cartesian": Trajectory.CARTESIAN,
|
|
1362
|
+
"epi": Trajectory.EPI,
|
|
1363
|
+
"radial": Trajectory.RADIAL,
|
|
1364
|
+
"goldenangle": Trajectory.GOLDENANGLE,
|
|
1365
|
+
"spiral": Trajectory.SPIRAL,
|
|
1366
|
+
"other": Trajectory.OTHER,
|
|
1367
|
+
}
|
|
1368
|
+
trajectory_value_to_name_map = {v: n for n, v in trajectory_name_to_value_map.items()}
|
|
1369
|
+
|
|
1370
|
+
class UserParameterLongTypeConverter(_ndjson.JsonConverter[UserParameterLongType, np.void]):
|
|
1371
|
+
def __init__(self) -> None:
|
|
1372
|
+
self._name_converter = _ndjson.string_converter
|
|
1373
|
+
self._value_converter = _ndjson.int64_converter
|
|
1374
|
+
super().__init__(np.dtype([
|
|
1375
|
+
("name", self._name_converter.overall_dtype()),
|
|
1376
|
+
("value", self._value_converter.overall_dtype()),
|
|
1377
|
+
]))
|
|
1378
|
+
|
|
1379
|
+
def to_json(self, value: UserParameterLongType) -> object:
|
|
1380
|
+
if not isinstance(value, UserParameterLongType): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1381
|
+
raise TypeError("Expected 'UserParameterLongType' instance")
|
|
1382
|
+
json_object = {}
|
|
1383
|
+
|
|
1384
|
+
json_object["name"] = self._name_converter.to_json(value.name)
|
|
1385
|
+
json_object["value"] = self._value_converter.to_json(value.value)
|
|
1386
|
+
return json_object
|
|
1387
|
+
|
|
1388
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
1389
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1390
|
+
raise TypeError("Expected 'np.void' instance")
|
|
1391
|
+
json_object = {}
|
|
1392
|
+
|
|
1393
|
+
json_object["name"] = self._name_converter.numpy_to_json(value["name"])
|
|
1394
|
+
json_object["value"] = self._value_converter.numpy_to_json(value["value"])
|
|
1395
|
+
return json_object
|
|
1396
|
+
|
|
1397
|
+
def from_json(self, json_object: object) -> UserParameterLongType:
|
|
1398
|
+
if not isinstance(json_object, dict):
|
|
1399
|
+
raise TypeError("Expected 'dict' instance")
|
|
1400
|
+
return UserParameterLongType(
|
|
1401
|
+
name=self._name_converter.from_json(json_object["name"],),
|
|
1402
|
+
value=self._value_converter.from_json(json_object["value"],),
|
|
1403
|
+
)
|
|
1404
|
+
|
|
1405
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
1406
|
+
if not isinstance(json_object, dict):
|
|
1407
|
+
raise TypeError("Expected 'dict' instance")
|
|
1408
|
+
return (
|
|
1409
|
+
self._name_converter.from_json_to_numpy(json_object["name"]),
|
|
1410
|
+
self._value_converter.from_json_to_numpy(json_object["value"]),
|
|
1411
|
+
) # type:ignore
|
|
1412
|
+
|
|
1413
|
+
|
|
1414
|
+
class UserParameterDoubleTypeConverter(_ndjson.JsonConverter[UserParameterDoubleType, np.void]):
|
|
1415
|
+
def __init__(self) -> None:
|
|
1416
|
+
self._name_converter = _ndjson.string_converter
|
|
1417
|
+
self._value_converter = _ndjson.float64_converter
|
|
1418
|
+
super().__init__(np.dtype([
|
|
1419
|
+
("name", self._name_converter.overall_dtype()),
|
|
1420
|
+
("value", self._value_converter.overall_dtype()),
|
|
1421
|
+
]))
|
|
1422
|
+
|
|
1423
|
+
def to_json(self, value: UserParameterDoubleType) -> object:
|
|
1424
|
+
if not isinstance(value, UserParameterDoubleType): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1425
|
+
raise TypeError("Expected 'UserParameterDoubleType' instance")
|
|
1426
|
+
json_object = {}
|
|
1427
|
+
|
|
1428
|
+
json_object["name"] = self._name_converter.to_json(value.name)
|
|
1429
|
+
json_object["value"] = self._value_converter.to_json(value.value)
|
|
1430
|
+
return json_object
|
|
1431
|
+
|
|
1432
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
1433
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1434
|
+
raise TypeError("Expected 'np.void' instance")
|
|
1435
|
+
json_object = {}
|
|
1436
|
+
|
|
1437
|
+
json_object["name"] = self._name_converter.numpy_to_json(value["name"])
|
|
1438
|
+
json_object["value"] = self._value_converter.numpy_to_json(value["value"])
|
|
1439
|
+
return json_object
|
|
1440
|
+
|
|
1441
|
+
def from_json(self, json_object: object) -> UserParameterDoubleType:
|
|
1442
|
+
if not isinstance(json_object, dict):
|
|
1443
|
+
raise TypeError("Expected 'dict' instance")
|
|
1444
|
+
return UserParameterDoubleType(
|
|
1445
|
+
name=self._name_converter.from_json(json_object["name"],),
|
|
1446
|
+
value=self._value_converter.from_json(json_object["value"],),
|
|
1447
|
+
)
|
|
1448
|
+
|
|
1449
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
1450
|
+
if not isinstance(json_object, dict):
|
|
1451
|
+
raise TypeError("Expected 'dict' instance")
|
|
1452
|
+
return (
|
|
1453
|
+
self._name_converter.from_json_to_numpy(json_object["name"]),
|
|
1454
|
+
self._value_converter.from_json_to_numpy(json_object["value"]),
|
|
1455
|
+
) # type:ignore
|
|
1456
|
+
|
|
1457
|
+
|
|
1458
|
+
class UserParameterStringTypeConverter(_ndjson.JsonConverter[UserParameterStringType, np.void]):
|
|
1459
|
+
def __init__(self) -> None:
|
|
1460
|
+
self._name_converter = _ndjson.string_converter
|
|
1461
|
+
self._value_converter = _ndjson.string_converter
|
|
1462
|
+
super().__init__(np.dtype([
|
|
1463
|
+
("name", self._name_converter.overall_dtype()),
|
|
1464
|
+
("value", self._value_converter.overall_dtype()),
|
|
1465
|
+
]))
|
|
1466
|
+
|
|
1467
|
+
def to_json(self, value: UserParameterStringType) -> object:
|
|
1468
|
+
if not isinstance(value, UserParameterStringType): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1469
|
+
raise TypeError("Expected 'UserParameterStringType' instance")
|
|
1470
|
+
json_object = {}
|
|
1471
|
+
|
|
1472
|
+
json_object["name"] = self._name_converter.to_json(value.name)
|
|
1473
|
+
json_object["value"] = self._value_converter.to_json(value.value)
|
|
1474
|
+
return json_object
|
|
1475
|
+
|
|
1476
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
1477
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1478
|
+
raise TypeError("Expected 'np.void' instance")
|
|
1479
|
+
json_object = {}
|
|
1480
|
+
|
|
1481
|
+
json_object["name"] = self._name_converter.numpy_to_json(value["name"])
|
|
1482
|
+
json_object["value"] = self._value_converter.numpy_to_json(value["value"])
|
|
1483
|
+
return json_object
|
|
1484
|
+
|
|
1485
|
+
def from_json(self, json_object: object) -> UserParameterStringType:
|
|
1486
|
+
if not isinstance(json_object, dict):
|
|
1487
|
+
raise TypeError("Expected 'dict' instance")
|
|
1488
|
+
return UserParameterStringType(
|
|
1489
|
+
name=self._name_converter.from_json(json_object["name"],),
|
|
1490
|
+
value=self._value_converter.from_json(json_object["value"],),
|
|
1491
|
+
)
|
|
1492
|
+
|
|
1493
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
1494
|
+
if not isinstance(json_object, dict):
|
|
1495
|
+
raise TypeError("Expected 'dict' instance")
|
|
1496
|
+
return (
|
|
1497
|
+
self._name_converter.from_json_to_numpy(json_object["name"]),
|
|
1498
|
+
self._value_converter.from_json_to_numpy(json_object["value"]),
|
|
1499
|
+
) # type:ignore
|
|
1500
|
+
|
|
1501
|
+
|
|
1502
|
+
class TrajectoryDescriptionTypeConverter(_ndjson.JsonConverter[TrajectoryDescriptionType, np.void]):
|
|
1503
|
+
def __init__(self) -> None:
|
|
1504
|
+
self._identifier_converter = _ndjson.string_converter
|
|
1505
|
+
self._user_parameter_long_converter = _ndjson.VectorConverter(UserParameterLongTypeConverter())
|
|
1506
|
+
self._user_parameter_double_converter = _ndjson.VectorConverter(UserParameterDoubleTypeConverter())
|
|
1507
|
+
self._user_parameter_string_converter = _ndjson.VectorConverter(UserParameterStringTypeConverter())
|
|
1508
|
+
self._comment_converter = _ndjson.OptionalConverter(_ndjson.string_converter)
|
|
1509
|
+
super().__init__(np.dtype([
|
|
1510
|
+
("identifier", self._identifier_converter.overall_dtype()),
|
|
1511
|
+
("user_parameter_long", self._user_parameter_long_converter.overall_dtype()),
|
|
1512
|
+
("user_parameter_double", self._user_parameter_double_converter.overall_dtype()),
|
|
1513
|
+
("user_parameter_string", self._user_parameter_string_converter.overall_dtype()),
|
|
1514
|
+
("comment", self._comment_converter.overall_dtype()),
|
|
1515
|
+
]))
|
|
1516
|
+
|
|
1517
|
+
def to_json(self, value: TrajectoryDescriptionType) -> object:
|
|
1518
|
+
if not isinstance(value, TrajectoryDescriptionType): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1519
|
+
raise TypeError("Expected 'TrajectoryDescriptionType' instance")
|
|
1520
|
+
json_object = {}
|
|
1521
|
+
|
|
1522
|
+
json_object["identifier"] = self._identifier_converter.to_json(value.identifier)
|
|
1523
|
+
json_object["userParameterLong"] = self._user_parameter_long_converter.to_json(value.user_parameter_long)
|
|
1524
|
+
json_object["userParameterDouble"] = self._user_parameter_double_converter.to_json(value.user_parameter_double)
|
|
1525
|
+
json_object["userParameterString"] = self._user_parameter_string_converter.to_json(value.user_parameter_string)
|
|
1526
|
+
if value.comment is not None:
|
|
1527
|
+
json_object["comment"] = self._comment_converter.to_json(value.comment)
|
|
1528
|
+
return json_object
|
|
1529
|
+
|
|
1530
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
1531
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1532
|
+
raise TypeError("Expected 'np.void' instance")
|
|
1533
|
+
json_object = {}
|
|
1534
|
+
|
|
1535
|
+
json_object["identifier"] = self._identifier_converter.numpy_to_json(value["identifier"])
|
|
1536
|
+
json_object["userParameterLong"] = self._user_parameter_long_converter.numpy_to_json(value["user_parameter_long"])
|
|
1537
|
+
json_object["userParameterDouble"] = self._user_parameter_double_converter.numpy_to_json(value["user_parameter_double"])
|
|
1538
|
+
json_object["userParameterString"] = self._user_parameter_string_converter.numpy_to_json(value["user_parameter_string"])
|
|
1539
|
+
if (field_val := value["comment"]) is not None:
|
|
1540
|
+
json_object["comment"] = self._comment_converter.numpy_to_json(field_val)
|
|
1541
|
+
return json_object
|
|
1542
|
+
|
|
1543
|
+
def from_json(self, json_object: object) -> TrajectoryDescriptionType:
|
|
1544
|
+
if not isinstance(json_object, dict):
|
|
1545
|
+
raise TypeError("Expected 'dict' instance")
|
|
1546
|
+
return TrajectoryDescriptionType(
|
|
1547
|
+
identifier=self._identifier_converter.from_json(json_object["identifier"],),
|
|
1548
|
+
user_parameter_long=self._user_parameter_long_converter.from_json(json_object["userParameterLong"],),
|
|
1549
|
+
user_parameter_double=self._user_parameter_double_converter.from_json(json_object["userParameterDouble"],),
|
|
1550
|
+
user_parameter_string=self._user_parameter_string_converter.from_json(json_object["userParameterString"],),
|
|
1551
|
+
comment=self._comment_converter.from_json(json_object.get("comment")),
|
|
1552
|
+
)
|
|
1553
|
+
|
|
1554
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
1555
|
+
if not isinstance(json_object, dict):
|
|
1556
|
+
raise TypeError("Expected 'dict' instance")
|
|
1557
|
+
return (
|
|
1558
|
+
self._identifier_converter.from_json_to_numpy(json_object["identifier"]),
|
|
1559
|
+
self._user_parameter_long_converter.from_json_to_numpy(json_object["userParameterLong"]),
|
|
1560
|
+
self._user_parameter_double_converter.from_json_to_numpy(json_object["userParameterDouble"]),
|
|
1561
|
+
self._user_parameter_string_converter.from_json_to_numpy(json_object["userParameterString"]),
|
|
1562
|
+
self._comment_converter.from_json_to_numpy(json_object.get("comment")),
|
|
1563
|
+
) # type:ignore
|
|
1564
|
+
|
|
1565
|
+
|
|
1566
|
+
class AccelerationFactorTypeConverter(_ndjson.JsonConverter[AccelerationFactorType, np.void]):
|
|
1567
|
+
def __init__(self) -> None:
|
|
1568
|
+
self._kspace_encoding_step_1_converter = _ndjson.uint32_converter
|
|
1569
|
+
self._kspace_encoding_step_2_converter = _ndjson.uint32_converter
|
|
1570
|
+
super().__init__(np.dtype([
|
|
1571
|
+
("kspace_encoding_step_1", self._kspace_encoding_step_1_converter.overall_dtype()),
|
|
1572
|
+
("kspace_encoding_step_2", self._kspace_encoding_step_2_converter.overall_dtype()),
|
|
1573
|
+
]))
|
|
1574
|
+
|
|
1575
|
+
def to_json(self, value: AccelerationFactorType) -> object:
|
|
1576
|
+
if not isinstance(value, AccelerationFactorType): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1577
|
+
raise TypeError("Expected 'AccelerationFactorType' instance")
|
|
1578
|
+
json_object = {}
|
|
1579
|
+
|
|
1580
|
+
json_object["kspaceEncodingStep1"] = self._kspace_encoding_step_1_converter.to_json(value.kspace_encoding_step_1)
|
|
1581
|
+
json_object["kspaceEncodingStep2"] = self._kspace_encoding_step_2_converter.to_json(value.kspace_encoding_step_2)
|
|
1582
|
+
return json_object
|
|
1583
|
+
|
|
1584
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
1585
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1586
|
+
raise TypeError("Expected 'np.void' instance")
|
|
1587
|
+
json_object = {}
|
|
1588
|
+
|
|
1589
|
+
json_object["kspaceEncodingStep1"] = self._kspace_encoding_step_1_converter.numpy_to_json(value["kspace_encoding_step_1"])
|
|
1590
|
+
json_object["kspaceEncodingStep2"] = self._kspace_encoding_step_2_converter.numpy_to_json(value["kspace_encoding_step_2"])
|
|
1591
|
+
return json_object
|
|
1592
|
+
|
|
1593
|
+
def from_json(self, json_object: object) -> AccelerationFactorType:
|
|
1594
|
+
if not isinstance(json_object, dict):
|
|
1595
|
+
raise TypeError("Expected 'dict' instance")
|
|
1596
|
+
return AccelerationFactorType(
|
|
1597
|
+
kspace_encoding_step_1=self._kspace_encoding_step_1_converter.from_json(json_object["kspaceEncodingStep1"],),
|
|
1598
|
+
kspace_encoding_step_2=self._kspace_encoding_step_2_converter.from_json(json_object["kspaceEncodingStep2"],),
|
|
1599
|
+
)
|
|
1600
|
+
|
|
1601
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
1602
|
+
if not isinstance(json_object, dict):
|
|
1603
|
+
raise TypeError("Expected 'dict' instance")
|
|
1604
|
+
return (
|
|
1605
|
+
self._kspace_encoding_step_1_converter.from_json_to_numpy(json_object["kspaceEncodingStep1"]),
|
|
1606
|
+
self._kspace_encoding_step_2_converter.from_json_to_numpy(json_object["kspaceEncodingStep2"]),
|
|
1607
|
+
) # type:ignore
|
|
1608
|
+
|
|
1609
|
+
|
|
1610
|
+
calibration_mode_name_to_value_map = {
|
|
1611
|
+
"embedded": CalibrationMode.EMBEDDED,
|
|
1612
|
+
"interleaved": CalibrationMode.INTERLEAVED,
|
|
1613
|
+
"separate": CalibrationMode.SEPARATE,
|
|
1614
|
+
"external": CalibrationMode.EXTERNAL,
|
|
1615
|
+
"other": CalibrationMode.OTHER,
|
|
1616
|
+
}
|
|
1617
|
+
calibration_mode_value_to_name_map = {v: n for n, v in calibration_mode_name_to_value_map.items()}
|
|
1618
|
+
|
|
1619
|
+
interleaving_dimension_name_to_value_map = {
|
|
1620
|
+
"phase": InterleavingDimension.PHASE,
|
|
1621
|
+
"repetition": InterleavingDimension.REPETITION,
|
|
1622
|
+
"contrast": InterleavingDimension.CONTRAST,
|
|
1623
|
+
"average": InterleavingDimension.AVERAGE,
|
|
1624
|
+
"other": InterleavingDimension.OTHER,
|
|
1625
|
+
}
|
|
1626
|
+
interleaving_dimension_value_to_name_map = {v: n for n, v in interleaving_dimension_name_to_value_map.items()}
|
|
1627
|
+
|
|
1628
|
+
class MultibandSpacingTypeConverter(_ndjson.JsonConverter[MultibandSpacingType, np.void]):
|
|
1629
|
+
def __init__(self) -> None:
|
|
1630
|
+
self._d_z_converter = _ndjson.VectorConverter(_ndjson.float32_converter)
|
|
1631
|
+
super().__init__(np.dtype([
|
|
1632
|
+
("d_z", self._d_z_converter.overall_dtype()),
|
|
1633
|
+
]))
|
|
1634
|
+
|
|
1635
|
+
def to_json(self, value: MultibandSpacingType) -> object:
|
|
1636
|
+
if not isinstance(value, MultibandSpacingType): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1637
|
+
raise TypeError("Expected 'MultibandSpacingType' instance")
|
|
1638
|
+
json_object = {}
|
|
1639
|
+
|
|
1640
|
+
json_object["dZ"] = self._d_z_converter.to_json(value.d_z)
|
|
1641
|
+
return json_object
|
|
1642
|
+
|
|
1643
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
1644
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1645
|
+
raise TypeError("Expected 'np.void' instance")
|
|
1646
|
+
json_object = {}
|
|
1647
|
+
|
|
1648
|
+
json_object["dZ"] = self._d_z_converter.numpy_to_json(value["d_z"])
|
|
1649
|
+
return json_object
|
|
1650
|
+
|
|
1651
|
+
def from_json(self, json_object: object) -> MultibandSpacingType:
|
|
1652
|
+
if not isinstance(json_object, dict):
|
|
1653
|
+
raise TypeError("Expected 'dict' instance")
|
|
1654
|
+
return MultibandSpacingType(
|
|
1655
|
+
d_z=self._d_z_converter.from_json(json_object["dZ"],),
|
|
1656
|
+
)
|
|
1657
|
+
|
|
1658
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
1659
|
+
if not isinstance(json_object, dict):
|
|
1660
|
+
raise TypeError("Expected 'dict' instance")
|
|
1661
|
+
return (
|
|
1662
|
+
self._d_z_converter.from_json_to_numpy(json_object["dZ"]),
|
|
1663
|
+
) # type:ignore
|
|
1664
|
+
|
|
1665
|
+
|
|
1666
|
+
calibration_name_to_value_map = {
|
|
1667
|
+
"separable2D": Calibration.SEPARABLE_2D,
|
|
1668
|
+
"full3D": Calibration.FULL_3D,
|
|
1669
|
+
"other": Calibration.OTHER,
|
|
1670
|
+
}
|
|
1671
|
+
calibration_value_to_name_map = {v: n for n, v in calibration_name_to_value_map.items()}
|
|
1672
|
+
|
|
1673
|
+
class MultibandTypeConverter(_ndjson.JsonConverter[MultibandType, np.void]):
|
|
1674
|
+
def __init__(self) -> None:
|
|
1675
|
+
self._spacing_converter = _ndjson.VectorConverter(MultibandSpacingTypeConverter())
|
|
1676
|
+
self._delta_kz_converter = _ndjson.float32_converter
|
|
1677
|
+
self._multiband_factor_converter = _ndjson.uint32_converter
|
|
1678
|
+
self._calibration_converter = _ndjson.EnumConverter(Calibration, np.int32, calibration_name_to_value_map, calibration_value_to_name_map)
|
|
1679
|
+
self._calibration_encoding_converter = _ndjson.uint64_converter
|
|
1680
|
+
super().__init__(np.dtype([
|
|
1681
|
+
("spacing", self._spacing_converter.overall_dtype()),
|
|
1682
|
+
("delta_kz", self._delta_kz_converter.overall_dtype()),
|
|
1683
|
+
("multiband_factor", self._multiband_factor_converter.overall_dtype()),
|
|
1684
|
+
("calibration", self._calibration_converter.overall_dtype()),
|
|
1685
|
+
("calibration_encoding", self._calibration_encoding_converter.overall_dtype()),
|
|
1686
|
+
]))
|
|
1687
|
+
|
|
1688
|
+
def to_json(self, value: MultibandType) -> object:
|
|
1689
|
+
if not isinstance(value, MultibandType): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1690
|
+
raise TypeError("Expected 'MultibandType' instance")
|
|
1691
|
+
json_object = {}
|
|
1692
|
+
|
|
1693
|
+
json_object["spacing"] = self._spacing_converter.to_json(value.spacing)
|
|
1694
|
+
json_object["deltaKz"] = self._delta_kz_converter.to_json(value.delta_kz)
|
|
1695
|
+
json_object["multibandFactor"] = self._multiband_factor_converter.to_json(value.multiband_factor)
|
|
1696
|
+
json_object["calibration"] = self._calibration_converter.to_json(value.calibration)
|
|
1697
|
+
json_object["calibrationEncoding"] = self._calibration_encoding_converter.to_json(value.calibration_encoding)
|
|
1698
|
+
return json_object
|
|
1699
|
+
|
|
1700
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
1701
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1702
|
+
raise TypeError("Expected 'np.void' instance")
|
|
1703
|
+
json_object = {}
|
|
1704
|
+
|
|
1705
|
+
json_object["spacing"] = self._spacing_converter.numpy_to_json(value["spacing"])
|
|
1706
|
+
json_object["deltaKz"] = self._delta_kz_converter.numpy_to_json(value["delta_kz"])
|
|
1707
|
+
json_object["multibandFactor"] = self._multiband_factor_converter.numpy_to_json(value["multiband_factor"])
|
|
1708
|
+
json_object["calibration"] = self._calibration_converter.numpy_to_json(value["calibration"])
|
|
1709
|
+
json_object["calibrationEncoding"] = self._calibration_encoding_converter.numpy_to_json(value["calibration_encoding"])
|
|
1710
|
+
return json_object
|
|
1711
|
+
|
|
1712
|
+
def from_json(self, json_object: object) -> MultibandType:
|
|
1713
|
+
if not isinstance(json_object, dict):
|
|
1714
|
+
raise TypeError("Expected 'dict' instance")
|
|
1715
|
+
return MultibandType(
|
|
1716
|
+
spacing=self._spacing_converter.from_json(json_object["spacing"],),
|
|
1717
|
+
delta_kz=self._delta_kz_converter.from_json(json_object["deltaKz"],),
|
|
1718
|
+
multiband_factor=self._multiband_factor_converter.from_json(json_object["multibandFactor"],),
|
|
1719
|
+
calibration=self._calibration_converter.from_json(json_object["calibration"],),
|
|
1720
|
+
calibration_encoding=self._calibration_encoding_converter.from_json(json_object["calibrationEncoding"],),
|
|
1721
|
+
)
|
|
1722
|
+
|
|
1723
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
1724
|
+
if not isinstance(json_object, dict):
|
|
1725
|
+
raise TypeError("Expected 'dict' instance")
|
|
1726
|
+
return (
|
|
1727
|
+
self._spacing_converter.from_json_to_numpy(json_object["spacing"]),
|
|
1728
|
+
self._delta_kz_converter.from_json_to_numpy(json_object["deltaKz"]),
|
|
1729
|
+
self._multiband_factor_converter.from_json_to_numpy(json_object["multibandFactor"]),
|
|
1730
|
+
self._calibration_converter.from_json_to_numpy(json_object["calibration"]),
|
|
1731
|
+
self._calibration_encoding_converter.from_json_to_numpy(json_object["calibrationEncoding"]),
|
|
1732
|
+
) # type:ignore
|
|
1733
|
+
|
|
1734
|
+
|
|
1735
|
+
class ParallelImagingTypeConverter(_ndjson.JsonConverter[ParallelImagingType, np.void]):
|
|
1736
|
+
def __init__(self) -> None:
|
|
1737
|
+
self._acceleration_factor_converter = AccelerationFactorTypeConverter()
|
|
1738
|
+
self._calibration_mode_converter = _ndjson.OptionalConverter(_ndjson.EnumConverter(CalibrationMode, np.int32, calibration_mode_name_to_value_map, calibration_mode_value_to_name_map))
|
|
1739
|
+
self._interleaving_dimension_converter = _ndjson.OptionalConverter(_ndjson.EnumConverter(InterleavingDimension, np.int32, interleaving_dimension_name_to_value_map, interleaving_dimension_value_to_name_map))
|
|
1740
|
+
self._multiband_converter = _ndjson.OptionalConverter(MultibandTypeConverter())
|
|
1741
|
+
super().__init__(np.dtype([
|
|
1742
|
+
("acceleration_factor", self._acceleration_factor_converter.overall_dtype()),
|
|
1743
|
+
("calibration_mode", self._calibration_mode_converter.overall_dtype()),
|
|
1744
|
+
("interleaving_dimension", self._interleaving_dimension_converter.overall_dtype()),
|
|
1745
|
+
("multiband", self._multiband_converter.overall_dtype()),
|
|
1746
|
+
]))
|
|
1747
|
+
|
|
1748
|
+
def to_json(self, value: ParallelImagingType) -> object:
|
|
1749
|
+
if not isinstance(value, ParallelImagingType): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1750
|
+
raise TypeError("Expected 'ParallelImagingType' instance")
|
|
1751
|
+
json_object = {}
|
|
1752
|
+
|
|
1753
|
+
json_object["accelerationFactor"] = self._acceleration_factor_converter.to_json(value.acceleration_factor)
|
|
1754
|
+
if value.calibration_mode is not None:
|
|
1755
|
+
json_object["calibrationMode"] = self._calibration_mode_converter.to_json(value.calibration_mode)
|
|
1756
|
+
if value.interleaving_dimension is not None:
|
|
1757
|
+
json_object["interleavingDimension"] = self._interleaving_dimension_converter.to_json(value.interleaving_dimension)
|
|
1758
|
+
if value.multiband is not None:
|
|
1759
|
+
json_object["multiband"] = self._multiband_converter.to_json(value.multiband)
|
|
1760
|
+
return json_object
|
|
1761
|
+
|
|
1762
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
1763
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1764
|
+
raise TypeError("Expected 'np.void' instance")
|
|
1765
|
+
json_object = {}
|
|
1766
|
+
|
|
1767
|
+
json_object["accelerationFactor"] = self._acceleration_factor_converter.numpy_to_json(value["acceleration_factor"])
|
|
1768
|
+
if (field_val := value["calibration_mode"]) is not None:
|
|
1769
|
+
json_object["calibrationMode"] = self._calibration_mode_converter.numpy_to_json(field_val)
|
|
1770
|
+
if (field_val := value["interleaving_dimension"]) is not None:
|
|
1771
|
+
json_object["interleavingDimension"] = self._interleaving_dimension_converter.numpy_to_json(field_val)
|
|
1772
|
+
if (field_val := value["multiband"]) is not None:
|
|
1773
|
+
json_object["multiband"] = self._multiband_converter.numpy_to_json(field_val)
|
|
1774
|
+
return json_object
|
|
1775
|
+
|
|
1776
|
+
def from_json(self, json_object: object) -> ParallelImagingType:
|
|
1777
|
+
if not isinstance(json_object, dict):
|
|
1778
|
+
raise TypeError("Expected 'dict' instance")
|
|
1779
|
+
return ParallelImagingType(
|
|
1780
|
+
acceleration_factor=self._acceleration_factor_converter.from_json(json_object["accelerationFactor"],),
|
|
1781
|
+
calibration_mode=self._calibration_mode_converter.from_json(json_object.get("calibrationMode")),
|
|
1782
|
+
interleaving_dimension=self._interleaving_dimension_converter.from_json(json_object.get("interleavingDimension")),
|
|
1783
|
+
multiband=self._multiband_converter.from_json(json_object.get("multiband")),
|
|
1784
|
+
)
|
|
1785
|
+
|
|
1786
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
1787
|
+
if not isinstance(json_object, dict):
|
|
1788
|
+
raise TypeError("Expected 'dict' instance")
|
|
1789
|
+
return (
|
|
1790
|
+
self._acceleration_factor_converter.from_json_to_numpy(json_object["accelerationFactor"]),
|
|
1791
|
+
self._calibration_mode_converter.from_json_to_numpy(json_object.get("calibrationMode")),
|
|
1792
|
+
self._interleaving_dimension_converter.from_json_to_numpy(json_object.get("interleavingDimension")),
|
|
1793
|
+
self._multiband_converter.from_json_to_numpy(json_object.get("multiband")),
|
|
1794
|
+
) # type:ignore
|
|
1795
|
+
|
|
1796
|
+
|
|
1797
|
+
class EncodingTypeConverter(_ndjson.JsonConverter[EncodingType, np.void]):
|
|
1798
|
+
def __init__(self) -> None:
|
|
1799
|
+
self._encoded_space_converter = EncodingSpaceTypeConverter()
|
|
1800
|
+
self._recon_space_converter = EncodingSpaceTypeConverter()
|
|
1801
|
+
self._encoding_limits_converter = EncodingLimitsTypeConverter()
|
|
1802
|
+
self._trajectory_converter = _ndjson.EnumConverter(Trajectory, np.int32, trajectory_name_to_value_map, trajectory_value_to_name_map)
|
|
1803
|
+
self._trajectory_description_converter = _ndjson.OptionalConverter(TrajectoryDescriptionTypeConverter())
|
|
1804
|
+
self._parallel_imaging_converter = _ndjson.OptionalConverter(ParallelImagingTypeConverter())
|
|
1805
|
+
self._echo_train_length_converter = _ndjson.OptionalConverter(_ndjson.int64_converter)
|
|
1806
|
+
super().__init__(np.dtype([
|
|
1807
|
+
("encoded_space", self._encoded_space_converter.overall_dtype()),
|
|
1808
|
+
("recon_space", self._recon_space_converter.overall_dtype()),
|
|
1809
|
+
("encoding_limits", self._encoding_limits_converter.overall_dtype()),
|
|
1810
|
+
("trajectory", self._trajectory_converter.overall_dtype()),
|
|
1811
|
+
("trajectory_description", self._trajectory_description_converter.overall_dtype()),
|
|
1812
|
+
("parallel_imaging", self._parallel_imaging_converter.overall_dtype()),
|
|
1813
|
+
("echo_train_length", self._echo_train_length_converter.overall_dtype()),
|
|
1814
|
+
]))
|
|
1815
|
+
|
|
1816
|
+
def to_json(self, value: EncodingType) -> object:
|
|
1817
|
+
if not isinstance(value, EncodingType): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1818
|
+
raise TypeError("Expected 'EncodingType' instance")
|
|
1819
|
+
json_object = {}
|
|
1820
|
+
|
|
1821
|
+
json_object["encodedSpace"] = self._encoded_space_converter.to_json(value.encoded_space)
|
|
1822
|
+
json_object["reconSpace"] = self._recon_space_converter.to_json(value.recon_space)
|
|
1823
|
+
json_object["encodingLimits"] = self._encoding_limits_converter.to_json(value.encoding_limits)
|
|
1824
|
+
json_object["trajectory"] = self._trajectory_converter.to_json(value.trajectory)
|
|
1825
|
+
if value.trajectory_description is not None:
|
|
1826
|
+
json_object["trajectoryDescription"] = self._trajectory_description_converter.to_json(value.trajectory_description)
|
|
1827
|
+
if value.parallel_imaging is not None:
|
|
1828
|
+
json_object["parallelImaging"] = self._parallel_imaging_converter.to_json(value.parallel_imaging)
|
|
1829
|
+
if value.echo_train_length is not None:
|
|
1830
|
+
json_object["echoTrainLength"] = self._echo_train_length_converter.to_json(value.echo_train_length)
|
|
1831
|
+
return json_object
|
|
1832
|
+
|
|
1833
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
1834
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1835
|
+
raise TypeError("Expected 'np.void' instance")
|
|
1836
|
+
json_object = {}
|
|
1837
|
+
|
|
1838
|
+
json_object["encodedSpace"] = self._encoded_space_converter.numpy_to_json(value["encoded_space"])
|
|
1839
|
+
json_object["reconSpace"] = self._recon_space_converter.numpy_to_json(value["recon_space"])
|
|
1840
|
+
json_object["encodingLimits"] = self._encoding_limits_converter.numpy_to_json(value["encoding_limits"])
|
|
1841
|
+
json_object["trajectory"] = self._trajectory_converter.numpy_to_json(value["trajectory"])
|
|
1842
|
+
if (field_val := value["trajectory_description"]) is not None:
|
|
1843
|
+
json_object["trajectoryDescription"] = self._trajectory_description_converter.numpy_to_json(field_val)
|
|
1844
|
+
if (field_val := value["parallel_imaging"]) is not None:
|
|
1845
|
+
json_object["parallelImaging"] = self._parallel_imaging_converter.numpy_to_json(field_val)
|
|
1846
|
+
if (field_val := value["echo_train_length"]) is not None:
|
|
1847
|
+
json_object["echoTrainLength"] = self._echo_train_length_converter.numpy_to_json(field_val)
|
|
1848
|
+
return json_object
|
|
1849
|
+
|
|
1850
|
+
def from_json(self, json_object: object) -> EncodingType:
|
|
1851
|
+
if not isinstance(json_object, dict):
|
|
1852
|
+
raise TypeError("Expected 'dict' instance")
|
|
1853
|
+
return EncodingType(
|
|
1854
|
+
encoded_space=self._encoded_space_converter.from_json(json_object["encodedSpace"],),
|
|
1855
|
+
recon_space=self._recon_space_converter.from_json(json_object["reconSpace"],),
|
|
1856
|
+
encoding_limits=self._encoding_limits_converter.from_json(json_object["encodingLimits"],),
|
|
1857
|
+
trajectory=self._trajectory_converter.from_json(json_object["trajectory"],),
|
|
1858
|
+
trajectory_description=self._trajectory_description_converter.from_json(json_object.get("trajectoryDescription")),
|
|
1859
|
+
parallel_imaging=self._parallel_imaging_converter.from_json(json_object.get("parallelImaging")),
|
|
1860
|
+
echo_train_length=self._echo_train_length_converter.from_json(json_object.get("echoTrainLength")),
|
|
1861
|
+
)
|
|
1862
|
+
|
|
1863
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
1864
|
+
if not isinstance(json_object, dict):
|
|
1865
|
+
raise TypeError("Expected 'dict' instance")
|
|
1866
|
+
return (
|
|
1867
|
+
self._encoded_space_converter.from_json_to_numpy(json_object["encodedSpace"]),
|
|
1868
|
+
self._recon_space_converter.from_json_to_numpy(json_object["reconSpace"]),
|
|
1869
|
+
self._encoding_limits_converter.from_json_to_numpy(json_object["encodingLimits"]),
|
|
1870
|
+
self._trajectory_converter.from_json_to_numpy(json_object["trajectory"]),
|
|
1871
|
+
self._trajectory_description_converter.from_json_to_numpy(json_object.get("trajectoryDescription")),
|
|
1872
|
+
self._parallel_imaging_converter.from_json_to_numpy(json_object.get("parallelImaging")),
|
|
1873
|
+
self._echo_train_length_converter.from_json_to_numpy(json_object.get("echoTrainLength")),
|
|
1874
|
+
) # type:ignore
|
|
1875
|
+
|
|
1876
|
+
|
|
1877
|
+
diffusion_dimension_name_to_value_map = {
|
|
1878
|
+
"average": DiffusionDimension.AVERAGE,
|
|
1879
|
+
"contrast": DiffusionDimension.CONTRAST,
|
|
1880
|
+
"phase": DiffusionDimension.PHASE,
|
|
1881
|
+
"repetition": DiffusionDimension.REPETITION,
|
|
1882
|
+
"set": DiffusionDimension.SET,
|
|
1883
|
+
"segment": DiffusionDimension.SEGMENT,
|
|
1884
|
+
"user0": DiffusionDimension.USER_0,
|
|
1885
|
+
"user1": DiffusionDimension.USER_1,
|
|
1886
|
+
"user2": DiffusionDimension.USER_2,
|
|
1887
|
+
"user3": DiffusionDimension.USER_3,
|
|
1888
|
+
"user4": DiffusionDimension.USER_4,
|
|
1889
|
+
"user5": DiffusionDimension.USER_5,
|
|
1890
|
+
"user6": DiffusionDimension.USER_6,
|
|
1891
|
+
"user7": DiffusionDimension.USER_7,
|
|
1892
|
+
}
|
|
1893
|
+
diffusion_dimension_value_to_name_map = {v: n for n, v in diffusion_dimension_name_to_value_map.items()}
|
|
1894
|
+
|
|
1895
|
+
class GradientDirectionTypeConverter(_ndjson.JsonConverter[GradientDirectionType, np.void]):
|
|
1896
|
+
def __init__(self) -> None:
|
|
1897
|
+
self._rl_converter = _ndjson.float32_converter
|
|
1898
|
+
self._ap_converter = _ndjson.float32_converter
|
|
1899
|
+
self._fh_converter = _ndjson.float32_converter
|
|
1900
|
+
super().__init__(np.dtype([
|
|
1901
|
+
("rl", self._rl_converter.overall_dtype()),
|
|
1902
|
+
("ap", self._ap_converter.overall_dtype()),
|
|
1903
|
+
("fh", self._fh_converter.overall_dtype()),
|
|
1904
|
+
]))
|
|
1905
|
+
|
|
1906
|
+
def to_json(self, value: GradientDirectionType) -> object:
|
|
1907
|
+
if not isinstance(value, GradientDirectionType): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1908
|
+
raise TypeError("Expected 'GradientDirectionType' instance")
|
|
1909
|
+
json_object = {}
|
|
1910
|
+
|
|
1911
|
+
json_object["rl"] = self._rl_converter.to_json(value.rl)
|
|
1912
|
+
json_object["ap"] = self._ap_converter.to_json(value.ap)
|
|
1913
|
+
json_object["fh"] = self._fh_converter.to_json(value.fh)
|
|
1914
|
+
return json_object
|
|
1915
|
+
|
|
1916
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
1917
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1918
|
+
raise TypeError("Expected 'np.void' instance")
|
|
1919
|
+
json_object = {}
|
|
1920
|
+
|
|
1921
|
+
json_object["rl"] = self._rl_converter.numpy_to_json(value["rl"])
|
|
1922
|
+
json_object["ap"] = self._ap_converter.numpy_to_json(value["ap"])
|
|
1923
|
+
json_object["fh"] = self._fh_converter.numpy_to_json(value["fh"])
|
|
1924
|
+
return json_object
|
|
1925
|
+
|
|
1926
|
+
def from_json(self, json_object: object) -> GradientDirectionType:
|
|
1927
|
+
if not isinstance(json_object, dict):
|
|
1928
|
+
raise TypeError("Expected 'dict' instance")
|
|
1929
|
+
return GradientDirectionType(
|
|
1930
|
+
rl=self._rl_converter.from_json(json_object["rl"],),
|
|
1931
|
+
ap=self._ap_converter.from_json(json_object["ap"],),
|
|
1932
|
+
fh=self._fh_converter.from_json(json_object["fh"],),
|
|
1933
|
+
)
|
|
1934
|
+
|
|
1935
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
1936
|
+
if not isinstance(json_object, dict):
|
|
1937
|
+
raise TypeError("Expected 'dict' instance")
|
|
1938
|
+
return (
|
|
1939
|
+
self._rl_converter.from_json_to_numpy(json_object["rl"]),
|
|
1940
|
+
self._ap_converter.from_json_to_numpy(json_object["ap"]),
|
|
1941
|
+
self._fh_converter.from_json_to_numpy(json_object["fh"]),
|
|
1942
|
+
) # type:ignore
|
|
1943
|
+
|
|
1944
|
+
|
|
1945
|
+
class DiffusionTypeConverter(_ndjson.JsonConverter[DiffusionType, np.void]):
|
|
1946
|
+
def __init__(self) -> None:
|
|
1947
|
+
self._gradient_direction_converter = GradientDirectionTypeConverter()
|
|
1948
|
+
self._bvalue_converter = _ndjson.float32_converter
|
|
1949
|
+
super().__init__(np.dtype([
|
|
1950
|
+
("gradient_direction", self._gradient_direction_converter.overall_dtype()),
|
|
1951
|
+
("bvalue", self._bvalue_converter.overall_dtype()),
|
|
1952
|
+
]))
|
|
1953
|
+
|
|
1954
|
+
def to_json(self, value: DiffusionType) -> object:
|
|
1955
|
+
if not isinstance(value, DiffusionType): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1956
|
+
raise TypeError("Expected 'DiffusionType' instance")
|
|
1957
|
+
json_object = {}
|
|
1958
|
+
|
|
1959
|
+
json_object["gradientDirection"] = self._gradient_direction_converter.to_json(value.gradient_direction)
|
|
1960
|
+
json_object["bvalue"] = self._bvalue_converter.to_json(value.bvalue)
|
|
1961
|
+
return json_object
|
|
1962
|
+
|
|
1963
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
1964
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
1965
|
+
raise TypeError("Expected 'np.void' instance")
|
|
1966
|
+
json_object = {}
|
|
1967
|
+
|
|
1968
|
+
json_object["gradientDirection"] = self._gradient_direction_converter.numpy_to_json(value["gradient_direction"])
|
|
1969
|
+
json_object["bvalue"] = self._bvalue_converter.numpy_to_json(value["bvalue"])
|
|
1970
|
+
return json_object
|
|
1971
|
+
|
|
1972
|
+
def from_json(self, json_object: object) -> DiffusionType:
|
|
1973
|
+
if not isinstance(json_object, dict):
|
|
1974
|
+
raise TypeError("Expected 'dict' instance")
|
|
1975
|
+
return DiffusionType(
|
|
1976
|
+
gradient_direction=self._gradient_direction_converter.from_json(json_object["gradientDirection"],),
|
|
1977
|
+
bvalue=self._bvalue_converter.from_json(json_object["bvalue"],),
|
|
1978
|
+
)
|
|
1979
|
+
|
|
1980
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
1981
|
+
if not isinstance(json_object, dict):
|
|
1982
|
+
raise TypeError("Expected 'dict' instance")
|
|
1983
|
+
return (
|
|
1984
|
+
self._gradient_direction_converter.from_json_to_numpy(json_object["gradientDirection"]),
|
|
1985
|
+
self._bvalue_converter.from_json_to_numpy(json_object["bvalue"]),
|
|
1986
|
+
) # type:ignore
|
|
1987
|
+
|
|
1988
|
+
|
|
1989
|
+
class SequenceParametersTypeConverter(_ndjson.JsonConverter[SequenceParametersType, np.void]):
|
|
1990
|
+
def __init__(self) -> None:
|
|
1991
|
+
self._t_r_converter = _ndjson.VectorConverter(_ndjson.float32_converter)
|
|
1992
|
+
self._t_e_converter = _ndjson.VectorConverter(_ndjson.float32_converter)
|
|
1993
|
+
self._t_i_converter = _ndjson.VectorConverter(_ndjson.float32_converter)
|
|
1994
|
+
self._flip_angle_deg_converter = _ndjson.VectorConverter(_ndjson.float32_converter)
|
|
1995
|
+
self._sequence_type_converter = _ndjson.OptionalConverter(_ndjson.string_converter)
|
|
1996
|
+
self._echo_spacing_converter = _ndjson.VectorConverter(_ndjson.float32_converter)
|
|
1997
|
+
self._diffusion_dimension_converter = _ndjson.OptionalConverter(_ndjson.EnumConverter(DiffusionDimension, np.int32, diffusion_dimension_name_to_value_map, diffusion_dimension_value_to_name_map))
|
|
1998
|
+
self._diffusion_converter = _ndjson.VectorConverter(DiffusionTypeConverter())
|
|
1999
|
+
self._diffusion_scheme_converter = _ndjson.OptionalConverter(_ndjson.string_converter)
|
|
2000
|
+
super().__init__(np.dtype([
|
|
2001
|
+
("t_r", self._t_r_converter.overall_dtype()),
|
|
2002
|
+
("t_e", self._t_e_converter.overall_dtype()),
|
|
2003
|
+
("t_i", self._t_i_converter.overall_dtype()),
|
|
2004
|
+
("flip_angle_deg", self._flip_angle_deg_converter.overall_dtype()),
|
|
2005
|
+
("sequence_type", self._sequence_type_converter.overall_dtype()),
|
|
2006
|
+
("echo_spacing", self._echo_spacing_converter.overall_dtype()),
|
|
2007
|
+
("diffusion_dimension", self._diffusion_dimension_converter.overall_dtype()),
|
|
2008
|
+
("diffusion", self._diffusion_converter.overall_dtype()),
|
|
2009
|
+
("diffusion_scheme", self._diffusion_scheme_converter.overall_dtype()),
|
|
2010
|
+
]))
|
|
2011
|
+
|
|
2012
|
+
def to_json(self, value: SequenceParametersType) -> object:
|
|
2013
|
+
if not isinstance(value, SequenceParametersType): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
2014
|
+
raise TypeError("Expected 'SequenceParametersType' instance")
|
|
2015
|
+
json_object = {}
|
|
2016
|
+
|
|
2017
|
+
json_object["tR"] = self._t_r_converter.to_json(value.t_r)
|
|
2018
|
+
json_object["tE"] = self._t_e_converter.to_json(value.t_e)
|
|
2019
|
+
json_object["tI"] = self._t_i_converter.to_json(value.t_i)
|
|
2020
|
+
json_object["flipAngleDeg"] = self._flip_angle_deg_converter.to_json(value.flip_angle_deg)
|
|
2021
|
+
if value.sequence_type is not None:
|
|
2022
|
+
json_object["sequenceType"] = self._sequence_type_converter.to_json(value.sequence_type)
|
|
2023
|
+
json_object["echoSpacing"] = self._echo_spacing_converter.to_json(value.echo_spacing)
|
|
2024
|
+
if value.diffusion_dimension is not None:
|
|
2025
|
+
json_object["diffusionDimension"] = self._diffusion_dimension_converter.to_json(value.diffusion_dimension)
|
|
2026
|
+
json_object["diffusion"] = self._diffusion_converter.to_json(value.diffusion)
|
|
2027
|
+
if value.diffusion_scheme is not None:
|
|
2028
|
+
json_object["diffusionScheme"] = self._diffusion_scheme_converter.to_json(value.diffusion_scheme)
|
|
2029
|
+
return json_object
|
|
2030
|
+
|
|
2031
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
2032
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
2033
|
+
raise TypeError("Expected 'np.void' instance")
|
|
2034
|
+
json_object = {}
|
|
2035
|
+
|
|
2036
|
+
json_object["tR"] = self._t_r_converter.numpy_to_json(value["t_r"])
|
|
2037
|
+
json_object["tE"] = self._t_e_converter.numpy_to_json(value["t_e"])
|
|
2038
|
+
json_object["tI"] = self._t_i_converter.numpy_to_json(value["t_i"])
|
|
2039
|
+
json_object["flipAngleDeg"] = self._flip_angle_deg_converter.numpy_to_json(value["flip_angle_deg"])
|
|
2040
|
+
if (field_val := value["sequence_type"]) is not None:
|
|
2041
|
+
json_object["sequenceType"] = self._sequence_type_converter.numpy_to_json(field_val)
|
|
2042
|
+
json_object["echoSpacing"] = self._echo_spacing_converter.numpy_to_json(value["echo_spacing"])
|
|
2043
|
+
if (field_val := value["diffusion_dimension"]) is not None:
|
|
2044
|
+
json_object["diffusionDimension"] = self._diffusion_dimension_converter.numpy_to_json(field_val)
|
|
2045
|
+
json_object["diffusion"] = self._diffusion_converter.numpy_to_json(value["diffusion"])
|
|
2046
|
+
if (field_val := value["diffusion_scheme"]) is not None:
|
|
2047
|
+
json_object["diffusionScheme"] = self._diffusion_scheme_converter.numpy_to_json(field_val)
|
|
2048
|
+
return json_object
|
|
2049
|
+
|
|
2050
|
+
def from_json(self, json_object: object) -> SequenceParametersType:
|
|
2051
|
+
if not isinstance(json_object, dict):
|
|
2052
|
+
raise TypeError("Expected 'dict' instance")
|
|
2053
|
+
return SequenceParametersType(
|
|
2054
|
+
t_r=self._t_r_converter.from_json(json_object["tR"],),
|
|
2055
|
+
t_e=self._t_e_converter.from_json(json_object["tE"],),
|
|
2056
|
+
t_i=self._t_i_converter.from_json(json_object["tI"],),
|
|
2057
|
+
flip_angle_deg=self._flip_angle_deg_converter.from_json(json_object["flipAngleDeg"],),
|
|
2058
|
+
sequence_type=self._sequence_type_converter.from_json(json_object.get("sequenceType")),
|
|
2059
|
+
echo_spacing=self._echo_spacing_converter.from_json(json_object["echoSpacing"],),
|
|
2060
|
+
diffusion_dimension=self._diffusion_dimension_converter.from_json(json_object.get("diffusionDimension")),
|
|
2061
|
+
diffusion=self._diffusion_converter.from_json(json_object["diffusion"],),
|
|
2062
|
+
diffusion_scheme=self._diffusion_scheme_converter.from_json(json_object.get("diffusionScheme")),
|
|
2063
|
+
)
|
|
2064
|
+
|
|
2065
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
2066
|
+
if not isinstance(json_object, dict):
|
|
2067
|
+
raise TypeError("Expected 'dict' instance")
|
|
2068
|
+
return (
|
|
2069
|
+
self._t_r_converter.from_json_to_numpy(json_object["tR"]),
|
|
2070
|
+
self._t_e_converter.from_json_to_numpy(json_object["tE"]),
|
|
2071
|
+
self._t_i_converter.from_json_to_numpy(json_object["tI"]),
|
|
2072
|
+
self._flip_angle_deg_converter.from_json_to_numpy(json_object["flipAngleDeg"]),
|
|
2073
|
+
self._sequence_type_converter.from_json_to_numpy(json_object.get("sequenceType")),
|
|
2074
|
+
self._echo_spacing_converter.from_json_to_numpy(json_object["echoSpacing"]),
|
|
2075
|
+
self._diffusion_dimension_converter.from_json_to_numpy(json_object.get("diffusionDimension")),
|
|
2076
|
+
self._diffusion_converter.from_json_to_numpy(json_object["diffusion"]),
|
|
2077
|
+
self._diffusion_scheme_converter.from_json_to_numpy(json_object.get("diffusionScheme")),
|
|
2078
|
+
) # type:ignore
|
|
2079
|
+
|
|
2080
|
+
|
|
2081
|
+
class UserParameterBase64TypeConverter(_ndjson.JsonConverter[UserParameterBase64Type, np.void]):
|
|
2082
|
+
def __init__(self) -> None:
|
|
2083
|
+
self._name_converter = _ndjson.string_converter
|
|
2084
|
+
self._value_converter = _ndjson.string_converter
|
|
2085
|
+
super().__init__(np.dtype([
|
|
2086
|
+
("name", self._name_converter.overall_dtype()),
|
|
2087
|
+
("value", self._value_converter.overall_dtype()),
|
|
2088
|
+
]))
|
|
2089
|
+
|
|
2090
|
+
def to_json(self, value: UserParameterBase64Type) -> object:
|
|
2091
|
+
if not isinstance(value, UserParameterBase64Type): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
2092
|
+
raise TypeError("Expected 'UserParameterBase64Type' instance")
|
|
2093
|
+
json_object = {}
|
|
2094
|
+
|
|
2095
|
+
json_object["name"] = self._name_converter.to_json(value.name)
|
|
2096
|
+
json_object["value"] = self._value_converter.to_json(value.value)
|
|
2097
|
+
return json_object
|
|
2098
|
+
|
|
2099
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
2100
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
2101
|
+
raise TypeError("Expected 'np.void' instance")
|
|
2102
|
+
json_object = {}
|
|
2103
|
+
|
|
2104
|
+
json_object["name"] = self._name_converter.numpy_to_json(value["name"])
|
|
2105
|
+
json_object["value"] = self._value_converter.numpy_to_json(value["value"])
|
|
2106
|
+
return json_object
|
|
2107
|
+
|
|
2108
|
+
def from_json(self, json_object: object) -> UserParameterBase64Type:
|
|
2109
|
+
if not isinstance(json_object, dict):
|
|
2110
|
+
raise TypeError("Expected 'dict' instance")
|
|
2111
|
+
return UserParameterBase64Type(
|
|
2112
|
+
name=self._name_converter.from_json(json_object["name"],),
|
|
2113
|
+
value=self._value_converter.from_json(json_object["value"],),
|
|
2114
|
+
)
|
|
2115
|
+
|
|
2116
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
2117
|
+
if not isinstance(json_object, dict):
|
|
2118
|
+
raise TypeError("Expected 'dict' instance")
|
|
2119
|
+
return (
|
|
2120
|
+
self._name_converter.from_json_to_numpy(json_object["name"]),
|
|
2121
|
+
self._value_converter.from_json_to_numpy(json_object["value"]),
|
|
2122
|
+
) # type:ignore
|
|
2123
|
+
|
|
2124
|
+
|
|
2125
|
+
class UserParametersTypeConverter(_ndjson.JsonConverter[UserParametersType, np.void]):
|
|
2126
|
+
def __init__(self) -> None:
|
|
2127
|
+
self._user_parameter_long_converter = _ndjson.VectorConverter(UserParameterLongTypeConverter())
|
|
2128
|
+
self._user_parameter_double_converter = _ndjson.VectorConverter(UserParameterDoubleTypeConverter())
|
|
2129
|
+
self._user_parameter_string_converter = _ndjson.VectorConverter(UserParameterStringTypeConverter())
|
|
2130
|
+
self._user_parameter_base64_converter = _ndjson.VectorConverter(UserParameterBase64TypeConverter())
|
|
2131
|
+
super().__init__(np.dtype([
|
|
2132
|
+
("user_parameter_long", self._user_parameter_long_converter.overall_dtype()),
|
|
2133
|
+
("user_parameter_double", self._user_parameter_double_converter.overall_dtype()),
|
|
2134
|
+
("user_parameter_string", self._user_parameter_string_converter.overall_dtype()),
|
|
2135
|
+
("user_parameter_base64", self._user_parameter_base64_converter.overall_dtype()),
|
|
2136
|
+
]))
|
|
2137
|
+
|
|
2138
|
+
def to_json(self, value: UserParametersType) -> object:
|
|
2139
|
+
if not isinstance(value, UserParametersType): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
2140
|
+
raise TypeError("Expected 'UserParametersType' instance")
|
|
2141
|
+
json_object = {}
|
|
2142
|
+
|
|
2143
|
+
json_object["userParameterLong"] = self._user_parameter_long_converter.to_json(value.user_parameter_long)
|
|
2144
|
+
json_object["userParameterDouble"] = self._user_parameter_double_converter.to_json(value.user_parameter_double)
|
|
2145
|
+
json_object["userParameterString"] = self._user_parameter_string_converter.to_json(value.user_parameter_string)
|
|
2146
|
+
json_object["userParameterBase64"] = self._user_parameter_base64_converter.to_json(value.user_parameter_base64)
|
|
2147
|
+
return json_object
|
|
2148
|
+
|
|
2149
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
2150
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
2151
|
+
raise TypeError("Expected 'np.void' instance")
|
|
2152
|
+
json_object = {}
|
|
2153
|
+
|
|
2154
|
+
json_object["userParameterLong"] = self._user_parameter_long_converter.numpy_to_json(value["user_parameter_long"])
|
|
2155
|
+
json_object["userParameterDouble"] = self._user_parameter_double_converter.numpy_to_json(value["user_parameter_double"])
|
|
2156
|
+
json_object["userParameterString"] = self._user_parameter_string_converter.numpy_to_json(value["user_parameter_string"])
|
|
2157
|
+
json_object["userParameterBase64"] = self._user_parameter_base64_converter.numpy_to_json(value["user_parameter_base64"])
|
|
2158
|
+
return json_object
|
|
2159
|
+
|
|
2160
|
+
def from_json(self, json_object: object) -> UserParametersType:
|
|
2161
|
+
if not isinstance(json_object, dict):
|
|
2162
|
+
raise TypeError("Expected 'dict' instance")
|
|
2163
|
+
return UserParametersType(
|
|
2164
|
+
user_parameter_long=self._user_parameter_long_converter.from_json(json_object["userParameterLong"],),
|
|
2165
|
+
user_parameter_double=self._user_parameter_double_converter.from_json(json_object["userParameterDouble"],),
|
|
2166
|
+
user_parameter_string=self._user_parameter_string_converter.from_json(json_object["userParameterString"],),
|
|
2167
|
+
user_parameter_base64=self._user_parameter_base64_converter.from_json(json_object["userParameterBase64"],),
|
|
2168
|
+
)
|
|
2169
|
+
|
|
2170
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
2171
|
+
if not isinstance(json_object, dict):
|
|
2172
|
+
raise TypeError("Expected 'dict' instance")
|
|
2173
|
+
return (
|
|
2174
|
+
self._user_parameter_long_converter.from_json_to_numpy(json_object["userParameterLong"]),
|
|
2175
|
+
self._user_parameter_double_converter.from_json_to_numpy(json_object["userParameterDouble"]),
|
|
2176
|
+
self._user_parameter_string_converter.from_json_to_numpy(json_object["userParameterString"]),
|
|
2177
|
+
self._user_parameter_base64_converter.from_json_to_numpy(json_object["userParameterBase64"]),
|
|
2178
|
+
) # type:ignore
|
|
2179
|
+
|
|
2180
|
+
|
|
2181
|
+
waveform_type_name_to_value_map = {
|
|
2182
|
+
"ecg": WaveformType.ECG,
|
|
2183
|
+
"pulse": WaveformType.PULSE,
|
|
2184
|
+
"respiratory": WaveformType.RESPIRATORY,
|
|
2185
|
+
"trigger": WaveformType.TRIGGER,
|
|
2186
|
+
"gradientwaveform": WaveformType.GRADIENTWAVEFORM,
|
|
2187
|
+
"other": WaveformType.OTHER,
|
|
2188
|
+
}
|
|
2189
|
+
waveform_type_value_to_name_map = {v: n for n, v in waveform_type_name_to_value_map.items()}
|
|
2190
|
+
|
|
2191
|
+
class WaveformInformationTypeConverter(_ndjson.JsonConverter[WaveformInformationType, np.void]):
|
|
2192
|
+
def __init__(self) -> None:
|
|
2193
|
+
self._waveform_name_converter = _ndjson.string_converter
|
|
2194
|
+
self._waveform_type_converter = _ndjson.EnumConverter(WaveformType, np.int32, waveform_type_name_to_value_map, waveform_type_value_to_name_map)
|
|
2195
|
+
self._user_parameters_converter = UserParametersTypeConverter()
|
|
2196
|
+
super().__init__(np.dtype([
|
|
2197
|
+
("waveform_name", self._waveform_name_converter.overall_dtype()),
|
|
2198
|
+
("waveform_type", self._waveform_type_converter.overall_dtype()),
|
|
2199
|
+
("user_parameters", self._user_parameters_converter.overall_dtype()),
|
|
2200
|
+
]))
|
|
2201
|
+
|
|
2202
|
+
def to_json(self, value: WaveformInformationType) -> object:
|
|
2203
|
+
if not isinstance(value, WaveformInformationType): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
2204
|
+
raise TypeError("Expected 'WaveformInformationType' instance")
|
|
2205
|
+
json_object = {}
|
|
2206
|
+
|
|
2207
|
+
json_object["waveformName"] = self._waveform_name_converter.to_json(value.waveform_name)
|
|
2208
|
+
json_object["waveformType"] = self._waveform_type_converter.to_json(value.waveform_type)
|
|
2209
|
+
json_object["userParameters"] = self._user_parameters_converter.to_json(value.user_parameters)
|
|
2210
|
+
return json_object
|
|
2211
|
+
|
|
2212
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
2213
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
2214
|
+
raise TypeError("Expected 'np.void' instance")
|
|
2215
|
+
json_object = {}
|
|
2216
|
+
|
|
2217
|
+
json_object["waveformName"] = self._waveform_name_converter.numpy_to_json(value["waveform_name"])
|
|
2218
|
+
json_object["waveformType"] = self._waveform_type_converter.numpy_to_json(value["waveform_type"])
|
|
2219
|
+
json_object["userParameters"] = self._user_parameters_converter.numpy_to_json(value["user_parameters"])
|
|
2220
|
+
return json_object
|
|
2221
|
+
|
|
2222
|
+
def from_json(self, json_object: object) -> WaveformInformationType:
|
|
2223
|
+
if not isinstance(json_object, dict):
|
|
2224
|
+
raise TypeError("Expected 'dict' instance")
|
|
2225
|
+
return WaveformInformationType(
|
|
2226
|
+
waveform_name=self._waveform_name_converter.from_json(json_object["waveformName"],),
|
|
2227
|
+
waveform_type=self._waveform_type_converter.from_json(json_object["waveformType"],),
|
|
2228
|
+
user_parameters=self._user_parameters_converter.from_json(json_object["userParameters"],),
|
|
2229
|
+
)
|
|
2230
|
+
|
|
2231
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
2232
|
+
if not isinstance(json_object, dict):
|
|
2233
|
+
raise TypeError("Expected 'dict' instance")
|
|
2234
|
+
return (
|
|
2235
|
+
self._waveform_name_converter.from_json_to_numpy(json_object["waveformName"]),
|
|
2236
|
+
self._waveform_type_converter.from_json_to_numpy(json_object["waveformType"]),
|
|
2237
|
+
self._user_parameters_converter.from_json_to_numpy(json_object["userParameters"]),
|
|
2238
|
+
) # type:ignore
|
|
2239
|
+
|
|
2240
|
+
|
|
2241
|
+
class HeaderConverter(_ndjson.JsonConverter[Header, np.void]):
|
|
2242
|
+
def __init__(self) -> None:
|
|
2243
|
+
self._version_converter = _ndjson.OptionalConverter(_ndjson.int64_converter)
|
|
2244
|
+
self._subject_information_converter = _ndjson.OptionalConverter(SubjectInformationTypeConverter())
|
|
2245
|
+
self._study_information_converter = _ndjson.OptionalConverter(StudyInformationTypeConverter())
|
|
2246
|
+
self._measurement_information_converter = _ndjson.OptionalConverter(MeasurementInformationTypeConverter())
|
|
2247
|
+
self._acquisition_system_information_converter = _ndjson.OptionalConverter(AcquisitionSystemInformationTypeConverter())
|
|
2248
|
+
self._experimental_conditions_converter = ExperimentalConditionsTypeConverter()
|
|
2249
|
+
self._encoding_converter = _ndjson.VectorConverter(EncodingTypeConverter())
|
|
2250
|
+
self._sequence_parameters_converter = _ndjson.OptionalConverter(SequenceParametersTypeConverter())
|
|
2251
|
+
self._user_parameters_converter = _ndjson.OptionalConverter(UserParametersTypeConverter())
|
|
2252
|
+
self._waveform_information_converter = _ndjson.VectorConverter(WaveformInformationTypeConverter())
|
|
2253
|
+
super().__init__(np.dtype([
|
|
2254
|
+
("version", self._version_converter.overall_dtype()),
|
|
2255
|
+
("subject_information", self._subject_information_converter.overall_dtype()),
|
|
2256
|
+
("study_information", self._study_information_converter.overall_dtype()),
|
|
2257
|
+
("measurement_information", self._measurement_information_converter.overall_dtype()),
|
|
2258
|
+
("acquisition_system_information", self._acquisition_system_information_converter.overall_dtype()),
|
|
2259
|
+
("experimental_conditions", self._experimental_conditions_converter.overall_dtype()),
|
|
2260
|
+
("encoding", self._encoding_converter.overall_dtype()),
|
|
2261
|
+
("sequence_parameters", self._sequence_parameters_converter.overall_dtype()),
|
|
2262
|
+
("user_parameters", self._user_parameters_converter.overall_dtype()),
|
|
2263
|
+
("waveform_information", self._waveform_information_converter.overall_dtype()),
|
|
2264
|
+
]))
|
|
2265
|
+
|
|
2266
|
+
def to_json(self, value: Header) -> object:
|
|
2267
|
+
if not isinstance(value, Header): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
2268
|
+
raise TypeError("Expected 'Header' instance")
|
|
2269
|
+
json_object = {}
|
|
2270
|
+
|
|
2271
|
+
if value.version is not None:
|
|
2272
|
+
json_object["version"] = self._version_converter.to_json(value.version)
|
|
2273
|
+
if value.subject_information is not None:
|
|
2274
|
+
json_object["subjectInformation"] = self._subject_information_converter.to_json(value.subject_information)
|
|
2275
|
+
if value.study_information is not None:
|
|
2276
|
+
json_object["studyInformation"] = self._study_information_converter.to_json(value.study_information)
|
|
2277
|
+
if value.measurement_information is not None:
|
|
2278
|
+
json_object["measurementInformation"] = self._measurement_information_converter.to_json(value.measurement_information)
|
|
2279
|
+
if value.acquisition_system_information is not None:
|
|
2280
|
+
json_object["acquisitionSystemInformation"] = self._acquisition_system_information_converter.to_json(value.acquisition_system_information)
|
|
2281
|
+
json_object["experimentalConditions"] = self._experimental_conditions_converter.to_json(value.experimental_conditions)
|
|
2282
|
+
json_object["encoding"] = self._encoding_converter.to_json(value.encoding)
|
|
2283
|
+
if value.sequence_parameters is not None:
|
|
2284
|
+
json_object["sequenceParameters"] = self._sequence_parameters_converter.to_json(value.sequence_parameters)
|
|
2285
|
+
if value.user_parameters is not None:
|
|
2286
|
+
json_object["userParameters"] = self._user_parameters_converter.to_json(value.user_parameters)
|
|
2287
|
+
json_object["waveformInformation"] = self._waveform_information_converter.to_json(value.waveform_information)
|
|
2288
|
+
return json_object
|
|
2289
|
+
|
|
2290
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
2291
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
2292
|
+
raise TypeError("Expected 'np.void' instance")
|
|
2293
|
+
json_object = {}
|
|
2294
|
+
|
|
2295
|
+
if (field_val := value["version"]) is not None:
|
|
2296
|
+
json_object["version"] = self._version_converter.numpy_to_json(field_val)
|
|
2297
|
+
if (field_val := value["subject_information"]) is not None:
|
|
2298
|
+
json_object["subjectInformation"] = self._subject_information_converter.numpy_to_json(field_val)
|
|
2299
|
+
if (field_val := value["study_information"]) is not None:
|
|
2300
|
+
json_object["studyInformation"] = self._study_information_converter.numpy_to_json(field_val)
|
|
2301
|
+
if (field_val := value["measurement_information"]) is not None:
|
|
2302
|
+
json_object["measurementInformation"] = self._measurement_information_converter.numpy_to_json(field_val)
|
|
2303
|
+
if (field_val := value["acquisition_system_information"]) is not None:
|
|
2304
|
+
json_object["acquisitionSystemInformation"] = self._acquisition_system_information_converter.numpy_to_json(field_val)
|
|
2305
|
+
json_object["experimentalConditions"] = self._experimental_conditions_converter.numpy_to_json(value["experimental_conditions"])
|
|
2306
|
+
json_object["encoding"] = self._encoding_converter.numpy_to_json(value["encoding"])
|
|
2307
|
+
if (field_val := value["sequence_parameters"]) is not None:
|
|
2308
|
+
json_object["sequenceParameters"] = self._sequence_parameters_converter.numpy_to_json(field_val)
|
|
2309
|
+
if (field_val := value["user_parameters"]) is not None:
|
|
2310
|
+
json_object["userParameters"] = self._user_parameters_converter.numpy_to_json(field_val)
|
|
2311
|
+
json_object["waveformInformation"] = self._waveform_information_converter.numpy_to_json(value["waveform_information"])
|
|
2312
|
+
return json_object
|
|
2313
|
+
|
|
2314
|
+
def from_json(self, json_object: object) -> Header:
|
|
2315
|
+
if not isinstance(json_object, dict):
|
|
2316
|
+
raise TypeError("Expected 'dict' instance")
|
|
2317
|
+
return Header(
|
|
2318
|
+
version=self._version_converter.from_json(json_object.get("version")),
|
|
2319
|
+
subject_information=self._subject_information_converter.from_json(json_object.get("subjectInformation")),
|
|
2320
|
+
study_information=self._study_information_converter.from_json(json_object.get("studyInformation")),
|
|
2321
|
+
measurement_information=self._measurement_information_converter.from_json(json_object.get("measurementInformation")),
|
|
2322
|
+
acquisition_system_information=self._acquisition_system_information_converter.from_json(json_object.get("acquisitionSystemInformation")),
|
|
2323
|
+
experimental_conditions=self._experimental_conditions_converter.from_json(json_object["experimentalConditions"],),
|
|
2324
|
+
encoding=self._encoding_converter.from_json(json_object["encoding"],),
|
|
2325
|
+
sequence_parameters=self._sequence_parameters_converter.from_json(json_object.get("sequenceParameters")),
|
|
2326
|
+
user_parameters=self._user_parameters_converter.from_json(json_object.get("userParameters")),
|
|
2327
|
+
waveform_information=self._waveform_information_converter.from_json(json_object["waveformInformation"],),
|
|
2328
|
+
)
|
|
2329
|
+
|
|
2330
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
2331
|
+
if not isinstance(json_object, dict):
|
|
2332
|
+
raise TypeError("Expected 'dict' instance")
|
|
2333
|
+
return (
|
|
2334
|
+
self._version_converter.from_json_to_numpy(json_object.get("version")),
|
|
2335
|
+
self._subject_information_converter.from_json_to_numpy(json_object.get("subjectInformation")),
|
|
2336
|
+
self._study_information_converter.from_json_to_numpy(json_object.get("studyInformation")),
|
|
2337
|
+
self._measurement_information_converter.from_json_to_numpy(json_object.get("measurementInformation")),
|
|
2338
|
+
self._acquisition_system_information_converter.from_json_to_numpy(json_object.get("acquisitionSystemInformation")),
|
|
2339
|
+
self._experimental_conditions_converter.from_json_to_numpy(json_object["experimentalConditions"]),
|
|
2340
|
+
self._encoding_converter.from_json_to_numpy(json_object["encoding"]),
|
|
2341
|
+
self._sequence_parameters_converter.from_json_to_numpy(json_object.get("sequenceParameters")),
|
|
2342
|
+
self._user_parameters_converter.from_json_to_numpy(json_object.get("userParameters")),
|
|
2343
|
+
self._waveform_information_converter.from_json_to_numpy(json_object["waveformInformation"]),
|
|
2344
|
+
) # type:ignore
|
|
2345
|
+
|
|
2346
|
+
|
|
2347
|
+
image_flags_name_to_value_map = {
|
|
2348
|
+
"isNavigationData": ImageFlags.IS_NAVIGATION_DATA,
|
|
2349
|
+
"firstInAverage": ImageFlags.FIRST_IN_AVERAGE,
|
|
2350
|
+
"lastInAverage": ImageFlags.LAST_IN_AVERAGE,
|
|
2351
|
+
"firstInSlice": ImageFlags.FIRST_IN_SLICE,
|
|
2352
|
+
"lastInSlice": ImageFlags.LAST_IN_SLICE,
|
|
2353
|
+
"firstInContrast": ImageFlags.FIRST_IN_CONTRAST,
|
|
2354
|
+
"lastInContrast": ImageFlags.LAST_IN_CONTRAST,
|
|
2355
|
+
"firstInPhase": ImageFlags.FIRST_IN_PHASE,
|
|
2356
|
+
"lastInPhase": ImageFlags.LAST_IN_PHASE,
|
|
2357
|
+
"firstInRepetition": ImageFlags.FIRST_IN_REPETITION,
|
|
2358
|
+
"lastInRepetition": ImageFlags.LAST_IN_REPETITION,
|
|
2359
|
+
"firstInSet": ImageFlags.FIRST_IN_SET,
|
|
2360
|
+
"lastInSet": ImageFlags.LAST_IN_SET,
|
|
2361
|
+
}
|
|
2362
|
+
image_flags_value_to_name_map = {v: n for n, v in image_flags_name_to_value_map.items()}
|
|
2363
|
+
|
|
2364
|
+
image_type_name_to_value_map = {
|
|
2365
|
+
"magnitude": ImageType.MAGNITUDE,
|
|
2366
|
+
"phase": ImageType.PHASE,
|
|
2367
|
+
"real": ImageType.REAL,
|
|
2368
|
+
"imag": ImageType.IMAG,
|
|
2369
|
+
"complex": ImageType.COMPLEX,
|
|
2370
|
+
}
|
|
2371
|
+
image_type_value_to_name_map = {v: n for n, v in image_type_name_to_value_map.items()}
|
|
2372
|
+
|
|
2373
|
+
class ImageMetaDataConverter(_ndjson.JsonConverter[ImageMetaData, np.void]):
|
|
2374
|
+
def __init__(self) -> None:
|
|
2375
|
+
self._name_converter = _ndjson.string_converter
|
|
2376
|
+
self._value_converter = _ndjson.string_converter
|
|
2377
|
+
super().__init__(np.dtype([
|
|
2378
|
+
("name", self._name_converter.overall_dtype()),
|
|
2379
|
+
("value", self._value_converter.overall_dtype()),
|
|
2380
|
+
]))
|
|
2381
|
+
|
|
2382
|
+
def to_json(self, value: ImageMetaData) -> object:
|
|
2383
|
+
if not isinstance(value, ImageMetaData): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
2384
|
+
raise TypeError("Expected 'ImageMetaData' instance")
|
|
2385
|
+
json_object = {}
|
|
2386
|
+
|
|
2387
|
+
json_object["name"] = self._name_converter.to_json(value.name)
|
|
2388
|
+
json_object["value"] = self._value_converter.to_json(value.value)
|
|
2389
|
+
return json_object
|
|
2390
|
+
|
|
2391
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
2392
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
2393
|
+
raise TypeError("Expected 'np.void' instance")
|
|
2394
|
+
json_object = {}
|
|
2395
|
+
|
|
2396
|
+
json_object["name"] = self._name_converter.numpy_to_json(value["name"])
|
|
2397
|
+
json_object["value"] = self._value_converter.numpy_to_json(value["value"])
|
|
2398
|
+
return json_object
|
|
2399
|
+
|
|
2400
|
+
def from_json(self, json_object: object) -> ImageMetaData:
|
|
2401
|
+
if not isinstance(json_object, dict):
|
|
2402
|
+
raise TypeError("Expected 'dict' instance")
|
|
2403
|
+
return ImageMetaData(
|
|
2404
|
+
name=self._name_converter.from_json(json_object["name"],),
|
|
2405
|
+
value=self._value_converter.from_json(json_object["value"],),
|
|
2406
|
+
)
|
|
2407
|
+
|
|
2408
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
2409
|
+
if not isinstance(json_object, dict):
|
|
2410
|
+
raise TypeError("Expected 'dict' instance")
|
|
2411
|
+
return (
|
|
2412
|
+
self._name_converter.from_json_to_numpy(json_object["name"]),
|
|
2413
|
+
self._value_converter.from_json_to_numpy(json_object["value"]),
|
|
2414
|
+
) # type:ignore
|
|
2415
|
+
|
|
2416
|
+
|
|
2417
|
+
class ImageConverter(typing.Generic[T, T_NP], _ndjson.JsonConverter[Image[T_NP], np.void]):
|
|
2418
|
+
def __init__(self, t_converter: _ndjson.JsonConverter[T, T_NP]) -> None:
|
|
2419
|
+
self._flags_converter = _ndjson.FlagsConverter(ImageFlags, np.uint64, image_flags_name_to_value_map, image_flags_value_to_name_map)
|
|
2420
|
+
self._measurement_uid_converter = _ndjson.uint32_converter
|
|
2421
|
+
self._field_of_view_converter = _ndjson.FixedNDArrayConverter(_ndjson.float32_converter, (3,))
|
|
2422
|
+
self._position_converter = _ndjson.FixedNDArrayConverter(_ndjson.float32_converter, (3,))
|
|
2423
|
+
self._col_dir_converter = _ndjson.FixedNDArrayConverter(_ndjson.float32_converter, (3,))
|
|
2424
|
+
self._line_dir_converter = _ndjson.FixedNDArrayConverter(_ndjson.float32_converter, (3,))
|
|
2425
|
+
self._slice_dir_converter = _ndjson.FixedNDArrayConverter(_ndjson.float32_converter, (3,))
|
|
2426
|
+
self._patient_table_position_converter = _ndjson.FixedNDArrayConverter(_ndjson.float32_converter, (3,))
|
|
2427
|
+
self._average_converter = _ndjson.OptionalConverter(_ndjson.uint32_converter)
|
|
2428
|
+
self._slice_converter = _ndjson.OptionalConverter(_ndjson.uint32_converter)
|
|
2429
|
+
self._contrast_converter = _ndjson.OptionalConverter(_ndjson.uint32_converter)
|
|
2430
|
+
self._phase_converter = _ndjson.OptionalConverter(_ndjson.uint32_converter)
|
|
2431
|
+
self._repetition_converter = _ndjson.OptionalConverter(_ndjson.uint32_converter)
|
|
2432
|
+
self._set_converter = _ndjson.OptionalConverter(_ndjson.uint32_converter)
|
|
2433
|
+
self._acquisition_time_stamp_converter = _ndjson.OptionalConverter(_ndjson.uint32_converter)
|
|
2434
|
+
self._physiology_time_stamp_converter = _ndjson.VectorConverter(_ndjson.uint32_converter)
|
|
2435
|
+
self._image_type_converter = _ndjson.EnumConverter(ImageType, np.int32, image_type_name_to_value_map, image_type_value_to_name_map)
|
|
2436
|
+
self._image_index_converter = _ndjson.OptionalConverter(_ndjson.uint32_converter)
|
|
2437
|
+
self._image_series_index_converter = _ndjson.OptionalConverter(_ndjson.uint32_converter)
|
|
2438
|
+
self._user_int_converter = _ndjson.VectorConverter(_ndjson.int32_converter)
|
|
2439
|
+
self._user_float_converter = _ndjson.VectorConverter(_ndjson.float32_converter)
|
|
2440
|
+
self._data_converter = _ndjson.NDArrayConverter(t_converter, 4)
|
|
2441
|
+
self._meta_converter = _ndjson.MapConverter(_ndjson.string_converter, _ndjson.VectorConverter(_ndjson.string_converter))
|
|
2442
|
+
super().__init__(np.dtype([
|
|
2443
|
+
("flags", self._flags_converter.overall_dtype()),
|
|
2444
|
+
("measurement_uid", self._measurement_uid_converter.overall_dtype()),
|
|
2445
|
+
("field_of_view", self._field_of_view_converter.overall_dtype()),
|
|
2446
|
+
("position", self._position_converter.overall_dtype()),
|
|
2447
|
+
("col_dir", self._col_dir_converter.overall_dtype()),
|
|
2448
|
+
("line_dir", self._line_dir_converter.overall_dtype()),
|
|
2449
|
+
("slice_dir", self._slice_dir_converter.overall_dtype()),
|
|
2450
|
+
("patient_table_position", self._patient_table_position_converter.overall_dtype()),
|
|
2451
|
+
("average", self._average_converter.overall_dtype()),
|
|
2452
|
+
("slice", self._slice_converter.overall_dtype()),
|
|
2453
|
+
("contrast", self._contrast_converter.overall_dtype()),
|
|
2454
|
+
("phase", self._phase_converter.overall_dtype()),
|
|
2455
|
+
("repetition", self._repetition_converter.overall_dtype()),
|
|
2456
|
+
("set", self._set_converter.overall_dtype()),
|
|
2457
|
+
("acquisition_time_stamp", self._acquisition_time_stamp_converter.overall_dtype()),
|
|
2458
|
+
("physiology_time_stamp", self._physiology_time_stamp_converter.overall_dtype()),
|
|
2459
|
+
("image_type", self._image_type_converter.overall_dtype()),
|
|
2460
|
+
("image_index", self._image_index_converter.overall_dtype()),
|
|
2461
|
+
("image_series_index", self._image_series_index_converter.overall_dtype()),
|
|
2462
|
+
("user_int", self._user_int_converter.overall_dtype()),
|
|
2463
|
+
("user_float", self._user_float_converter.overall_dtype()),
|
|
2464
|
+
("data", self._data_converter.overall_dtype()),
|
|
2465
|
+
("meta", self._meta_converter.overall_dtype()),
|
|
2466
|
+
]))
|
|
2467
|
+
|
|
2468
|
+
def to_json(self, value: Image[T_NP]) -> object:
|
|
2469
|
+
if not isinstance(value, Image): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
2470
|
+
raise TypeError("Expected 'Image[T_NP]' instance")
|
|
2471
|
+
json_object = {}
|
|
2472
|
+
|
|
2473
|
+
json_object["flags"] = self._flags_converter.to_json(value.flags)
|
|
2474
|
+
json_object["measurementUid"] = self._measurement_uid_converter.to_json(value.measurement_uid)
|
|
2475
|
+
json_object["fieldOfView"] = self._field_of_view_converter.to_json(value.field_of_view)
|
|
2476
|
+
json_object["position"] = self._position_converter.to_json(value.position)
|
|
2477
|
+
json_object["colDir"] = self._col_dir_converter.to_json(value.col_dir)
|
|
2478
|
+
json_object["lineDir"] = self._line_dir_converter.to_json(value.line_dir)
|
|
2479
|
+
json_object["sliceDir"] = self._slice_dir_converter.to_json(value.slice_dir)
|
|
2480
|
+
json_object["patientTablePosition"] = self._patient_table_position_converter.to_json(value.patient_table_position)
|
|
2481
|
+
if value.average is not None:
|
|
2482
|
+
json_object["average"] = self._average_converter.to_json(value.average)
|
|
2483
|
+
if value.slice is not None:
|
|
2484
|
+
json_object["slice"] = self._slice_converter.to_json(value.slice)
|
|
2485
|
+
if value.contrast is not None:
|
|
2486
|
+
json_object["contrast"] = self._contrast_converter.to_json(value.contrast)
|
|
2487
|
+
if value.phase is not None:
|
|
2488
|
+
json_object["phase"] = self._phase_converter.to_json(value.phase)
|
|
2489
|
+
if value.repetition is not None:
|
|
2490
|
+
json_object["repetition"] = self._repetition_converter.to_json(value.repetition)
|
|
2491
|
+
if value.set is not None:
|
|
2492
|
+
json_object["set"] = self._set_converter.to_json(value.set)
|
|
2493
|
+
if value.acquisition_time_stamp is not None:
|
|
2494
|
+
json_object["acquisitionTimeStamp"] = self._acquisition_time_stamp_converter.to_json(value.acquisition_time_stamp)
|
|
2495
|
+
json_object["physiologyTimeStamp"] = self._physiology_time_stamp_converter.to_json(value.physiology_time_stamp)
|
|
2496
|
+
json_object["imageType"] = self._image_type_converter.to_json(value.image_type)
|
|
2497
|
+
if value.image_index is not None:
|
|
2498
|
+
json_object["imageIndex"] = self._image_index_converter.to_json(value.image_index)
|
|
2499
|
+
if value.image_series_index is not None:
|
|
2500
|
+
json_object["imageSeriesIndex"] = self._image_series_index_converter.to_json(value.image_series_index)
|
|
2501
|
+
json_object["userInt"] = self._user_int_converter.to_json(value.user_int)
|
|
2502
|
+
json_object["userFloat"] = self._user_float_converter.to_json(value.user_float)
|
|
2503
|
+
json_object["data"] = self._data_converter.to_json(value.data)
|
|
2504
|
+
json_object["meta"] = self._meta_converter.to_json(value.meta)
|
|
2505
|
+
return json_object
|
|
2506
|
+
|
|
2507
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
2508
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
2509
|
+
raise TypeError("Expected 'np.void' instance")
|
|
2510
|
+
json_object = {}
|
|
2511
|
+
|
|
2512
|
+
json_object["flags"] = self._flags_converter.numpy_to_json(value["flags"])
|
|
2513
|
+
json_object["measurementUid"] = self._measurement_uid_converter.numpy_to_json(value["measurement_uid"])
|
|
2514
|
+
json_object["fieldOfView"] = self._field_of_view_converter.numpy_to_json(value["field_of_view"])
|
|
2515
|
+
json_object["position"] = self._position_converter.numpy_to_json(value["position"])
|
|
2516
|
+
json_object["colDir"] = self._col_dir_converter.numpy_to_json(value["col_dir"])
|
|
2517
|
+
json_object["lineDir"] = self._line_dir_converter.numpy_to_json(value["line_dir"])
|
|
2518
|
+
json_object["sliceDir"] = self._slice_dir_converter.numpy_to_json(value["slice_dir"])
|
|
2519
|
+
json_object["patientTablePosition"] = self._patient_table_position_converter.numpy_to_json(value["patient_table_position"])
|
|
2520
|
+
if (field_val := value["average"]) is not None:
|
|
2521
|
+
json_object["average"] = self._average_converter.numpy_to_json(field_val)
|
|
2522
|
+
if (field_val := value["slice"]) is not None:
|
|
2523
|
+
json_object["slice"] = self._slice_converter.numpy_to_json(field_val)
|
|
2524
|
+
if (field_val := value["contrast"]) is not None:
|
|
2525
|
+
json_object["contrast"] = self._contrast_converter.numpy_to_json(field_val)
|
|
2526
|
+
if (field_val := value["phase"]) is not None:
|
|
2527
|
+
json_object["phase"] = self._phase_converter.numpy_to_json(field_val)
|
|
2528
|
+
if (field_val := value["repetition"]) is not None:
|
|
2529
|
+
json_object["repetition"] = self._repetition_converter.numpy_to_json(field_val)
|
|
2530
|
+
if (field_val := value["set"]) is not None:
|
|
2531
|
+
json_object["set"] = self._set_converter.numpy_to_json(field_val)
|
|
2532
|
+
if (field_val := value["acquisition_time_stamp"]) is not None:
|
|
2533
|
+
json_object["acquisitionTimeStamp"] = self._acquisition_time_stamp_converter.numpy_to_json(field_val)
|
|
2534
|
+
json_object["physiologyTimeStamp"] = self._physiology_time_stamp_converter.numpy_to_json(value["physiology_time_stamp"])
|
|
2535
|
+
json_object["imageType"] = self._image_type_converter.numpy_to_json(value["image_type"])
|
|
2536
|
+
if (field_val := value["image_index"]) is not None:
|
|
2537
|
+
json_object["imageIndex"] = self._image_index_converter.numpy_to_json(field_val)
|
|
2538
|
+
if (field_val := value["image_series_index"]) is not None:
|
|
2539
|
+
json_object["imageSeriesIndex"] = self._image_series_index_converter.numpy_to_json(field_val)
|
|
2540
|
+
json_object["userInt"] = self._user_int_converter.numpy_to_json(value["user_int"])
|
|
2541
|
+
json_object["userFloat"] = self._user_float_converter.numpy_to_json(value["user_float"])
|
|
2542
|
+
json_object["data"] = self._data_converter.numpy_to_json(value["data"])
|
|
2543
|
+
json_object["meta"] = self._meta_converter.numpy_to_json(value["meta"])
|
|
2544
|
+
return json_object
|
|
2545
|
+
|
|
2546
|
+
def from_json(self, json_object: object) -> Image[T_NP]:
|
|
2547
|
+
if not isinstance(json_object, dict):
|
|
2548
|
+
raise TypeError("Expected 'dict' instance")
|
|
2549
|
+
return Image[T_NP](
|
|
2550
|
+
flags=self._flags_converter.from_json(json_object["flags"],),
|
|
2551
|
+
measurement_uid=self._measurement_uid_converter.from_json(json_object["measurementUid"],),
|
|
2552
|
+
field_of_view=self._field_of_view_converter.from_json(json_object["fieldOfView"],),
|
|
2553
|
+
position=self._position_converter.from_json(json_object["position"],),
|
|
2554
|
+
col_dir=self._col_dir_converter.from_json(json_object["colDir"],),
|
|
2555
|
+
line_dir=self._line_dir_converter.from_json(json_object["lineDir"],),
|
|
2556
|
+
slice_dir=self._slice_dir_converter.from_json(json_object["sliceDir"],),
|
|
2557
|
+
patient_table_position=self._patient_table_position_converter.from_json(json_object["patientTablePosition"],),
|
|
2558
|
+
average=self._average_converter.from_json(json_object.get("average")),
|
|
2559
|
+
slice=self._slice_converter.from_json(json_object.get("slice")),
|
|
2560
|
+
contrast=self._contrast_converter.from_json(json_object.get("contrast")),
|
|
2561
|
+
phase=self._phase_converter.from_json(json_object.get("phase")),
|
|
2562
|
+
repetition=self._repetition_converter.from_json(json_object.get("repetition")),
|
|
2563
|
+
set=self._set_converter.from_json(json_object.get("set")),
|
|
2564
|
+
acquisition_time_stamp=self._acquisition_time_stamp_converter.from_json(json_object.get("acquisitionTimeStamp")),
|
|
2565
|
+
physiology_time_stamp=self._physiology_time_stamp_converter.from_json(json_object["physiologyTimeStamp"],),
|
|
2566
|
+
image_type=self._image_type_converter.from_json(json_object["imageType"],),
|
|
2567
|
+
image_index=self._image_index_converter.from_json(json_object.get("imageIndex")),
|
|
2568
|
+
image_series_index=self._image_series_index_converter.from_json(json_object.get("imageSeriesIndex")),
|
|
2569
|
+
user_int=self._user_int_converter.from_json(json_object["userInt"],),
|
|
2570
|
+
user_float=self._user_float_converter.from_json(json_object["userFloat"],),
|
|
2571
|
+
data=self._data_converter.from_json(json_object["data"],),
|
|
2572
|
+
meta=self._meta_converter.from_json(json_object["meta"],),
|
|
2573
|
+
)
|
|
2574
|
+
|
|
2575
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
2576
|
+
if not isinstance(json_object, dict):
|
|
2577
|
+
raise TypeError("Expected 'dict' instance")
|
|
2578
|
+
return (
|
|
2579
|
+
self._flags_converter.from_json_to_numpy(json_object["flags"]),
|
|
2580
|
+
self._measurement_uid_converter.from_json_to_numpy(json_object["measurementUid"]),
|
|
2581
|
+
self._field_of_view_converter.from_json_to_numpy(json_object["fieldOfView"]),
|
|
2582
|
+
self._position_converter.from_json_to_numpy(json_object["position"]),
|
|
2583
|
+
self._col_dir_converter.from_json_to_numpy(json_object["colDir"]),
|
|
2584
|
+
self._line_dir_converter.from_json_to_numpy(json_object["lineDir"]),
|
|
2585
|
+
self._slice_dir_converter.from_json_to_numpy(json_object["sliceDir"]),
|
|
2586
|
+
self._patient_table_position_converter.from_json_to_numpy(json_object["patientTablePosition"]),
|
|
2587
|
+
self._average_converter.from_json_to_numpy(json_object.get("average")),
|
|
2588
|
+
self._slice_converter.from_json_to_numpy(json_object.get("slice")),
|
|
2589
|
+
self._contrast_converter.from_json_to_numpy(json_object.get("contrast")),
|
|
2590
|
+
self._phase_converter.from_json_to_numpy(json_object.get("phase")),
|
|
2591
|
+
self._repetition_converter.from_json_to_numpy(json_object.get("repetition")),
|
|
2592
|
+
self._set_converter.from_json_to_numpy(json_object.get("set")),
|
|
2593
|
+
self._acquisition_time_stamp_converter.from_json_to_numpy(json_object.get("acquisitionTimeStamp")),
|
|
2594
|
+
self._physiology_time_stamp_converter.from_json_to_numpy(json_object["physiologyTimeStamp"]),
|
|
2595
|
+
self._image_type_converter.from_json_to_numpy(json_object["imageType"]),
|
|
2596
|
+
self._image_index_converter.from_json_to_numpy(json_object.get("imageIndex")),
|
|
2597
|
+
self._image_series_index_converter.from_json_to_numpy(json_object.get("imageSeriesIndex")),
|
|
2598
|
+
self._user_int_converter.from_json_to_numpy(json_object["userInt"]),
|
|
2599
|
+
self._user_float_converter.from_json_to_numpy(json_object["userFloat"]),
|
|
2600
|
+
self._data_converter.from_json_to_numpy(json_object["data"]),
|
|
2601
|
+
self._meta_converter.from_json_to_numpy(json_object["meta"]),
|
|
2602
|
+
) # type:ignore
|
|
2603
|
+
|
|
2604
|
+
|
|
2605
|
+
class WaveformConverter(typing.Generic[T, T_NP], _ndjson.JsonConverter[Waveform[T_NP], np.void]):
|
|
2606
|
+
def __init__(self, t_converter: _ndjson.JsonConverter[T, T_NP]) -> None:
|
|
2607
|
+
self._flags_converter = _ndjson.uint64_converter
|
|
2608
|
+
self._measurement_uid_converter = _ndjson.uint32_converter
|
|
2609
|
+
self._scan_counter_converter = _ndjson.uint32_converter
|
|
2610
|
+
self._time_stamp_converter = _ndjson.uint32_converter
|
|
2611
|
+
self._sample_time_us_converter = _ndjson.float32_converter
|
|
2612
|
+
self._waveform_id_converter = _ndjson.uint32_converter
|
|
2613
|
+
self._data_converter = _ndjson.NDArrayConverter(t_converter, 2)
|
|
2614
|
+
super().__init__(np.dtype([
|
|
2615
|
+
("flags", self._flags_converter.overall_dtype()),
|
|
2616
|
+
("measurement_uid", self._measurement_uid_converter.overall_dtype()),
|
|
2617
|
+
("scan_counter", self._scan_counter_converter.overall_dtype()),
|
|
2618
|
+
("time_stamp", self._time_stamp_converter.overall_dtype()),
|
|
2619
|
+
("sample_time_us", self._sample_time_us_converter.overall_dtype()),
|
|
2620
|
+
("waveform_id", self._waveform_id_converter.overall_dtype()),
|
|
2621
|
+
("data", self._data_converter.overall_dtype()),
|
|
2622
|
+
]))
|
|
2623
|
+
|
|
2624
|
+
def to_json(self, value: Waveform[T_NP]) -> object:
|
|
2625
|
+
if not isinstance(value, Waveform): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
2626
|
+
raise TypeError("Expected 'Waveform[T_NP]' instance")
|
|
2627
|
+
json_object = {}
|
|
2628
|
+
|
|
2629
|
+
json_object["flags"] = self._flags_converter.to_json(value.flags)
|
|
2630
|
+
json_object["measurementUid"] = self._measurement_uid_converter.to_json(value.measurement_uid)
|
|
2631
|
+
json_object["scanCounter"] = self._scan_counter_converter.to_json(value.scan_counter)
|
|
2632
|
+
json_object["timeStamp"] = self._time_stamp_converter.to_json(value.time_stamp)
|
|
2633
|
+
json_object["sampleTimeUs"] = self._sample_time_us_converter.to_json(value.sample_time_us)
|
|
2634
|
+
json_object["waveformId"] = self._waveform_id_converter.to_json(value.waveform_id)
|
|
2635
|
+
json_object["data"] = self._data_converter.to_json(value.data)
|
|
2636
|
+
return json_object
|
|
2637
|
+
|
|
2638
|
+
def numpy_to_json(self, value: np.void) -> object:
|
|
2639
|
+
if not isinstance(value, np.void): # pyright: ignore [reportUnnecessaryIsInstance]
|
|
2640
|
+
raise TypeError("Expected 'np.void' instance")
|
|
2641
|
+
json_object = {}
|
|
2642
|
+
|
|
2643
|
+
json_object["flags"] = self._flags_converter.numpy_to_json(value["flags"])
|
|
2644
|
+
json_object["measurementUid"] = self._measurement_uid_converter.numpy_to_json(value["measurement_uid"])
|
|
2645
|
+
json_object["scanCounter"] = self._scan_counter_converter.numpy_to_json(value["scan_counter"])
|
|
2646
|
+
json_object["timeStamp"] = self._time_stamp_converter.numpy_to_json(value["time_stamp"])
|
|
2647
|
+
json_object["sampleTimeUs"] = self._sample_time_us_converter.numpy_to_json(value["sample_time_us"])
|
|
2648
|
+
json_object["waveformId"] = self._waveform_id_converter.numpy_to_json(value["waveform_id"])
|
|
2649
|
+
json_object["data"] = self._data_converter.numpy_to_json(value["data"])
|
|
2650
|
+
return json_object
|
|
2651
|
+
|
|
2652
|
+
def from_json(self, json_object: object) -> Waveform[T_NP]:
|
|
2653
|
+
if not isinstance(json_object, dict):
|
|
2654
|
+
raise TypeError("Expected 'dict' instance")
|
|
2655
|
+
return Waveform[T_NP](
|
|
2656
|
+
flags=self._flags_converter.from_json(json_object["flags"],),
|
|
2657
|
+
measurement_uid=self._measurement_uid_converter.from_json(json_object["measurementUid"],),
|
|
2658
|
+
scan_counter=self._scan_counter_converter.from_json(json_object["scanCounter"],),
|
|
2659
|
+
time_stamp=self._time_stamp_converter.from_json(json_object["timeStamp"],),
|
|
2660
|
+
sample_time_us=self._sample_time_us_converter.from_json(json_object["sampleTimeUs"],),
|
|
2661
|
+
waveform_id=self._waveform_id_converter.from_json(json_object["waveformId"],),
|
|
2662
|
+
data=self._data_converter.from_json(json_object["data"],),
|
|
2663
|
+
)
|
|
2664
|
+
|
|
2665
|
+
def from_json_to_numpy(self, json_object: object) -> np.void:
|
|
2666
|
+
if not isinstance(json_object, dict):
|
|
2667
|
+
raise TypeError("Expected 'dict' instance")
|
|
2668
|
+
return (
|
|
2669
|
+
self._flags_converter.from_json_to_numpy(json_object["flags"]),
|
|
2670
|
+
self._measurement_uid_converter.from_json_to_numpy(json_object["measurementUid"]),
|
|
2671
|
+
self._scan_counter_converter.from_json_to_numpy(json_object["scanCounter"]),
|
|
2672
|
+
self._time_stamp_converter.from_json_to_numpy(json_object["timeStamp"]),
|
|
2673
|
+
self._sample_time_us_converter.from_json_to_numpy(json_object["sampleTimeUs"]),
|
|
2674
|
+
self._waveform_id_converter.from_json_to_numpy(json_object["waveformId"]),
|
|
2675
|
+
self._data_converter.from_json_to_numpy(json_object["data"]),
|
|
2676
|
+
) # type:ignore
|
|
2677
|
+
|
|
2678
|
+
|
|
2679
|
+
class NDJsonMrdWriter(_ndjson.NDJsonProtocolWriter, MrdWriterBase):
|
|
2680
|
+
"""NDJson writer for the Mrd protocol."""
|
|
2681
|
+
|
|
2682
|
+
|
|
2683
|
+
def __init__(self, stream: typing.Union[typing.TextIO, str]) -> None:
|
|
2684
|
+
MrdWriterBase.__init__(self)
|
|
2685
|
+
_ndjson.NDJsonProtocolWriter.__init__(self, stream, MrdWriterBase.schema)
|
|
2686
|
+
|
|
2687
|
+
def _write_header(self, value: typing.Optional[Header]) -> None:
|
|
2688
|
+
converter = _ndjson.OptionalConverter(HeaderConverter())
|
|
2689
|
+
json_value = converter.to_json(value)
|
|
2690
|
+
self._write_json_line({"header": json_value})
|
|
2691
|
+
|
|
2692
|
+
def _write_data(self, value: collections.abc.Iterable[StreamItem]) -> None:
|
|
2693
|
+
converter = _ndjson.UnionConverter(StreamItem, [(StreamItem.Acquisition, AcquisitionConverter(), [dict]), (StreamItem.WaveformUint32, WaveformConverter(_ndjson.uint32_converter), [dict]), (StreamItem.ImageUint16, ImageConverter(_ndjson.uint16_converter), [dict]), (StreamItem.ImageInt16, ImageConverter(_ndjson.int16_converter), [dict]), (StreamItem.ImageUint, ImageConverter(_ndjson.uint32_converter), [dict]), (StreamItem.ImageInt, ImageConverter(_ndjson.int32_converter), [dict]), (StreamItem.ImageFloat, ImageConverter(_ndjson.float32_converter), [dict]), (StreamItem.ImageDouble, ImageConverter(_ndjson.float64_converter), [dict]), (StreamItem.ImageComplexFloat, ImageConverter(_ndjson.complexfloat32_converter), [dict]), (StreamItem.ImageComplexDouble, ImageConverter(_ndjson.complexfloat64_converter), [dict])], False)
|
|
2694
|
+
for item in value:
|
|
2695
|
+
json_item = converter.to_json(item)
|
|
2696
|
+
self._write_json_line({"data": json_item})
|
|
2697
|
+
|
|
2698
|
+
|
|
2699
|
+
class NDJsonMrdReader(_ndjson.NDJsonProtocolReader, MrdReaderBase):
|
|
2700
|
+
"""NDJson writer for the Mrd protocol."""
|
|
2701
|
+
|
|
2702
|
+
|
|
2703
|
+
def __init__(self, stream: typing.Union[io.BufferedReader, typing.TextIO, str]) -> None:
|
|
2704
|
+
MrdReaderBase.__init__(self)
|
|
2705
|
+
_ndjson.NDJsonProtocolReader.__init__(self, stream, MrdReaderBase.schema)
|
|
2706
|
+
|
|
2707
|
+
def _read_header(self) -> typing.Optional[Header]:
|
|
2708
|
+
json_object = self._read_json_line("header", True)
|
|
2709
|
+
converter = _ndjson.OptionalConverter(HeaderConverter())
|
|
2710
|
+
return converter.from_json(json_object)
|
|
2711
|
+
|
|
2712
|
+
def _read_data(self) -> collections.abc.Iterable[StreamItem]:
|
|
2713
|
+
converter = _ndjson.UnionConverter(StreamItem, [(StreamItem.Acquisition, AcquisitionConverter(), [dict]), (StreamItem.WaveformUint32, WaveformConverter(_ndjson.uint32_converter), [dict]), (StreamItem.ImageUint16, ImageConverter(_ndjson.uint16_converter), [dict]), (StreamItem.ImageInt16, ImageConverter(_ndjson.int16_converter), [dict]), (StreamItem.ImageUint, ImageConverter(_ndjson.uint32_converter), [dict]), (StreamItem.ImageInt, ImageConverter(_ndjson.int32_converter), [dict]), (StreamItem.ImageFloat, ImageConverter(_ndjson.float32_converter), [dict]), (StreamItem.ImageDouble, ImageConverter(_ndjson.float64_converter), [dict]), (StreamItem.ImageComplexFloat, ImageConverter(_ndjson.complexfloat32_converter), [dict]), (StreamItem.ImageComplexDouble, ImageConverter(_ndjson.complexfloat64_converter), [dict])], False)
|
|
2714
|
+
while (json_object := self._read_json_line("data", False)) is not _ndjson.MISSING_SENTINEL:
|
|
2715
|
+
yield converter.from_json(json_object)
|
|
2716
|
+
|