@@ -3628,6 +3628,22 @@ class TestVectorCubeRunUDF:
3628
3628
- https://github.com/Open-EO/openeo-geopyspark-driver/issues/437
3629
3629
"""
3630
3630
3631
+ def _build_run_udf_callback (self , udf_code : str ) -> dict :
3632
+ udf_code = textwrap .dedent (udf_code )
3633
+ return {
3634
+ "process_graph" : {
3635
+ "runudf1" : {
3636
+ "process_id" : "run_udf" ,
3637
+ "arguments" : {
3638
+ "data" : {"from_parameter" : "data" },
3639
+ "udf" : udf_code ,
3640
+ "runtime" : "Python" ,
3641
+ },
3642
+ "result" : True ,
3643
+ }
3644
+ },
3645
+ }
3646
+
3631
3647
@pytest .mark .parametrize (
3632
3648
"dimension" ,
3633
3649
[
@@ -3636,40 +3652,32 @@ class TestVectorCubeRunUDF:
3636
3652
],
3637
3653
)
3638
3654
def test_apply_dimension_run_udf_change_geometry (self , api100 , dimension ):
3639
- udf_code = """
3640
- from openeo.udf import UdfData, FeatureCollection
3641
- def process_geometries(udf_data: UdfData) -> UdfData:
3642
- [feature_collection] = udf_data.get_feature_collection_list()
3643
- gdf = feature_collection.data
3644
- gdf["geometry"] = gdf["geometry"].buffer(distance=1, resolution=2)
3645
- udf_data.set_feature_collection_list([
3646
- FeatureCollection(id="_", data=gdf),
3647
- ])
3648
- """
3649
- udf_code = textwrap .dedent (udf_code )
3655
+ """VectorCube + apply_dimension + UDF (changing geometry)"""
3650
3656
process_graph = {
3651
- "get_vector_data" : {
3652
- "process_id" : "load_uploaded_files" ,
3653
- "arguments" : {"paths" : [str (get_path ("geojson/FeatureCollection02.json" ))], "format" : "GeoJSON" },
3657
+ "load" : {
3658
+ "process_id" : "load_geojson" ,
3659
+ "arguments" : {
3660
+ "data" : load_json ("geojson/FeatureCollection02.json" ),
3661
+ "properties" : ["pop" ],
3662
+ },
3654
3663
},
3655
3664
"apply_dimension" : {
3656
3665
"process_id" : "apply_dimension" ,
3657
3666
"arguments" : {
3658
- "data" : {"from_node" : "get_vector_data " },
3667
+ "data" : {"from_node" : "load " },
3659
3668
"dimension" : dimension ,
3660
- "process" : {
3661
- "process_graph" : {
3662
- "runudf1" : {
3663
- "process_id" : "run_udf" ,
3664
- "arguments" : {
3665
- "data" : {"from_node" : "get_vector_data" },
3666
- "udf" : udf_code ,
3667
- "runtime" : "Python" ,
3668
- },
3669
- "result" : True ,
3670
- }
3671
- },
3672
- },
3669
+ "process" : self ._build_run_udf_callback (
3670
+ """
3671
+ from openeo.udf import UdfData, FeatureCollection
3672
+ def process_geometries(udf_data: UdfData) -> UdfData:
3673
+ [feature_collection] = udf_data.get_feature_collection_list()
3674
+ gdf = feature_collection.data
3675
+ gdf["geometry"] = gdf["geometry"].buffer(distance=1, resolution=2)
3676
+ udf_data.set_feature_collection_list([
3677
+ FeatureCollection(id="_", data=gdf),
3678
+ ])
3679
+ """
3680
+ ),
3673
3681
},
3674
3682
"result" : True ,
3675
3683
},
@@ -3708,42 +3716,33 @@ def test_apply_dimension_run_udf_filter_on_geometries(self, api100, dimension):
3708
3716
Test to use `apply_dimension(dimension="...", process=UDF)` to filter out certain
3709
3717
entries from geometries dimension based on geometry (e.g. intersection with another geometry)
3710
3718
"""
3711
- udf_code = """
3712
- from openeo.udf import UdfData, FeatureCollection
3713
- import shapely.geometry
3714
- def process_geometries(udf_data: UdfData) -> UdfData:
3715
- [feature_collection] = udf_data.get_feature_collection_list()
3716
- gdf = feature_collection.data
3717
- to_intersect = shapely.geometry.box(4, 3, 8, 4)
3718
- gdf = gdf[gdf["geometry"].intersects(to_intersect)]
3719
- udf_data.set_feature_collection_list([
3720
- FeatureCollection(id="_", data=gdf),
3721
- ])
3722
- """
3723
- udf_code = textwrap .dedent (udf_code )
3724
3719
process_graph = {
3725
- "get_vector_data" : {
3726
- "process_id" : "load_uploaded_files" ,
3727
- "arguments" : {"paths" : [str (get_path ("geojson/FeatureCollection10.json" ))], "format" : "GeoJSON" },
3720
+ "load" : {
3721
+ "process_id" : "load_geojson" ,
3722
+ "arguments" : {
3723
+ "data" : load_json ("geojson/FeatureCollection10.json" ),
3724
+ "properties" : ["pop" ],
3725
+ },
3728
3726
},
3729
3727
"apply_dimension" : {
3730
3728
"process_id" : "apply_dimension" ,
3731
3729
"arguments" : {
3732
- "data" : {"from_node" : "get_vector_data " },
3730
+ "data" : {"from_node" : "load " },
3733
3731
"dimension" : dimension ,
3734
- "process" : {
3735
- "process_graph" : {
3736
- "runudf1" : {
3737
- "process_id" : "run_udf" ,
3738
- "arguments" : {
3739
- "data" : {"from_node" : "get_vector_data" },
3740
- "udf" : udf_code ,
3741
- "runtime" : "Python" ,
3742
- },
3743
- "result" : True ,
3744
- }
3745
- },
3746
- },
3732
+ "process" : self ._build_run_udf_callback (
3733
+ """
3734
+ from openeo.udf import UdfData, FeatureCollection
3735
+ import shapely.geometry
3736
+ def process_geometries(udf_data: UdfData) -> UdfData:
3737
+ [feature_collection] = udf_data.get_feature_collection_list()
3738
+ gdf = feature_collection.data
3739
+ to_intersect = shapely.geometry.box(4, 3, 8, 4)
3740
+ gdf = gdf[gdf["geometry"].intersects(to_intersect)]
3741
+ udf_data.set_feature_collection_list([
3742
+ FeatureCollection(id="_", data=gdf),
3743
+ ])
3744
+ """
3745
+ ),
3747
3746
},
3748
3747
"result" : True ,
3749
3748
},
@@ -3787,41 +3786,32 @@ def test_apply_dimension_run_udf_filter_on_properties(self, api100, dimension):
3787
3786
as apply_dimension only allows changing the cardinality of the provided dimension ("properties" in this case),
3788
3787
not any other dimension (like "geometries" in this case).
3789
3788
"""
3790
- udf_code = """
3791
- from openeo.udf import UdfData, FeatureCollection
3792
- import shapely.geometry
3793
- def process_geometries(udf_data: UdfData) -> UdfData:
3794
- [feature_collection] = udf_data.get_feature_collection_list()
3795
- gdf = feature_collection.data
3796
- gdf = gdf[gdf["pop"] > 500]
3797
- udf_data.set_feature_collection_list([
3798
- FeatureCollection(id="_", data=gdf),
3799
- ])
3800
- """
3801
- udf_code = textwrap .dedent (udf_code )
3802
3789
process_graph = {
3803
- "get_vector_data" : {
3804
- "process_id" : "load_uploaded_files" ,
3805
- "arguments" : {"paths" : [str (get_path ("geojson/FeatureCollection10.json" ))], "format" : "GeoJSON" },
3790
+ "load" : {
3791
+ "process_id" : "load_geojson" ,
3792
+ "arguments" : {
3793
+ "data" : load_json ("geojson/FeatureCollection10.json" ),
3794
+ "properties" : ["pop" ],
3795
+ },
3806
3796
},
3807
3797
"apply_dimension" : {
3808
3798
"process_id" : "apply_dimension" ,
3809
3799
"arguments" : {
3810
- "data" : {"from_node" : "get_vector_data " },
3800
+ "data" : {"from_node" : "load " },
3811
3801
"dimension" : dimension ,
3812
- "process" : {
3813
- "process_graph" : {
3814
- "runudf1" : {
3815
- "process_id" : "run_udf" ,
3816
- "arguments" : {
3817
- "data" : { "from_node" : "get_vector_data" },
3818
- "udf" : udf_code ,
3819
- "runtime" : "Python" ,
3820
- },
3821
- "result" : True ,
3822
- }
3823
- },
3824
- } ,
3802
+ "process" : self . _build_run_udf_callback (
3803
+ """
3804
+ from openeo.udf import UdfData, FeatureCollection
3805
+ import shapely.geometry
3806
+ def process_geometries(udf_data: UdfData) -> UdfData:
3807
+ [feature_collection] = udf_data.get_feature_collection_list()
3808
+ gdf = feature_collection.data
3809
+ gdf = gdf[gdf["pop"] > 500]
3810
+ udf_data.set_feature_collection_list([
3811
+ FeatureCollection(id="_", data=gdf) ,
3812
+ ])
3813
+ """
3814
+ ) ,
3825
3815
},
3826
3816
"result" : True ,
3827
3817
},
@@ -3859,41 +3849,32 @@ def test_apply_dimension_run_udf_add_properties(self, api100, dimension):
3859
3849
"""
3860
3850
Test to use `apply_dimension(dimension="...", process=UDF)` to add properties
3861
3851
"""
3862
- udf_code = """
3863
- from openeo.udf import UdfData, FeatureCollection
3864
- import shapely.geometry
3865
- def process_geometries(udf_data: UdfData) -> UdfData:
3866
- [feature_collection] = udf_data.get_feature_collection_list()
3867
- gdf = feature_collection.data
3868
- gdf["poppop"] = gdf["pop"] ** 2
3869
- udf_data.set_feature_collection_list([
3870
- FeatureCollection(id="_", data=gdf),
3871
- ])
3872
- """
3873
- udf_code = textwrap .dedent (udf_code )
3874
3852
process_graph = {
3875
- "get_vector_data" : {
3876
- "process_id" : "load_uploaded_files" ,
3877
- "arguments" : {"paths" : [str (get_path ("geojson/FeatureCollection02.json" ))], "format" : "GeoJSON" },
3853
+ "load" : {
3854
+ "process_id" : "load_geojson" ,
3855
+ "arguments" : {
3856
+ "data" : load_json ("geojson/FeatureCollection02.json" ),
3857
+ "properties" : ["pop" ],
3858
+ },
3878
3859
},
3879
3860
"apply_dimension" : {
3880
3861
"process_id" : "apply_dimension" ,
3881
3862
"arguments" : {
3882
- "data" : {"from_node" : "get_vector_data " },
3863
+ "data" : {"from_node" : "load " },
3883
3864
"dimension" : dimension ,
3884
- "process" : {
3885
- "process_graph" : {
3886
- "runudf1" : {
3887
- "process_id" : "run_udf" ,
3888
- "arguments" : {
3889
- "data" : { "from_node" : "get_vector_data" },
3890
- "udf" : udf_code ,
3891
- "runtime" : "Python" ,
3892
- },
3893
- "result" : True ,
3894
- }
3895
- },
3896
- } ,
3865
+ "process" : self . _build_run_udf_callback (
3866
+ """
3867
+ from openeo.udf import UdfData, FeatureCollection
3868
+ import shapely.geometry
3869
+ def process_geometries(udf_data: UdfData) -> UdfData:
3870
+ [feature_collection] = udf_data.get_feature_collection_list()
3871
+ gdf = feature_collection.data
3872
+ gdf["poppop"] = gdf["pop"] ** 2
3873
+ udf_data.set_feature_collection_list([
3874
+ FeatureCollection(id="_", data=gdf) ,
3875
+ ])
3876
+ """
3877
+ ) ,
3897
3878
},
3898
3879
"result" : True ,
3899
3880
},
0 commit comments