Skip to content

Commit

Permalink
opendatacube#656 Test animate config parameter
Browse files Browse the repository at this point in the history
Signed-off-by: Tisham Dhar <[email protected]>
  • Loading branch information
whatnick committed Jul 15, 2021
1 parent b8b5c71 commit 0c07e50
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions datacube_ows/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ def _write_png(data, style, extent_mask, qprof):
img_data = style.transform_data(data, mask)
qprof.end_event("apply-style")
qprof.start_event("write")
# TODO: Activate loop_over and animate flags for APNG
image = xarray_image_as_png(img_data, mask)
qprof.end_event("write")
return image
Expand Down
15 changes: 13 additions & 2 deletions datacube_ows/ogc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ def xarray_image_as_png(img_data, mask=None, loop_over=None, animate=False):
img_io.seek(0)
return img_io.read()

masked_data = _img2bands_array(img_data, mask, width, height)
masked_data = render_frame(img_data, mask, width, height)
if not loop_over and animate:
return masked_data
# TODO: Change PNG rendering to Pillow
Expand All @@ -569,7 +569,18 @@ def xarray_image_as_png(img_data, mask=None, loop_over=None, animate=False):
thing.write(masked_data)
return memfile.read()

def _img2bands_array(img_data, mask, width, height):
def render_frame(img_data, mask, width, height):
"""Render to a 3D numpy array an Xarray input with masking
Args:
img_data ([type]): Input 3D XArray
mask ([type]): Masking array, possibly None
width ([type]): Width of the frame to render
height ([type]): Height of the frame to render
Returns:
numpy.ndarray: 3D Rendered Xarray as numpy array
"""
masked = False
last_band = None
buffer = numpy.zeros((4, width, height), numpy.uint8)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_multidate_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ def __init__(self):
"aggregator_function": "datacube_ows.band_utils.multi_date_delta",
}

fake_cfg_anim = {
"allowed_count_range": [2,10],
"aggregator_function": "datacube_ows.band_utils.multi_date_pass",
"animate": True
}

fake_cfg_equal = {
"allowed_count_range": [1, 1],
"aggregator_function": "datacube_ows.band_utils.multi_date_delta",
Expand All @@ -55,6 +61,10 @@ def __init__(self):
assert isinstance(mdh.range_str(), str)
assert mdh.applies_to(2)
assert not mdh.applies_to(11)
assert not mdh.animate

mdh_anim = StyleDefBase.MultiDateHandler(FakeMdhStyle(), fake_cfg_anim)
assert mdh_anim.animate

mdh_equal = StyleDefBase.MultiDateHandler(FakeMdhStyle(), fake_cfg_equal)
assert isinstance(mdh_equal.range_str(), str)
Expand Down

0 comments on commit 0c07e50

Please sign in to comment.