Skip to content

Commit

Permalink
DAS-2180: Extracts get_harmony_message_from_params
Browse files Browse the repository at this point in the history
Also adds back __init__.py to get tests running locally. (outside of docker and
workflows)
  • Loading branch information
flamingbear committed Jul 30, 2024
1 parent bdde01e commit 257a462
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
24 changes: 2 additions & 22 deletions hybig/browse.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from rioxarray import open_rasterio
from xarray import DataArray

from hybig.browse_utility import get_harmony_message_from_params
from hybig.color_utility import (
NODATA_IDX,
NODATA_RGBA,
Expand Down Expand Up @@ -127,28 +128,7 @@ def create_browse(
)
"""
if params is None:
params = {}
mime = params.get('mime', 'image/png')
crs = params.get('crs', None)
scale_extent = params.get('scale_extent', None)
scale_size = params.get('scale_size', None)
height = params.get('height', None)
width = params.get('width', None)

harmony_message = HarmonyMessage(
{
"format": {
"mime": mime,
"crs": crs,
"srs": crs,
"scaleExtent": scale_extent,
"scaleSize": scale_size,
"height": height,
"width": width,
},
}
)
harmony_message = get_harmony_message_from_params(params)

if logger is None:
logger = getLogger('hybig-py')
Expand Down
34 changes: 34 additions & 0 deletions hybig/browse_utility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Module containing utility functionality for browse generation."""

from harmony.message import Message as HarmonyMessage


def get_harmony_message_from_params(params: dict | None) -> HarmonyMessage:
"""Constructs a harmony message from the input parms.
We have to create a harmony message to pass to the create_browse_imagery
function so that both the library and service calls are identical.
"""
if params is None:
params = {}
mime = params.get('mime', 'image/png')
crs = params.get('crs', None)
scale_extent = params.get('scale_extent', None)
scale_size = params.get('scale_size', None)
height = params.get('height', None)
width = params.get('width', None)

return HarmonyMessage(
{
"format": {
"mime": mime,
"crs": crs,
"srs": crs,
"scaleExtent": scale_extent,
"scaleSize": scale_size,
"height": height,
"width": width,
},
}
)
Empty file added tests/unit/__init__.py
Empty file.

0 comments on commit 257a462

Please sign in to comment.