Skip to content

Instantly share code, notes, and snippets.

@JeroenVerstraelen
Created May 6, 2024 07:29
Show Gist options
  • Save JeroenVerstraelen/b26d89cf9c84e2dc4435fb47802ebaed to your computer and use it in GitHub Desktop.
Save JeroenVerstraelen/b26d89cf9c84e2dc4435fb47802ebaed to your computer and use it in GitHub Desktop.
OpenEO randomforest inference
import shapely
from shapely.geometry import Polygon, MultiPolygon
import openeo
from openeo.rest.job import JobResults
from openeo.rest.mlmodel import MlModel
from openeo.rest.job import BatchJob, JobResults
from openeo.rest.mlmodel import MlModel
c = openeo.connect("https://openeo.dev.warsaw.openeo.dataspace.copernicus.eu/openeo/").authenticate_oidc()
signed_url = "https://openeo.dataspace.copernicus.eu/openeo/1.2/jobs/j-24050486ed974fdc80e73eff53974d89/results/items/ZTNlOGRjZjMtYWM3Yy00NmMzLThiZGQtMDM0YmYyMmRjMzQy/322cfe4d8974a52f84ff8a30475568d4/ml_model_metadata.json?expires=1715585149"
model = MlModel.load_ml_model(connection=c, id=signed_url)
cube = c.load_collection(
"SENTINEL2_L2A",
temporal_extent=["2020-12-30", "2022-01-01"],
spatial_extent={
'west': 3.39,
'east': 3.61,
'south': 51.09,
'north': 51.21
},
bands=["B02", "B03", "B04"]
)
cube_xyb = cube.reduce_dimension(dimension="t", reducer="mean")
predicted = cube_xyb.predict_random_forest(
model=model,
dimension="bands"
)
predicted.execute_batch("predicted.GTiff", validate=None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment