Skip to content

Commit

Permalink
Add raster color ramping, bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
j9ac9k committed Feb 18, 2025
1 parent f7ad566 commit 06d70a4
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 48 deletions.
2 changes: 1 addition & 1 deletion eptium/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# Copyright (c) Ognyan Moore.
# Distributed under the terms of the Modified BSD License.

__version__ = "0.1.2"
__version__ = "0.1.3"
17 changes: 0 additions & 17 deletions eptium/template_state.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
{
"ramps": [
{
"id": "black-to-white",
"name": "Black to white",
"expression": "rgb( ${T} * 255, ${T} * 255, ${T} * 255 )"
},
{
"id": "blue-to-red",
"name": "Blue to red",
"expression": "rgb( max(0, cos((1 - ${T} - 2 / 6) * Math.PI)) * 255, max(0, cos((1 - ${T} - 3 / 6) * Math.PI)) * 255, max(0, cos((1 - ${T} - 4 / 6) * Math.PI)) * 255 )"
},
{
"id": "pink-to-yellow",
"name": "Pink to yellow",
"expression": "rgb( (${T} < 0.5 ? 1 - 2 * ${T} : 2 * ${T} - 1) * 255, (${T} < 0.5 ? 1.5 * ${T} : 0.5 + 0.5 * ${T}) * 255, (${T} < 0.5 ? 0.5 + (0.5 * (1 - ${T})) : 1.5 * (1 - ${T})) * 255 )"
}
],
"groups": [
{
"isOpen": true,
Expand Down
93 changes: 63 additions & 30 deletions eptium/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,19 @@ def _setColorOn(self, attribute: str):
# TODO: insert checks to ensure attribute is one of the supported ones
self.state['groups'][0]['colorId'] = attribute

def _setColorRamp(self, ramp: str):
def _setPointCloudColorRamp(self, ramp: str):
group = self.state['groups'][0]
colors = group['colors']
for color in colors:
if color['id'] == group['colorId'] and color['type'] == 'continuous':
color['rampId'] = ramp


def _setRasterColorRamp(self, ramp: str):
group = self.state['rasterGroups'][0]
colors = group['colors']
for color in colors:
if color['id'] == group['colorId'] and color['type'] == 'continuous':
color['rampId'] = ramp

def _addPath(self, path: str | pathlib.Path ):
if isinstance(path, pathlib.Path):
Expand Down Expand Up @@ -183,10 +188,8 @@ def _addPath(self, path: str | pathlib.Path ):
path = f"{server['url']}files/{path}?{params}"

# append resource


_, _, extension = path.rpartition(".")
if extension == "tif":
if extension.startswith("tif"):
# geotiff
resource = {
"id": str(uuid.uuid4()),
Expand All @@ -213,7 +216,8 @@ def render(
path: str | pathlib.Path | list[str | pathlib.Path],
height: str | int = '600px',
color_on: str = "elevation",
color_ramp: str | None = None,
color_ramp_pc: str | None = None,
color_ramp_raster: str | None = None,
viewBounds: tuple[float, float, float, float] | None = None,
wireFrame: bool = False
):
Expand All @@ -224,34 +228,61 @@ def render(
path : str | pathlib.Path
Path to the asset that Eptium should display. Acceptable
values include local file paths, or URLs to
height : int | str
height : int | str, default='600px'
Accepted values are used to set the ``height`` attribute
of an iframe. Defaults to ``600px``.
color_on : str
of an iframe.
color_on : str, default='elevation'
Attribute to set the coloring based off. Possible values include
* rgb
* elevation (default)
* intensity
* classification
* return-type
* return-number
* return-count
* scan-angle
* post-source-id
* fixed
color_ramp : str
Color ramp to set the coloring based off. Possible values include
* black-to-white
* blue-to-red
* pink-to-yellow
* rgb
* elevation (default)
* intensity
* classification
* return-type
* return-number
* return-count
* scan-angle
* post-source-id
* fixed
color_ramp_pc : str
Color ramp to set the coloring for point clouds. Possible values include
* viridis
* magma
* plasma
* inferno
* cividis
* turbo
* dem-screen
* usgs
* black-to-white
* blue-to-red
* pink-to-yellow
Default value depends on what the ``color_on`` attribute is set to.
This setting only applies to ``color_on`` attributes that are continuous.
Those include
* elevation
* intensity
* scan-angle
viewBounds : (float, float, float, float), Optional
* elevation
* intensity
* scan-angle
color_ramp_raster : str, default='dem-screen'
Color ramp to set the coloring for rasters. Possible values include
* viridis
* magma
* plasma
* inferno
* cividis
* turbo
* dem-screen
* usgs
* black-to-white
* blue-to-red
* pink-to-yellow
viewBounds : (float, float, float, float), Optional, default=None
Bounding box in EPSG:4326 to set the initial view to. If not specified,
view will center about the resource being displayed.
wireFrame : bool, default False
Expand All @@ -264,9 +295,11 @@ def render(
self._addPath(path)
self._setHeight(height)
self._setColorOn(color_on)
if color_ramp is not None:
if color_ramp_pc is not None:
# needs to happen after _setColorOn
self._setColorRamp(color_ramp)
self._setPointCloudColorRamp(color_ramp_pc)
if color_ramp_raster is not None:
self._setRasterColorRamp(color_ramp_raster)
if viewBounds is not None:
self._setBoundingGeometry(*viewBounds)

Expand Down

0 comments on commit 06d70a4

Please sign in to comment.