coordinates.mixins.mathops.CoordinateSystemMathMixin.compute_expression#
- CoordinateSystemMathMixin.compute_expression(expression: str, coordinates: Sequence[_Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]], fixed_axes: Dict[str, float] | None = None) _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] [source]#
Evaluate a named symbolic expression over mixed coordinate inputs.
This method supports evaluating an expression by combining: - Positional *coordinates (1D arrays for free axes), - Keyword fixed_axes (scalars for fixed axes), into a full coordinate list in canonical axis order.
- Parameters:
expression (
str
) – The name of the symbolic expression to evaluate.*coordinates (
array-like
) – Positional coordinate inputs for free axes. The number of entries must match the number of non-fixed axes in the system.fixed_axes (
dict
of{str: float}
, optional) – A dictionary mapping axis names to fixed scalar values (e.g., theta=np.pi/2). These axes must be a subset of the coordinate system’s axes and must not overlap with the axes supplied positionally.
- Returns:
The result of evaluating the named expression at the provided coordinates.
- Return type:
array-like
- Raises:
KeyError – If the expression is not found or has no numeric form.
ValueError – If coordinate axes or counts are inconsistent with the system definition.
Examples
>>> from pymetric.coordinates import CylindricalCoordinateSystem >>> from pymetric.utilities.logging import pg_log >>> pg_log.level = 50 >>> cs = CylindricalCoordinateSystem() >>> r = np.linspace(0, 1, 100) >>> z = np.linspace(-1, 1, 100) >>> R,Z = cs.coordinate_meshgrid(r,z,axes=['rho','z']) >>> rho = cs.compute_expression_from_coordinates( ... "metric_density", ... [R,Z], ... fixed_axes={"phi": np.pi/4} ... ) >>> rho.shape (100, 100)