Skip to content

Commit

Permalink
ml_predict process
Browse files Browse the repository at this point in the history
ml_predict process
  • Loading branch information
PondiB authored Aug 14, 2024
2 parents 6ad1922 + e126019 commit f104d84
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docker-compose-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ jobs:
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Run docker-compose
run: docker-compose up -d
- name: Run docker compose
run: docker compose up -d
4 changes: 2 additions & 2 deletions .github/workflows/docker-compose-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ jobs:
push: true
tags: brianpondi/openeocubes:latest

- name: Run docker-compose
run: docker-compose up -d
- name: Run docker compose
run: docker compose up -d
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Imports:
gdalcubes,
rstac
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Collate:
'api_process_graphs.R'
'api_job.R'
Expand Down
2 changes: 2 additions & 0 deletions R/api.R
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ addEndpoint = function() {
Session$assignProcess(multiply)
Session$assignProcess(divide)
Session$assignProcess(evi)
# assign ml processes
Session$assignProcess(ml_predict)


}
80 changes: 80 additions & 0 deletions R/ml-processes.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,84 @@
NULL




#' ml_datacube_schema
#' @description Return a list with datacube description and schema
#'
#' @return datacube list
ml_datacube_schema <- function() {
info <- list(
description = "A data cube with the predicted values. It removes the specified dimensions and adds new dimension for the predicted values.",
schema = list(type = "object", subtype = "raster-cube")
)
return(info)
}

#' ml_model_schema
#' @description Return a list with datacube description and schema
#'
#' @return model list
ml_model_schema <- function() {
info <- list(
description = "A ML model that was trained with one of the ML training processes.",
schema = list(type = "object", subtype = "mlm-model")
)
return(info)
}

#' return objects for the processes
eo_datacube <- ml_datacube_schema()
ml_model <- ml_model_schema()


#' TO DO : Implement machine learning processes
#'


#' ml_predict
ml_predict <- Process$new(
id = "ml_predict",
description = "Applies a machine learning model to a data cube of input features and returns the predicted values.",
categories = as.array("cubes"),
summary = "Predict using ML",
parameters = list(
Parameter$new(
name = "data",
description = "A data cube with bands.",
schema = list(
type = "object",
subtype = "raster-cube"
)
),
Parameter$new(
name = "model",
description = "The current name of the dimension.",
schema = ml_model,
optional = FALSE
),
Parameter$new(
name = "dimensions",
description = "Zero or more dimensions that will be reduced by the model. Fails with a `DimensionNotAvailable` exception if one of the specified dimensions does not exist.",
schema = list(
type = list("string", "array")
),
optional = FALSE
)
),
returns = eo_datacube,
operation = function(data, model, dimension = NULL) {
tryCatch({
prediction <- gdalcubes::predict(aoi_cube, model)
print(prediction)
message("Prediction calculated ....")
message(gdalcubes::as_json(prediction))

return(prediction)
},
error = function(e){
message("Error in prediction: ")
message(conditionMessage(e))
})
}
)
8 changes: 7 additions & 1 deletion man/eo_datacube.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions man/ml_datacube_schema.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions man/ml_model_schema.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions man/ml_predict.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f104d84

Please sign in to comment.