Skip to content

ORDERED_TRIPLE_2_SURFACE

Download Flojoy Studio to try this app
Convert an OrderedTriple DataContainer to a Surface DataContainer. Params: default : OrderedTriple The input OrderedTriple to which we apply the conversion to. Returns: out : Surface The surface result from the conversion of the input.
Python Code
from flojoy import flojoy, OrderedTriple, Surface
import numpy as np


@flojoy
def ORDERED_TRIPLE_2_SURFACE(default: OrderedTriple) -> Surface:
    """Convert an OrderedTriple DataContainer to a Surface DataContainer.

    Parameters
    ----------
    default : OrderedTriple
        The input OrderedTriple to which we apply the conversion to.

    Returns
    -------
    Surface
        The surface result from the conversion of the input.
    """

    x = np.unique(default.x)
    y = np.unique(default.y)

    z_size = len(x) * len(y)

    # Truncate or pad the z array to match the desired size
    if z_size > len(default.z):
        z = np.pad(default.z, (0, z_size - len(default.z)), mode="constant").reshape(
            len(y), len(x)
        )
    else:
        z = default.z[:z_size].reshape(len(y), len(x))

    X, Y = np.meshgrid(x, y)
    return Surface(x=X, y=Y, z=z)

Find this Flojoy Block on GitHub

Example App

Having problems with this example app? Join our Discord community and we will help you out!
React Flow mini map

In this example we started with the PLOTLY_DATASET node to generate a DataFrame which we passed to a type casting node DF_2_ORDERED_TRIPLE to convert DataFrame into OrderedTriple type of DataContainer class.

Then we used ORDERED_TRIPLE_2_SURFACE node to cast OrderedTriple to Surface DataContainer type. Finally we vizualized output with Plotly visualizer node SURFACE3D.