示例#1
0
    def test_rct_stats(self):
        """Test the raster collection tile statistics UDF"""

        dir = os.path.dirname(openeo_udf.functions.__file__)
        file_name = os.path.join(dir, "raster_collections_statistics.py")
        udf_code = UdfCode(language="python",
                           source=open(file_name, "r").read())
        udf_data = PIXEL

        udf_request = UdfRequest(data=udf_data, code=udf_code)
        print(udf_request)

        response = self.app.post('/udf',
                                 data=json.dumps(udf_request),
                                 content_type="application/json")
        result = json.loads(response.data)
        pprint.pprint(result)

        self.assertEqual(len(result["feature_collection_tiles"]), 0)
        self.assertEqual(len(result["raster_collection_tiles"]), 0)
        self.assertEqual(len(result["structured_data_list"]), 1)
        self.assertEqual(result["structured_data_list"][0]["type"], "dict")
        self.assertEqual(result["structured_data_list"][0]["data"]["NIR"], {
            'max': 9.0,
            'mean': 6.0,
            'min': 3.0,
            'sum': 24.0
        })
        self.assertEqual(result["structured_data_list"][0]["data"]["RED"], {
            'max': 10.0,
            'mean': 7.0,
            'min': 4.0,
            'sum': 28.0
        })
示例#2
0
    def test_buffer(self):
        """Test the feature collection buffering UDF"""

        dir = os.path.dirname(openeo_udf.functions.__file__)
        file_name = os.path.join(dir, "feature_collections_buffer.py")
        udf_code = UdfCode(language="python",
                           source=open(file_name, "r").read())
        udf_data = FEATURE

        udf_request = UdfRequest(data=udf_data, code=udf_code)
        print(udf_request)

        response = self.app.post('/udf',
                                 data=json.dumps(udf_request),
                                 content_type="application/json")
        result = json.loads(response.data)
        pprint.pprint(result)

        self.assertEqual(len(result["feature_collection_tiles"]), 1)
        self.assertEqual(
            len(result["feature_collection_tiles"][0]["data"]["features"]), 2)
        self.assertEqual(
            result["feature_collection_tiles"][0]["data"]["features"][0]
            ["properties"], {
                'a': 1,
                'b': 'a'
            })
        self.assertEqual(
            result["feature_collection_tiles"][0]["data"]["features"][1]
            ["properties"], {
                'a': 2,
                'b': 'b'
            })
示例#3
0
    def test_sampling(self):
        """Test the feature collection sampling UDF"""

        dir = os.path.dirname(openeo_udf.functions.__file__)
        file_name = os.path.join(dir, "raster_collections_sampling.py")
        udf_code = UdfCode(language="python",
                           source=open(file_name, "r").read())
        udf_data = PIXEL_FEATURE

        udf_request = UdfRequest(data=udf_data, code=udf_code)
        print(udf_request)

        response = self.app.post('/udf',
                                 data=json.dumps(udf_request),
                                 content_type="application/json")
        result = json.loads(response.data)
        pprint.pprint(result)

        self.assertEqual(len(result["feature_collection_tiles"]), 1)
        self.assertEqual(
            len(result["feature_collection_tiles"][0]["data"]["features"]), 3)
        self.assertEqual(
            result["feature_collection_tiles"][0]["data"]["features"][0]
            ["properties"], {
                'NIR_0': 4,
                'NIR_1': 6,
                "NIR_2": 1,
                "RED_0": 3,
                "RED_1": 8
            })
        self.assertEqual(
            result["feature_collection_tiles"][0]["data"]["features"][1]
            ["properties"], {
                'NIR_0': 1,
                'NIR_1': 8,
                "NIR_2": 0,
                "RED_0": 4,
                "RED_1": 10
            })
        self.assertEqual(
            result["feature_collection_tiles"][0]["data"]["features"][2]
            ["properties"], {
                'NIR_0': None,
                'NIR_1': None,
                "NIR_2": None,
                "RED_0": None,
                "RED_1": None
            })
示例#4
0
    def test_pytorch_linear_nn(self):
        """Test linear pytorch model training and UDF application"""

        model = SimpleNetwork()

        MachineLearningPytorchTestCase.train_pytorch_model(model=model)

        dir = os.path.dirname(openeo_udf.functions.__file__)
        file_name = os.path.join(dir, "raster_collections_pytorch_ml.py")
        udf_code = UdfCode(language="python", source=open(file_name, "r").read())
        udf_data = PIXEL

        udf_request = UdfRequest(data=udf_data, code=udf_code)

        response = self.app.post('/udf', data=json.dumps(udf_request), content_type="application/json")
        result = json.loads(response.data)
        pprint.pprint(result)
示例#5
0
    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)
示例#6
0
    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)
示例#7
0
    def test_ndvi(self):
        """Test the time reduce sum UDF"""

        dir = os.path.dirname(openeo_udf.functions.__file__)
        file_name = os.path.join(dir, "raster_collections_ndvi.py")
        udf_code = UdfCode(language="python",
                           source=open(file_name, "r").read())
        udf_data = PIXEL

        udf_request = UdfRequest(data=udf_data, code=udf_code)
        print(udf_request)

        response = self.app.post('/udf',
                                 data=json.dumps(udf_request),
                                 content_type="application/json")
        result = json.loads(response.data)
        pprint.pprint(result)

        self.assertEqual(len(result["raster_collection_tiles"]), 1)
        self.assertEqual(result["raster_collection_tiles"][0]["data"],
                         [[[-0.25, 0.0]], [[0.0, -0.1111111111111111]]])
示例#8
0
 def test_sklearn_extra_tree_message_pack(self):
     """Test extra tree training and UDF application"""
     model = ExtraTreesRegressor(n_estimators=100,
                                 max_depth=7,
                                 max_features="log2",
                                 min_samples_split=2,
                                 min_samples_leaf=1,
                                 verbose=0)
     MachineLearningTestCase.train_sklearn_model(model=model)
     dir = os.path.dirname(openeo_udf.functions.__file__)
     file_name = os.path.join(dir, "raster_collections_sklearn_ml.py")
     udf_code = UdfCode(language="python",
                        source=open(file_name, "r").read())
     udf_data = PIXEL
     udf_request = UdfRequest(data=udf_data, code=udf_code)
     blob = base64.b64encode(msgpack.packb(udf_request, use_bin_type=True))
     response = self.app.post('/udf_message_pack',
                              data=blob,
                              content_type="application/base64")
     result = msgpack.unpackb(base64.b64decode(response.data), raw=False)
     self.assertAlmostEqual(
         result["raster_collection_tiles"][0]["data"][0][0][0], 3.0, 2)
     self.assertAlmostEqual(
         result["raster_collection_tiles"][0]["data"][1][0][0], 5.0, 2)
示例#9
0
 def test_sklearn_extra_tree(self):
     """Test extra tree training and UDF application"""
     model = ExtraTreesRegressor(n_estimators=100,
                                 max_depth=7,
                                 max_features="log2",
                                 min_samples_split=2,
                                 min_samples_leaf=1,
                                 verbose=0)
     MachineLearningTestCase.train_sklearn_model(model=model)
     dir = os.path.dirname(openeo_udf.functions.__file__)
     file_name = os.path.join(dir, "raster_collections_sklearn_ml.py")
     udf_code = UdfCode(language="python",
                        source=open(file_name, "r").read())
     udf_data = PIXEL
     udf_request = UdfRequest(data=udf_data, code=udf_code)
     response = self.app.post('/udf',
                              data=json.dumps(udf_request),
                              content_type="application/json")
     result = json.loads(response.data)
     pprint.pprint(result)
     self.assertAlmostEqual(
         result["raster_collection_tiles"][0]["data"][0][0][0], 3.0, 2)
     self.assertAlmostEqual(
         result["raster_collection_tiles"][0]["data"][1][0][0], 5.0, 2)
示例#10
0
    def test_pixel_min_mean_max_sum(self):
        """Test the time reduce min, max, mean, sum UDF"""

        dir = os.path.dirname(openeo_udf.functions.__file__)
        file_name = os.path.join(
            dir, "raster_collections_reduce_time_min_max_mean_sum.py")
        udf_code = UdfCode(language="python",
                           source=open(file_name, "r").read())
        udf_data = PIXEL

        udf_request = UdfRequest(data=udf_data, code=udf_code)
        print(udf_request)

        response = self.app.post('/udf',
                                 data=json.dumps(udf_request),
                                 content_type="application/json")
        result = json.loads(response.data)
        pprint.pprint(result)

        self.assertEqual(len(result["raster_collection_tiles"]), 8)
        self.assertEqual(result["raster_collection_tiles"][0]["data"],
                         [[[5.0, 4.0]]])
        self.assertEqual(result["raster_collection_tiles"][1]["data"],
                         [[[9.0, 10.0]]])
        self.assertEqual(result["raster_collection_tiles"][2]["data"],
                         [[[14.0, 14.0]]])
        self.assertEqual(result["raster_collection_tiles"][3]["data"],
                         [[[7.0, 7.0]]])
        self.assertEqual(result["raster_collection_tiles"][4]["data"],
                         [[[3.0, 4.0]]])
        self.assertEqual(result["raster_collection_tiles"][5]["data"],
                         [[[9.0, 8.0]]])
        self.assertEqual(result["raster_collection_tiles"][6]["data"],
                         [[[12.0, 12.0]]])
        self.assertEqual(result["raster_collection_tiles"][7]["data"],
                         [[[6.0, 6.0]]])