Skip to content

Commit

Permalink
Merge pull request #201 from geo-engine/multiband-colorizer
Browse files Browse the repository at this point in the history
Multiband colorizer
  • Loading branch information
jdroenner authored Nov 8, 2024
2 parents 58de02f + fab365c commit d80e984
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 69 deletions.
131 changes: 89 additions & 42 deletions examples/colorizer.ipynb

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion geoengine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
RasterResultDescriptor, Provenance, UnitlessMeasurement, ContinuousMeasurement, \
ClassificationMeasurement, BoundingBox2D, TimeInterval, SpatialResolution, SpatialPartition2D, \
RasterSymbology, VectorSymbology, VectorDataType, VectorResultDescriptor, VectorColumnInfo, \
FeatureDataType, RasterBandDescriptor, DEFAULT_ISO_TIME_FORMAT, RasterColorizer, SingleBandRasterColorizer \
FeatureDataType, RasterBandDescriptor, DEFAULT_ISO_TIME_FORMAT, RasterColorizer, SingleBandRasterColorizer, \
MultiBandRasterColorizer

from .util import clamp_datetime_ms_ns
from .workflow import WorkflowId, Workflow, workflow_by_id, register_workflow, get_quota, update_quota
Expand Down
25 changes: 0 additions & 25 deletions geoengine/colorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,6 @@ def palette_with_colormap(
default_color=default_color,
)

@staticmethod
def rgba() -> RgbaColorizer:
return RgbaColorizer()

@abstractmethod
def to_api_dict(self) -> geoengine_openapi_client.Colorizer:
pass
Expand All @@ -230,8 +226,6 @@ def from_response(response: geoengine_openapi_client.Colorizer) -> Colorizer:
return PaletteColorizer.from_response_palette(inner)
if isinstance(inner, geoengine_openapi_client.LogarithmicGradient):
return LogarithmicGradientColorizer.from_response_logarithmic(inner)
if isinstance(inner, geoengine_openapi_client.RgbaColorizer):
return RgbaColorizer.from_response_rgba(inner)

raise TypeError("Unknown colorizer type")

Expand Down Expand Up @@ -319,22 +313,3 @@ def to_api_dict(self) -> geoengine_openapi_client.Colorizer:
default_color=self.default_color,
no_data_color=self.no_data_color,
))


class RgbaColorizer(Colorizer):
'''A Rgba colorizer.'''

def __init__(self, no_data_color: Rgba = (0, 0, 0, 0)):
super().__init__(no_data_color)

@staticmethod
def from_response_rgba(_response: geoengine_openapi_client.RgbaColorizer) -> RgbaColorizer:
"""Create a colorizer from a response."""

return RgbaColorizer()

def to_api_dict(self) -> geoengine_openapi_client.Colorizer:
"""Return the colorizer as a dictionary."""
return geoengine_openapi_client.Colorizer(geoengine_openapi_client.RgbaColorizer(
type='rgba',
))
54 changes: 54 additions & 0 deletions geoengine/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,8 @@ def from_response(cls, response: geoengine_openapi_client.RasterColorizer) -> Ra

if isinstance(inner, geoengine_openapi_client.SingleBandRasterColorizer):
return SingleBandRasterColorizer.from_single_band_response(inner)
if isinstance(inner, geoengine_openapi_client.MultiBandRasterColorizer):
return MultiBandRasterColorizer.from_multi_band_response(inner)

raise GeoEngineException({"message": "Unknown RasterColorizer type"})

Expand Down Expand Up @@ -1009,6 +1011,58 @@ def to_api_dict(self) -> geoengine_openapi_client.RasterColorizer:
))


@dataclass
class MultiBandRasterColorizer(RasterColorizer):
'''A raster colorizer for multiple bands'''

blue_band: int
blue_max: float
blue_min: float
blue_scale: Optional[float]
green_band: int
green_max: float
green_min: float
green_scale: Optional[float]
red_band: int
red_max: float
red_min: float
red_scale: Optional[float]

@staticmethod
def from_multi_band_response(response: geoengine_openapi_client.MultiBandRasterColorizer) -> RasterColorizer:
return MultiBandRasterColorizer(
response.blue_band,
response.blue_max,
response.blue_min,
response.blue_scale,
response.green_band,
response.green_max,
response.green_min,
response.green_scale,
response.red_band,
response.red_max,
response.red_min,
response.red_scale
)

def to_api_dict(self) -> geoengine_openapi_client.RasterColorizer:
return geoengine_openapi_client.RasterColorizer(geoengine_openapi_client.MultiBandRasterColorizer(
type='multiBand',
blue_band=self.blue_band,
blue_max=self.blue_max,
blue_min=self.blue_min,
blue_scale=self.blue_scale,
green_band=self.green_band,
green_max=self.green_max,
green_min=self.green_min,
green_scale=self.green_scale,
red_band=self.red_band,
red_max=self.red_max,
red_min=self.red_min,
red_scale=self.red_scale
))


class RasterSymbology(Symbology):
'''A raster symbology'''
__opacity: float
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package_dir =
packages = find:
python_requires = >=3.9
install_requires =
geoengine-openapi-client == 0.0.13
geoengine-openapi-client @ git+https://github.com/geo-engine/openapi-client@multiband-colorizer#subdirectory=python # TODO update when merged
geopandas >=0.9,<0.15
matplotlib >=3.5,<3.8
numpy >=1.21,<2
Expand Down

0 comments on commit d80e984

Please sign in to comment.