Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docker/plumber.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ load_processes(api, processes_file)
#* @filter cors
function(req, res) {
print("CORS filter")
print(c(req$REQUEST_METHOD, req$PATH_INFO))
api_cors_handler(req, res, origin = "*", methods = "*")
}

Expand Down
18 changes: 14 additions & 4 deletions inst/demo-lps-2025/01_ml_api_eo_data_cubes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
},
{
"cell_type": "code",
"execution_count": 64,
"execution_count": null,
"id": "3843b5af",
"metadata": {},
"outputs": [],
Expand All @@ -99,7 +99,7 @@
},
{
"cell_type": "code",
"execution_count": 65,
"execution_count": 2,
"id": "71be7901",
"metadata": {},
"outputs": [],
Expand All @@ -111,6 +111,16 @@
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b02a117a",
"metadata": {},
"outputs": [],
"source": [
"print(connection.list_collections())"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -193,7 +203,7 @@
"source": [
"# Load a data cube\n",
"datacube = connection.load_collection(\n",
" collection_id=\"mpc/sentinel-2-l2a\",\n",
" collection_id=\"mpc-sentinel-2-l2a\",\n",
" spatial_extent={\"west\": -63.9, \"south\": -9.14, \"east\": -62.9, \"north\": -8.14},\n",
" temporal_extent=[\"2022-01-01\", \"2022-12-31\"]\n",
")"
Expand All @@ -210,7 +220,7 @@
" process_id=\"cube_regularize\",\n",
" arguments={\n",
" \"data\": datacube,\n",
" \"period\": \"P1M\", # Monthly regularization\n",
" \"period\": \"P16D\", # Monthly regularization\n",
" \"resolution\": 300\n",
" }\n",
")"
Expand Down
6 changes: 3 additions & 3 deletions inst/examples/01_ml_cube_regularize.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ p <- processes()
s2_reg <- p$export_cube(
data = p$cube_regularize(
data = p$load_collection(
id = "AWS/SENTINEL-2-L2A",
id = "mpc-sentinel-2-l2a",
spatial_extent = list(
west = -63.9, # rondonia area
east = -62.9,
Expand All @@ -21,11 +21,11 @@ s2_reg <- p$export_cube(
temporal_extent = list("2022-01-01", "2022-12-31"),
bands = list("B02","B03", "B04","B05","B06", "B07", "B08", "B11", "B12","B8A")
),
period = "P16D",
period = "P1M",
resolution = 320
),
name = "s2_cube",
folder = "openeocraft-cubes"
folder = "openeocraft-cubes-1M"
)


Expand Down
Binary file modified inst/ml/db.rds
Binary file not shown.
83 changes: 65 additions & 18 deletions inst/ml/processes.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,73 @@ load_collection <- function(id,
temporal_extent = NULL,
bands = NULL,
properties = NULL) {
base::print("load_collection()")
id <- base::strsplit(id, "/")[[1]]
source <- id[[1]]
collection <- id[[2]]
spatial_extent <- spatial_extent[c("west", "east", "south", "north")]
base::names(spatial_extent) <- c("lon_max", "lon_min", "lat_min", "lat_max")

data <- sits::sits_cube(
source = source,
collection = collection,
bands = bands,
roi = spatial_extent,
start_date = temporal_extent[[1]],
end_date = temporal_extent[[2]]
)
# Save roi for later
base::attr(data, "roi") <- spatial_extent
data
base::tryCatch(
{
base::print(">> load_collection() called")
base::print(base::paste(" collection_id:", id))
base::print(base::paste(" bands:", base::paste(bands, collapse = ", ")))
base::print(base::paste(" temporal_extent:", base::paste(temporal_extent, collapse = " to ")))
base::print(" spatial_extent:")
base::print(spatial_extent)

# Split ID like "mpc-sentinel-2-l2a" into source and collection
parts <- base::strsplit(id, "-", fixed = TRUE)[[1]]
if (base::length(parts) < 2) {
stop("Invalid collection ID. Expected format: 'source-collection'.")
}
source <- parts[[1]]
collection <- base::paste(parts[-1], collapse = "-")

# Ensure spatial_extent is a named list
if (!base::is.list(spatial_extent)) {
spatial_extent <- base::as.list(spatial_extent)
}

required_keys <- c("west", "east", "south", "north")
if (!base::all(required_keys %in% base::names(spatial_extent))) {
stop("Missing keys in spatial_extent. Expected: west, east, south, north")
}

spatial_extent <- base::list(
west = -63.9,
south = -9.14,
east = -62.9,
north = -8.14
)

roi <- base::list(
lon_max = spatial_extent[["west"]],
lon_min = spatial_extent[["east"]],
lat_min = spatial_extent[["south"]],
lat_max = spatial_extent[["north"]]
)

# Validate temporal_extent
if (!base::is.vector(temporal_extent) || base::length(temporal_extent) != 2) {
stop("temporal_extent must be a vector of length 2: [start_date, end_date]")
}

# Create the data cube
data <- sits::sits_cube(
source = source,
collection = collection,
bands = bands,
roi = roi,
start_date = temporal_extent[[1]],
end_date = temporal_extent[[2]]
)

base::attr(data, "roi") <- roi
return(data)
},
error = function(e) {
stop(base::paste("Error in load_collection():", e$message))
}
)
}



#* @openeo-process
mlm_class_random_forest <- function(num_trees = 100,
max_variables = "sqrt",
Expand Down
Loading