-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
679f33c
commit ef3cf59
Showing
3 changed files
with
68 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,4 +182,5 @@ catboost_info/catboost_training.json | |
*.tar | ||
*.zip | ||
|
||
.notebook-tests/ | ||
.notebook-tests/ | ||
.local-presto-test/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"""Perform cropland mapping inference using a local execution of presto. | ||
Make sure you test this script on the Python version 3.9+, and have worldcereal | ||
This comment has been minimized.
Sorry, something went wrong. |
||
dependencies installed with the presto wheel file installed with it's dependencies. | ||
""" | ||
|
||
from pathlib import Path | ||
|
||
import requests | ||
import xarray as xr | ||
from openeo_gfmap.features.feature_extractor import ( | ||
EPSG_HARMONIZED_NAME, | ||
apply_feature_extractor_local, | ||
) | ||
|
||
from worldcereal.openeo.feature_extractor import PrestoFeatureExtractor | ||
|
||
TEST_FILE_URL = "https://artifactory.vgt.vito.be/artifactory/auxdata-public/worldcereal/presto/localtestdata/local_presto_inputs.nc" | ||
TEST_FILE_PATH = Path.cwd() / "presto_test_inputs.nc" | ||
|
||
|
||
if __name__ == "__main__": | ||
if not TEST_FILE_PATH.exists(): | ||
print("Downloading test input data...") | ||
# Download the test input data | ||
with requests.get(TEST_FILE_URL, stream=True, timeout=180) as response: | ||
response.raise_for_status() | ||
with open(TEST_FILE_PATH, "wb") as f: | ||
for chunk in response.iter_content(chunk_size=8192): | ||
f.write(chunk) | ||
|
||
print("Loading array in-memory...") | ||
arr = ( | ||
xr.open_dataset(TEST_FILE_PATH) | ||
.to_array(dim="bands") | ||
.drop_sel(bands="crs") | ||
.astype("uint16") | ||
) | ||
|
||
print("Running presto UDF locally") | ||
features = apply_feature_extractor_local( | ||
PrestoFeatureExtractor, | ||
arr, | ||
parameters={EPSG_HARMONIZED_NAME: 32631, "ignore_dependencies": True}, | ||
) | ||
|
||
features.to_netcdf(Path.cwd() / "presto_test_features.nc") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 comment
on commit ef3cf59
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now the local test only does presto feature extraction, no catboost inference yet, right?
backend is at python=3.8 and I think we made everything compatible to 3.8