From 6fdf4f639de0b593c09ef65126950e14b1dffd9a Mon Sep 17 00:00:00 2001 From: Emile Sonneveld Date: Tue, 19 Mar 2024 14:54:27 +0100 Subject: [PATCH] Add test for loading ml model with results url. https://github.com/Open-EO/openeo-geopyspark-driver/issues/562 --- .../randomforest_ml_model_results.json | 95 +++++++++++++++++++ tests/test_integration.py | 23 +++++ 2 files changed, 118 insertions(+) create mode 100644 tests/data/mlmodels/randomforest_ml_model_results.json diff --git a/tests/data/mlmodels/randomforest_ml_model_results.json b/tests/data/mlmodels/randomforest_ml_model_results.json new file mode 100644 index 0000000..7fa1507 --- /dev/null +++ b/tests/data/mlmodels/randomforest_ml_model_results.json @@ -0,0 +1,95 @@ +{ + "assets": { + "randomforest.model.tar.gz": { + "file:size": 666, + "href": "https://github.com/Open-EO/openeo-geopyspark-integrationtests/raw/master/tests/data/mlmodels/randomforest.model.tar.gz", + "roles": [ + "data" + ], + "title": "randomforest.model.tar.gz", + "type": "application/octet-stream" + } + }, + "description": "This is an artificial results file for testing.", + "extent": { + "spatial": { + "bbox": [ + [ + 3.4, + 51.1, + 3.6, + 51.2 + ] + ] + }, + "temporal": { + "interval": [ + [ + "2018-03-01T00:00:00Z", + "2018-10-31T00:00:00Z" + ] + ] + } + }, + "id": "j-57bd02e55b364f9d9c9cc919e5fd4afc", + "license": "proprietary", + "links": [ + { + "href": "urn:eop:VITO:TERRASCOPE_S2_TOC_V2:S2B_20181023T105109_31UES_TOC_V200", + "rel": "derived_from", + "title": "Derived from urn:eop:VITO:TERRASCOPE_S2_TOC_V2:S2B_20181023T105109_31UES_TOC_V200", + "type": "application/json" + }, + { + "href": "urn:eop:VITO:TERRASCOPE_S2_TOC_V2:S2B_20181026T110129_31UES_TOC_V200", + "rel": "derived_from", + "title": "Derived from urn:eop:VITO:TERRASCOPE_S2_TOC_V2:S2B_20181026T110129_31UES_TOC_V200", + "type": "application/json" + }, + { + "href": "https://openeo-dev.vito.be/openeo/1.2/jobs/j-2403137d68e0467d81ba6f03e70f0e0e/results", + "rel": "self", + "type": "application/json" + }, + { + "href": "https://openeo-dev.vito.be/openeo/1.2/jobs/j-2403137d68e0467d81ba6f03e70f0e0e/results/YzkwNzQyODYzMmI0NmNiNDA2ZWYwMmEwMWE0YTVkYzM0YWVkYWQzNzAzNjlkN2I5ZDVjMzE0YTNiNjY2ZmQwM0BlZ2kuZXU=/d768733e986cf6cb542f4db1c611ea9d?expires=1711449373", + "rel": "canonical", + "type": "application/json" + }, + { + "href": "http://ceos.org/ard/files/PFS/SR/v5.0/CARD4L_Product_Family_Specification_Surface_Reflectance-v5.0.pdf", + "rel": "card4l-document", + "type": "application/pdf" + }, + { + "href": "https://openeo-dev.vito.be/openeo/1.2/jobs/j-2403137d68e0467d81ba6f03e70f0e0e/results/items/YzkwNzQyODYzMmI0NmNiNDA2ZWYwMmEwMWE0YTVkYzM0YWVkYWQzNzAzNjlkN2I5ZDVjMzE0YTNiNjY2ZmQwM0BlZ2kuZXU=/1612fa1ac689e7052651db3ca3037e1e/ml_model_metadata.json?expires=1711449373", + "rel": "item", + "type": "application/json" + } + ], + "openeo:status": "finished", + "providers": [ + {} + ], + "stac_extensions": [ + "https://stac-extensions.github.io/eo/v1.1.0/schema.json", + "https://stac-extensions.github.io/file/v2.1.0/schema.json", + "https://stac-extensions.github.io/processing/v1.1.0/schema.json", + "https://stac-extensions.github.io/projection/v1.1.0/schema.json", + "https://stac-extensions.github.io/ml-model/v1.0.0/schema.json" + ], + "stac_version": "1.0.0", + "summaries": { + "ml-model:architecture": [ + "random-forest" + ], + "ml-model:learning_approach": [ + "supervised" + ], + "ml-model:prediction_type": [ + "classification" + ] + }, + "title": "random_forest.py", + "type": "Collection" +} \ No newline at end of file diff --git a/tests/test_integration.py b/tests/test_integration.py index b7a6e64..d8cc19f 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -807,6 +807,29 @@ def test_random_forest_load_from_http(auth_connection: openeo.Connection, tmp_pa assert_geotiff_basics(with_link_output_file, min_width = 15, min_height = 15) +@pytest.mark.batchjob +@pytest.mark.timeout(BATCH_JOB_TIMEOUT) +def test_random_forest_load_from_http_results(auth_connection: openeo.Connection, tmp_path): + """ + Make predictions with the random forest model using a http link to the batch job results. + """ + + topredict_xybt = auth_connection.load_collection('PROBAV_L3_S10_TOC_333M', bands=["NDVI"], + spatial_extent={"west": 4.785919, "east": 4.909629, + "south": 51.259766, "north": 51.307638}, + temporal_extent=["2017-11-01", "2017-11-01"]) + topredict_cube_xyb = topredict_xybt.reduce_dimension(dimension="t", reducer="mean") + # Make predictions with the random forest model using http link. + random_forest_metadata_link = "https://github.com/Open-EO/openeo-geopyspark-integrationtests/raw/master/tests/data/mlmodels/randomforest_ml_model_results.json" + predicted_with_link = topredict_cube_xyb.predict_random_forest( + model=random_forest_metadata_link, + dimension="bands" + ) + with_link_output_file = tmp_path / "predicted_with_link.tiff" + predicted_with_link.download(with_link_output_file, format="GTiff") + assert_geotiff_basics(with_link_output_file, min_width=15, min_height=15) + + @pytest.mark.batchjob @pytest.mark.timeout(BATCH_JOB_TIMEOUT) def test_random_forest_train_and_load_from_jobid(auth_connection: openeo.Connection, tmp_path):