Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _DelayedImageCollection():
from .imagecollection import ImageCollection
return ImageCollection
@typecheck_promote((Image, ImageCollection), Kernel)
def conv2d(obj, filt):
"""
2-D spatial convolution of `Image` or `ImageCollection`.
Example
-------
>>> import descarteslabs.workflows as wf
>>> img = wf.Image.from_id("landsat:LC08:PRE:TOAR:meta_LC80270312016188_v1")
>>> rgb = img.pick_bands(["red", "green", "blue"])
>>> w = wf.Kernel(dims=(3,3), data=[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0])
>>> t = wf.conv2d(rgb, w)
"""
return obj._from_apply("conv2d", obj, filt)
def __getitem__(self, idx):
return ImageCollection._from_apply("ImageCollectionGroupby.get", self, idx)
If it returns an `ImageCollection`, the ImageCollections for all groups will be concatenated together.
If it returns an `Image`, those Images will be combined into a single ImageCollection.
If it returns any other type, `map` will return a `Dict`, where keys are groups
and values are results of ``func``.
Note that every `Image` in every `ImageCollecion` gets a ``"group"`` field added to its `~.Image.properties`,
so that field will be merged/dropped according to normal metadata broadcasting rules (i.e. will still be present
on an `Image` composited from a group's `ImageCollection`, since it's the same for every `Image`.)
"""
proxy_func = Function.from_callable(func, self.key_type, ImageCollection)
result_type = proxy_func._type_params[-1]
if result_type in (ImageCollection, Image):
out_type = ImageCollection
func = "ImageCollectionGroupby.map_ic"
else:
out_type = Dict[self.key_type, result_type]
func = "ImageCollectionGroupby.map"
return out_type._from_apply(func, self, proxy_func)
(Image, ImageCollection, Bool),
(Image, ImageCollection, Int, Float),
(Image, ImageCollection, Int, Float),
)
def where(condition, x, y):
"""
Returns an `Image` or `ImageCollection` with values chosen from ``x`` or ``y``
depending on ``condition``.
Parameters
----------
condition: `Image`, `ImageCollection`, `Bool`
A `Bool`, or a boolean `Image` or `ImageCollection`. Where True, yield ``x``;
where False, yield ``y``. If a non-boolean `Image` or `ImageCollection` is
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
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)
-------
`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)
----------
back: Int, optional, default 0
Number of previous Images to pass as ``back`` to the function.
fwd: Int, optional, default 0
Number of subsequent Images to pass as ``fwd`` to the function.
Returns
-------
mapped: ImageCollection or List
If ``func`` returns an `ImageCollection` or `Image`,
all of them are concatenated together and returned as one `ImageCollection`.
Otherwise, returns a `List` of the values returned by ``func``.
"""
delayed_func = Function.from_callable(
func, ImageCollection, Image, ImageCollection
)
return_type = delayed_func._type_params[-1]
out_type, func = (
(ImageCollection, "ImageCollection.map_window_ic")
if return_type in (Image, ImageCollection)
else (List[return_type], "ImageCollection.map_window")
)
return out_type._from_apply(func, self, delayed_func, back, fwd)