diff --git a/docker/plumber.R b/docker/plumber.R index eb95fed..4366425 100644 --- a/docker/plumber.R +++ b/docker/plumber.R @@ -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 = "*") } diff --git a/inst/demo-lps-2025/01_ml_api_eo_data_cubes.ipynb b/inst/demo-lps-2025/01_ml_api_eo_data_cubes.ipynb index 1580659..c8b07a5 100644 --- a/inst/demo-lps-2025/01_ml_api_eo_data_cubes.ipynb +++ b/inst/demo-lps-2025/01_ml_api_eo_data_cubes.ipynb @@ -86,7 +86,7 @@ }, { "cell_type": "code", - "execution_count": 64, + "execution_count": null, "id": "3843b5af", "metadata": {}, "outputs": [], @@ -99,7 +99,7 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 2, "id": "71be7901", "metadata": {}, "outputs": [], @@ -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, @@ -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", ")" @@ -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", ")" diff --git a/inst/examples/01_ml_cube_regularize.R b/inst/examples/01_ml_cube_regularize.R index dbfc271..3a53180 100644 --- a/inst/examples/01_ml_cube_regularize.R +++ b/inst/examples/01_ml_cube_regularize.R @@ -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, @@ -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" ) diff --git a/inst/ml/db.rds b/inst/ml/db.rds index a8cdef2..1154ff2 100644 Binary files a/inst/ml/db.rds and b/inst/ml/db.rds differ diff --git a/inst/ml/processes.R b/inst/ml/processes.R index 8ccb07c..80597c2 100644 --- a/inst/ml/processes.R +++ b/inst/ml/processes.R @@ -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",