How to use the descarteslabs.workflows.types.primitives.Float function in descarteslabs

To help you get started, we’ve selected a few descarteslabs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github descarteslabs / descarteslabs-python / descarteslabs / workflows / types / datetimes / datetime_.py View on Github external
    @typecheck_promote((Int, Float))
    def from_timestamp(cls, seconds):
        return cls._from_apply("datetime.from_timestamp", seconds)
github descarteslabs / descarteslabs-python / descarteslabs / workflows / types / geospatial / where.py View on Github external
x: `Image`, `ImageCollection`, `Int`, `Float`
        The true `Image`, `ImageCollection`, or scalar.  Where ``condition`` is True, we
        yield values from ``x``.
    y: `Image`, `ImageCollection`, `Int`, `Float`
        The false `Image`, `ImageCollection`, or scalar.  Where ``condition`` is False, we
        yield values from ``y``.

    Returns
    -------
    `Image`, `ImageCollection`
        An `Image` or `ImageCollection` with values from ``x`` where ``condition`` is
        True, and values from ``y`` elsewhere.
    """
    if (
        isinstance(condition, Bool)
        and isinstance(x, (Int, Float))
        and isinstance(y, (Int, Float))
    ):
        raise ValueError(
            "Can't call workflows.where with a boolean condition and scalar x, y; currently not supported."
        )
    args = [condition, x, y]
    if any(isinstance(arg, ImageCollection) for arg in args):
        return_type = ImageCollection
    elif any(isinstance(arg, Image) for arg in args):
        return_type = Image
    elif isinstance(x, Float) or isinstance(y, Float):
        return_type = Float
    else:
        return_type = Int
    return return_type._from_apply("where", condition, x, y)
github descarteslabs / descarteslabs-python / descarteslabs / workflows / types / geospatial / image.py View on Github external
----------
        fill: int, float, `Image`
            The value to fill the `Image` with. If int or float, the fill value will be broadcasted to
            band dimensions as determined by the geocontext and provided bandinfo.
        mask: bool, default True
            Whether to mask the band data. If ``mask`` is True and ``fill`` is an `Image`,
            the original `Image` mask will be overridden and all underlying data will be masked.
            If ``mask`` is False and ``fill`` is an `Image`, the original mask is left as is.
            If ``fill`` is scalar, the `Image` constructed will be fully masked or fully un-masked
            data if ``mask`` is True and False respectively.
        bandinfo: dict, default None
            Bandinfo used in constructing new `Image`. If ``fill`` is an `Image`, bandinfo is optional, and
            will be ignored if provided. If ``fill`` is a scalar, the bandinfo will be used to determine
            the number of bands on the new `Image`, as well as become the bandinfo for it.
        """
        if isinstance(fill, (Int, Float)) and isinstance(bandinfo, NoneType):
            # filling with scalar requires bandinfo to be provided
            raise ValueError(
                "To replace empty Image with an int or float, bandinfo must be provided."
            )
        return self._from_apply("Image.replace_empty_with", self, fill, mask, bandinfo)
github descarteslabs / descarteslabs-python / descarteslabs / workflows / types / math / arithmetic.py View on Github external
def _higher_precedence_type(t1, t2, to_float=True):
    order = (Int, Float, Image, ImageCollection)
    t1_i = order.index(t1)
    t2_i = order.index(t2)
    return order[max(t1_i, t2_i, 1 if to_float else 0)]
github descarteslabs / descarteslabs-python / descarteslabs / workflows / types / proxify / proxify.py View on Github external
return Function.from_callable(obj)
    elif isinstance(obj, (tuple, list)):
        contents = [proxify(x) for x in obj]
        types = tuple(type(x) for x in contents)
        if (
            isinstance(obj, list)
            and len(types) > 0
            and all(t is types[0] for t in types[1:])
        ):
            return List[types[0]](contents)
        else:
            return Tuple[types](contents)
    elif isinstance(obj, int):
        return Int(obj)
    elif isinstance(obj, float):
        return Float(obj)
    elif isinstance(obj, bool):
        return Bool(obj)
    elif isinstance(obj, str):
        return Str(obj)
    elif obj is None:
        return NoneType(obj)
    elif isinstance(obj, (datetime.datetime, datetime.date)):
        return Datetime._promote(obj)
    elif isinstance(obj, datetime.timedelta):
        return Timedelta._promote(obj)
    else:
        try:
            return Any._promote(obj)
        except ProxyTypeError:
            raise NotImplementedError(
                "Cannot automatically convert to a Proxytype. "
github descarteslabs / descarteslabs-python / descarteslabs / workflows / types / datetimes / timedelta.py View on Github external
def total_seconds(self):
        return Float._from_apply("timedelta.total_seconds", self)
github descarteslabs / descarteslabs-python / descarteslabs / workflows / types / geospatial / convolution.py View on Github external
from ...cereal import serializable
from ..core import typecheck_promote
from ..primitives import Int, Float
from ..containers import List, Struct, Tuple
from .image import Image
from .imagecollection import ImageCollection


KernelBase = Struct[{"dims": Tuple[Int, Int], "data": List[Float]}]


@serializable(is_named_concrete_type=True)
class Kernel(KernelBase):
    """
    A Kernel is a proxy object holding the kernel when performing a 2-dimensional
    convolution.
    """

    _doc = {
        "dims": "Tuple containing the dimensions of the kernel",
        "data": "List containing the kernel data in row-major format",
    }
    _constructor = "Kernel.load"
github descarteslabs / descarteslabs-python / descarteslabs / workflows / types / geospatial / feature.py View on Github external
    @typecheck_promote(value=(Int, Float, Str), default_value=(Int, Float))
    def rasterize(self, value=1, default_value=1):
        """
        Rasterize this `Feature` into an `~.geospatial.Image`

        Parameters
        ----------
        value: Int, Float, Str, default=1
            Fill pixels within the `Feature` with this value.
            Pixels outside the `Feature` will be masked, and set to 0.
            If a string, it will look up that key in ``self.properties``;
            the value there must be a number.
        default_value: Int, Float, default=1
            Value to use if ``value`` is a string and the key does
            not exist in ``self.properties``

        Notes