How to use the descarteslabs.workflows.types.primitives.Bool 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 / geospatial / imagecollection.py View on Github external
        mask=Bool,
        bandinfo=(NoneType, Dict[Str, Dict[Str, Any]]),
    )
    def replace_empty_with(self, fill, mask=True, bandinfo=None):
        """
        Replace `ImageCollection`, if empty, with fill value.

        Parameters
        ----------
        fill: int, float, `ImageCollection`
            The value to fill the `ImageCollection` with. If int or float, the fill value will be broadcasted to
            a 1 image collection, with 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 `ImageCollection`,
            the original `ImageCollection` mask will be overridden and all underlying data will be masked.
            If ``mask`` is False and ``fill`` is an `ImageCollection`, the original mask is left as is.
            If ``fill`` is scalar, the `ImageCollection` constructed will be fully masked or fully un-masked
github descarteslabs / descarteslabs-python / descarteslabs / workflows / types / geospatial / image.py View on Github external
        (lambda: Image, Geometry, Feature, FeatureCollection), replace=Bool
    )
    def mask(self, mask, replace=False):
        """
        New `Image`, masked with a boolean `Image` or vector object.

        Parameters
        ----------
        mask: `Image`, `Geometry`, `~.workflows.types.geospatial.Feature`, `~.workflows.types.geospatial.FeatureCollection`
            A single-band `Image` of boolean values,
            (such as produced by ``img > 2``, for example)
            where True means masked (invalid).

            Or, a vector (`Geometry`, `~.workflows.types.geospatial.Feature`,
            or `~.workflows.types.geospatial.FeatureCollection`),
            in which case pixels *outside* the vector are masked.
        replace: Bool, default False
github descarteslabs / descarteslabs-python / descarteslabs / workflows / types / proxify / proxify.py View on Github external
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. "
                "Please manually construct the appropriate container type "
                "and initialize it with your object. Value: {!r}".format(obj)
github descarteslabs / descarteslabs-python / descarteslabs / workflows / types / geospatial / imagecollection.py View on Github external
    @typecheck_promote(None, reverse=Bool)
    def sorted(self, key, reverse=False):
        """
        Copy of this `ImageCollection`, sorted by a key function.

        Parameters
        ----------
        key: Function
            Function which takes an `Image` and returns a value to sort by.
        reverse: Bool, default False
            Sorts in ascending order if False (default), descending if True.

        Returns
        -------
        sorted: ImageCollection
        """
        key = self._make_sort_key(key)
github descarteslabs / descarteslabs-python / descarteslabs / workflows / types / geospatial / imagecollection.py View on Github external
        replace=Bool,
    )
    def mask(self, mask, replace=False):
        """
        New `ImageCollection`, masked with a boolean `ImageCollection`, `Image`, or vector object.

        Parameters
        ----------
        mask: `ImageCollection`, `Image`, `Geometry`, `~.workflows.types.geospatial.Feature`, `~.workflows.types.geospatial.FeatureCollection`
            A single-band `ImageCollection` of boolean values,
            (such as produced by ``col > 2``, for example)
            where True means masked (invalid).

            Or, single-band `Image` of boolean values,
            (such as produced by ``img > 2``, for example)
            where True means masked (invalid).
github descarteslabs / descarteslabs-python / descarteslabs / workflows / types / containers / collection.py View on Github external
    @typecheck_promote(key=None, reverse=Bool)
    def sorted(self, key=None, reverse=False):
        """
        Copy of this collection, sorted by a key function.

        Parameters
        ----------
        key: Function, optional, default None
            Function which takes an element and returns a value to sort by.
            If not given, sorts by the elements themselves.
        reverse: Bool, default False
            Sorts in ascending order if False (default), descending if True.
        """
        key = self._make_sort_key(key)
        return self._from_apply("sorted", self, key=key, reverse=reverse)
github descarteslabs / descarteslabs-python / descarteslabs / workflows / types / geospatial / where.py View on Github external
provided, its values will be coerced to booleans by taking nonzeroness.
    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 / featurecollection.py View on Github external
    @typecheck_promote(None, reverse=Bool)
    def sorted(self, key, reverse=False):
        """
        Copy of this `~.geospatial.FeatureCollection`, sorted by a key function.

        Parameters
        ----------
        key: Function
            Function which takes an `Feature` and returns a value to sort by.
        reverse: Bool, default False
            Sorts in ascending order if False (default), descending if True.

        Returns
        -------
        sorted: ~.geospatial.FeatureCollection
        """
        key = self._make_sort_key(key)