Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

pymrm.segmentation.segment_values

Back to module page · Back to alphabetical overview

Signature

segment_values(values, seg, ibm, *, default = None)

Summary

Expand per-segment values to a per-crossing array for pymrm.apply_ibm.

Documentation

Parameters

Returns

Source

View on GitHub

def segment_values(values, seg, ibm, *, default=None):
    """Expand per-segment values to a per-crossing array for :func:`pymrm.apply_ibm`.

    Parameters
    ----------
    values : array_like or dict
        Either an array of shape ``(n_segments, *trailing)`` or a
        ``{label: value}`` dict.  The trailing dimensions must be broadcastable
        to ``ibm.ns_shape`` (the non-spatial axes).
    seg : Segmentation
    ibm : IBM
    default : optional
        Value for segments absent from a ``dict`` input.  If ``None`` a missing
        label that carries crossings raises ``ValueError``.

    Returns
    -------
    ndarray, shape ``(n_crossings, 1, ..., 1, *trailing)``
        Canonical point-value array, ready to pass as ``values_outside`` /
        ``values_inside``.
    """
    seg_ids = crossing_segments(seg, ibm)
    lookup, provided = _segment_lookup(values, seg.n_segments, default,
                                       "segment_values")
    picked = _index_lookup(lookup, provided, seg_ids, "segment_values")
    return _to_point_shape(picked, len(ibm.ns_shape))