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 PyInputData from 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) – True if the data corresponds to the diastolic phase.

  • eem_arr (ndarray | None) – (N, 4) array of EEM points [frame_index, x, y, z]. Default is None.

  • calcification (ndarray | None) – (N, 4) array of calcification points. Default is None.

  • sidebranch (ndarray | None) – (N, 4) array of side-branch points. Default is None.

  • 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_arr is empty.

multimodars._converters.numpy_to_geometry(lumen_arr, eem_arr=None, catheter_arr=None, wall_arr=None, reference_arr=None, label='')[source]

Build a PyGeometry from 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 is None.

  • catheter_arr (ndarray | None) – (K, 4) array of catheter points [frame_index, x, y, z]. Default is None.

  • wall_arr (ndarray | None) – (L, 4) array of wall points [frame_index, x, y, z]. Default is None.

  • reference_arr (ndarray | None) – (1, 4) or (4,) array [frame_index, x, y, z] for the reference point. Default is None.

  • 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_arr is empty.

multimodars._converters.numpy_to_centerline(arr, aortic=False)[source]

Build a PyCenterline from a numpy array.

Linearly interpolates NaN values along each coordinate axis. Raises ValueError if 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 is False.

Returns:

centerline – Centerline object built from the provided points.

Return type:

PyCenterline

Raises:

ValueError – If arr is 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 PyInputData from either Py* objects or NumPy arrays.

Accepts existing PyContour / PyRecord instances 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 is None.

  • eem (list of PyContour or np.ndarray, optional) – EEM contours or (N, 4) array. Default is None.

  • calcification (list of PyContour or np.ndarray, optional) – Calcification contours or (N, 4) array. Default is None.

  • sidebranch (list of PyContour or np.ndarray, optional) – Side-branch contours or (N, 4) array. Default is None.

  • records (list of PyRecord or np.ndarray, optional) – Records or (M, 4) array of (frame, phase, m1, m2) rows. Default is None.

  • reference (np.ndarray, optional) – (1, 4) or (4,) array [frame_index, x, y, z] for the reference point. Default is None.

  • diastole (bool) – True if the data corresponds to the diastolic phase. Default is True.

  • 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 PyGeometry to 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]]