def test_hypercube_ndvi(self): """Test the hypercube NDVI computation""" dir = os.path.dirname(openeo_udf.functions.__file__) file_name = os.path.join(dir, "hypercube_ndvi.py") udf_code = UdfCode(language="python", source=open(file_name, "r").read()) hc_red = create_hypercube(name="red", value=1, shape=(3, 3, 3)) hc_nir = create_hypercube(name="nir", value=3, shape=(3, 3, 3)) udf_data = UdfData(proj={"EPSG":4326}, hypercube_list=[hc_red, hc_nir]) udf_request = UdfRequest(data=udf_data.to_dict(), code=udf_code) pprint.pprint(udf_request) response = self.app.post('/udf', data=json.dumps(udf_request), content_type="application/json") dict_data = json.loads(response.data) pprint.pprint(dict_data) self.checkHyperCube(dict_data=dict_data)
def test_hypercube_ndvi_message_pack(self): """Test the hypercube NDVI computation with the message pack protocol""" dir = os.path.dirname(openeo_udf.functions.__file__) file_name = os.path.join(dir, "hypercube_ndvi.py") udf_code = UdfCode(language="python", source=open(file_name, "r").read()) hc_red = create_hypercube(name="red", value=1, shape=(3, 3, 3)) hc_nir = create_hypercube(name="nir", value=3, shape=(3, 3, 3)) udf_data = UdfData(proj={"EPSG":4326}, hypercube_list=[hc_red, hc_nir]) udf_request = UdfRequest(data=udf_data.to_dict(), code=udf_code) # pprint.pprint(udf_request) udf_request = base64.b64encode(msgpack.packb(udf_request, use_bin_type=True)) response = self.app.post('/udf_message_pack', data=udf_request, content_type="application/base64") blob = base64.b64decode(response.data) dict_data = msgpack.unpackb(blob, raw=False) self.checkHyperCube(dict_data=dict_data)