Converters
- multimodars._converters.to_array(generic)[source]
Convert various multimodars Py* objects into numpy array(s) or dictionaries of arrays.
- Parameters:
generic (PyContour, PyCenterline, PyGeometry, PyGeometryPair, PyFrame, or PyInputData) – The object to be converted to numpy representation.
- Return type:
ndarray|dict|tuple[dict,dict]- Returns:
np.ndarray – For PyContour or PyCenterline: A 2D array of shape (N, 4), where each row is (frame_index, x, y, z).
dict[str, np.ndarray] – For PyGeometry: A dictionary with keys for each contour type and “reference”, each containing a 2D array of shape (M, 4), where M is the number of points in that layer.
tuple[dict[str, np.ndarray], dict[str, np.ndarray]] – For PyGeometryPair: A tuple of two dictionaries (one for geom_a, one for geom_b), each in the same format as returned for a single PyGeometry.
dict[str, np.ndarray | list[str] | bool] – For PyInputData: A dictionary containing arrays for each contour type and metadata.
- Raises:
TypeError – If the input type is not one of the supported multimodars types.
- multimodars._converters.numpy_to_inputdata(lumen_arr, ref_point, diastole, record=None, eem_arr=None, calcification=None, sidebranch=None, label='')[source]
Build a
PyInputDatafrom numpy arrays, grouping by frame index into frames.Each row in the array arguments must be
[frame_index, x, y, z].- Parameters:
lumen_arr (
ndarray) –(N, 4)array of lumen points[frame_index, x, y, z].record (
ndarray|None) –(M, 4)array of records[frame, phase, measurement_1, measurement_2].ref_point (
ndarray) –(1, 4)or(4,)array[frame_index, x, y, z]for the reference point.diastole (
bool) –Trueif the data corresponds to the diastolic phase.eem_arr (
ndarray|None) –(N, 4)array of EEM points[frame_index, x, y, z]. Default isNone.calcification (
ndarray|None) –(N, 4)array of calcification points. Default isNone.sidebranch (
ndarray|None) –(N, 4)array of side-branch points. Default isNone.label (
str) – Label string for the input data. Default is"".
- Returns:
input_data – Input data object with contours grouped by frame index.
- Return type:
PyInputData- Raises:
ValueError – If
lumen_arris empty.
- multimodars._converters.numpy_to_geometry(lumen_arr, eem_arr=None, catheter_arr=None, wall_arr=None, reference_arr=None, label='')[source]
Build a
PyGeometryfrom numpy arrays, grouping by frame index into frames.Each row in the array arguments must be
[frame_index, x, y, z].- Parameters:
lumen_arr (
ndarray) –(N, 4)array of lumen points[frame_index, x, y, z].eem_arr (
ndarray|None) –(M, 4)array of EEM points[frame_index, x, y, z]. Default isNone.catheter_arr (
ndarray|None) –(K, 4)array of catheter points[frame_index, x, y, z]. Default isNone.wall_arr (
ndarray|None) –(L, 4)array of wall points[frame_index, x, y, z]. Default isNone.reference_arr (
ndarray|None) –(1, 4)or(4,)array[frame_index, x, y, z]for the reference point. Default isNone.label (
str) – Label string for the geometry. Default is"".
- Returns:
geometry – Geometry object with frames constructed from the provided arrays.
- Return type:
PyGeometry- Raises:
ValueError – If
lumen_arris empty.
- multimodars._converters.numpy_to_centerline(arr, aortic=False)[source]
Build a
PyCenterlinefrom a numpy array.Linearly interpolates NaN values along each coordinate axis. Raises
ValueErrorif an entire coordinate column is NaN or fewer than two points remain after processing.- Parameters:
arr (
ndarray) –(N, 3)array where each row is(x, y, z).aortic (
bool) – Whether to mark each point as aortic. Default isFalse.
- Returns:
centerline – Centerline object built from the provided points.
- Return type:
PyCenterline- Raises:
ValueError – If
arris not(N, 3), is empty, all values in a coordinate column are NaN, or fewer than two points remain after interpolation.
- multimodars._converters.array_to_pyinputdata(lumen=None, eem=None, calcification=None, sidebranch=None, records=None, reference=None, diastole=True, label='')[source]
Create a
PyInputDatafrom eitherPy*objects or NumPy arrays.Accepts existing
PyContour/PyRecordinstances or raw arrays. For layer arrays each row must be(frame_index, x, y, z). Records accept a structured array or a list/array of rows(frame, phase, measurement_1, measurement_2).- Parameters:
lumen (list of PyContour or np.ndarray, optional) – Lumen contours or
(N, 4)array. Default isNone.eem (list of PyContour or np.ndarray, optional) – EEM contours or
(N, 4)array. Default isNone.calcification (list of PyContour or np.ndarray, optional) – Calcification contours or
(N, 4)array. Default isNone.sidebranch (list of PyContour or np.ndarray, optional) – Side-branch contours or
(N, 4)array. Default isNone.records (list of PyRecord or np.ndarray, optional) – Records or
(M, 4)array of(frame, phase, m1, m2)rows. Default isNone.reference (np.ndarray, optional) –
(1, 4)or(4,)array[frame_index, x, y, z]for the reference point. Default isNone.diastole (
bool) –Trueif the data corresponds to the diastolic phase. Default isTrue.label (
str) – Label string for the input data. Default is"".
- Returns:
input_data – Input data object populated from the provided arguments.
- Return type:
PyInputData- Raises:
ValueError – If a layer array has an incompatible shape or unsupported format.
- multimodars._converters.geometry_to_frames_array(geometry)[source]
Convert a
PyGeometryto a nested dictionary of numpy arrays by frame.- Parameters:
geometry (
PyGeometry) – Geometry object to convert.- Returns:
result – Mapping from frame ID strings to dictionaries of contour-type arrays. Each inner dictionary has keys such as
"lumen","eem","catheter","wall", and"reference", each containing a(N, 4)array[frame_index, x, y, z].- Return type:
dict[str,dict[str,ndarray]]