PixelsTransform¶
- class geodesic.boson.PixelsTransform(*args, **kwargs)[source]¶
Bases:
geodesic.boson.middleware._Middleware
- static colormap(*, asset, band, colormap_name='magma', lookup_table=None, min=None, max=None, rescale=False, no_data_value=None, asset_name='colormap')[source]¶
apply a colormap to the pixels data from an existing asset in the dataset
- Parameters
asset (str) – asset to apply the colormap to
colormap_name (str) – name of the colormap to apply. Defaults to “magma”.
lookup_table (Optional[List[List[int]]]) – lookup table to apply. Defaults to None. This can be used to provide a custom colormap via a lookup table. In this case, this should be a list of lists where each sublist is a color, including the alpha channel. For instance, [[0, 0, 0, 255], [255, 255, 255, 255]] would create a colormap that goes from black to white in two steps, splitting values below 0,5 to black and above to white.
min (Optional[float]) – minimum value of the colormap. Valid only if rescale is True. Defaults to None.
max (Optional[float]) – maximum value of the colormap. Valid only if rescale is True. Defaults to None.
rescale (bool) – whether to rescale the colormap to the min and max values. If min/max are None, statistics of the dataset (if available) will be used, otherwise the values of the current response will be used. Defaults to False.
no_data_value (Optional[float]) – value to use for pixels with no data. These values will be transparent. Defaults to None.
asset_name (str) – name of the asset to create. Defaults to “colormap”.
- static default_asset_bands(default_asset_bands)[source]¶
sets the default value of asset_bands in a pixels request on a Dataset.
This is useful for when you are creating a static dataset and want to set the default bands that will be used in the pixels request or for when you have a dataset that has multiple bands and you want to set the default bands that will be used in the pixels request.
- static rasterize(attribute_name=None, value=None, use_z=False, initialize_value=None, invert=False, all_touched=False, add=False, collections=[], asset_name='rasterized', band_name='rasterized', feature_limit=25000)[source]¶
creates a rasterized image from a feature collection as a new raster asset
Rasterize middleware is useful for performing simple aggregations on a feature collection. This can be useful for things like creating a population density raster from a feature collection of population counts or creating a binary raster from a feature collection of labels in a segmentation task.
- Parameters
attribute_name (Optional[str]) – attribute name to rasterize. Defaults to None.
value (Optional[Any]) – value to rasterize. Defaults to None.
use_z (bool) – whether to use the z value of the feature. Defaults to False.
initialize_value (Optional[Any]) – value to initialize the raster with. Defaults to None.
invert (bool) – invert which pixels are rasterize. Defaults to False.
all_touched (bool) – whether to rasterize all pixels touched by the feature. Defaults to False.
add (bool) – whether to add the raster to the asset. Defaults to False.
collections (List[str]) – collections to rasterize. Defaults to [] (all collections).
asset_name (str) – name of the asset to create. Defaults to “rasterized”.
band_name (str) – name of the band to create. Defaults to “rasterized”.
feature_limit (int) – maximum number of features to rasterize. Defaults to 25000.
Examples
>>> # Rasterize the population attribute by summing the values in the attribute for each pixel >>> transform = PixelsTransform.rasterize( ... attribute_name="population", ... add=True, ... asset_name="population_raster", ... band_name="population" ... )
>>> # Rasterize by object by setting the value to 1 wherever there is an object >>> transform = PixelsTransform.rasterize( ... value=1 ... )
>>> # Rasterize by object by setting the value to 1 wherever there is NOT an object >>> transform = PixelsTransform.rasterize( ... value=1, ... invert=True ... )