Skip to content

Commit

Permalink
Revert "Add resampling and aggregation options to loadFromStac (GEO-B…
Browse files Browse the repository at this point in the history
…ON#169)"

This reverts commit 114470c.
  • Loading branch information
jmlord committed Oct 4, 2024
1 parent 34916d5 commit c827d9f
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 196 deletions.
158 changes: 17 additions & 141 deletions pipelines/SDM/SDM_maxEnt.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@
"data": {
"type": "options",
"value": "bootstrap",
"options": [
"bootstrap",
"crossvalidation",
"none"
]
"options": ["bootstrap", "crossvalidation", "none"]
}
},
{
Expand Down Expand Up @@ -135,12 +131,7 @@
"dragHandle": ".dragHandle",
"data": {
"type": "float[]",
"value": [
-2316297,
-1971146,
1015207,
1511916
]
"value": [-2316297, -1971146, 1015207, 1511916]
}
},
{
Expand Down Expand Up @@ -211,13 +202,7 @@
"data": {
"type": "options",
"value": "vif.cor",
"options": [
"vif.cor",
"vif.step",
"pearson",
"spearman",
"kendall"
]
"options": ["vif.cor", "vif.step", "pearson", "spearman", "kendall"]
}
},
{
Expand All @@ -231,11 +216,7 @@
"data": {
"type": "options",
"value": "pearson",
"options": [
"pearson",
"spearman",
"kendall"
]
"options": ["pearson", "spearman", "kendall"]
}
},
{
Expand Down Expand Up @@ -299,12 +280,7 @@
"data": {
"type": "options",
"value": "bbox",
"options": [
"box",
"mcp",
"buffer",
"bbox"
]
"options": ["box", "mcp", "buffer", "bbox"]
}
},
{
Expand Down Expand Up @@ -352,11 +328,7 @@
"dragHandle": ".dragHandle",
"data": {
"type": "text[]",
"value": [
"L",
"LQ",
"LQHP"
]
"value": ["L", "LQ", "LQHP"]
}
},
{
Expand All @@ -369,11 +341,7 @@
"dragHandle": ".dragHandle",
"data": {
"type": "float[]",
"value": [
0.5,
1,
2
]
"value": [0.5, 1, 2]
}
},
{
Expand All @@ -387,11 +355,7 @@
"data": {
"type": "options",
"value": "AUC",
"options": [
"p10",
"AIC",
"AUC"
]
"options": ["p10", "AIC", "AUC"]
}
},
{
Expand All @@ -405,12 +369,7 @@
"data": {
"type": "options",
"value": "lat_lon",
"options": [
"lat_lon",
"lon_lat",
"lon_lon",
"lat_lat"
]
"options": ["lat_lon", "lon_lat", "lon_lon", "lat_lat"]
}
},
{
Expand Down Expand Up @@ -447,9 +406,7 @@
"dragHandle": ".dragHandle",
"data": {
"type": "text[]",
"value": [
"Acer saccharum"
]
"value": ["Acer saccharum"]
}
},
{
Expand Down Expand Up @@ -519,55 +476,6 @@
"data": {
"descriptionFile": "data>GBIFHeatmapFromSTAC.yml"
}
},
{
"id": "131",
"type": "constant",
"position": {
"x": 181.433349609375,
"y": 369
},
"dragHandle": ".dragHandle",
"data": {
"type": "options",
"value": "near",
"options": [
"near",
"bilinear",
"average",
"mode",
"cubic",
"cubicspline",
"lanczos",
"rms",
"min",
"max",
"sum",
"med",
"q1",
"q3"
]
}
},
{
"id": "132",
"type": "constant",
"position": {
"x": 180.433349609375,
"y": 432
},
"dragHandle": ".dragHandle",
"data": {
"type": "options",
"value": "first",
"options": [
"first",
"min",
"max",
"mean",
"median"
]
}
}
],
"edges": [
Expand Down Expand Up @@ -927,30 +835,14 @@
"target": "130",
"targetHandle": "spatial_res",
"id": "reactflow__edge-128-130spatial_res"
},
{
"source": "131",
"sourceHandle": null,
"target": "119",
"targetHandle": "resampling",
"id": "reactflow__edge-131-119resampling"
},
{
"source": "132",
"sourceHandle": null,
"target": "119",
"targetHandle": "aggregation",
"id": "reactflow__edge-132-119aggregation"
}
],
"inputs": {
"pipeline@121": {
"label": "Taxa list",
"description": "Array of taxa values",
"type": "text[]",
"example": [
"Acer saccharum"
],
"example": ["Acer saccharum"],
"weight": 0
},
"SDM>selectBackground.yml@40|method_background": {
Expand Down Expand Up @@ -991,22 +883,14 @@
"label": "bbox",
"description": "Vector of float, bbox coordinates of the bbox in the order xmin, ymin, xmax, ymax",
"type": "float[]",
"example": [
-2316297,
-1971146,
1015207,
1511916
],
"example": [-2316297, -1971146, 1015207, 1511916],
"weight": 5
},
"data>pyLoadObservations>pyLoadObservations.yml@96|data_source": {
"description": "Source of the data (One of gbif_pc - Planetary computer or gbif_api - GBIF Download API)",
"label": "Data source",
"type": "options",
"options": [
"gbif_pc",
"gbif_api"
],
"options": ["gbif_pc", "gbif_api"],
"example": "gbif_api",
"weight": 6
},
Expand Down Expand Up @@ -1049,10 +933,7 @@
"description": "Vector of strings, collection name followed by '|' followed by item id",
"label": "collections_items",
"type": "text[]",
"example": [
"chelsa-clim|bio1",
"chelsa-clim|bio2"
],
"example": ["chelsa-clim|bio1", "chelsa-clim|bio2"],
"weight": 11
},
"data>loadFromStac.yml@119|mask": {
Expand Down Expand Up @@ -1090,9 +971,7 @@
"pipeline@121|defaultOutput": {
"label": "Species",
"description": "Species for which this model was run.",
"example": [
"Acer saccharum"
],
"example": ["Acer saccharum"],
"type": "text[]",
"weight": 0
},
Expand All @@ -1119,10 +998,7 @@
"description": "Model predictions from Maxent algorithm",
"label": "Predictions",
"type": "image/tiff;application=geotiff",
"range": [
0,
1
],
"range": [0, 1],
"weight": 4
},
"SDM>rangePredictions.yml@68|range_predictions": {
Expand Down Expand Up @@ -1152,4 +1028,4 @@
"license": "MIT",
"external_link": "https://github.com/GEO-BON/biab-2.0/blob/main/scripts/SDM/runMaxent.R"
}
}
}
87 changes: 87 additions & 0 deletions scripts/data/heatmapFromSTAC.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
## Script to download heatmaps from STAC
# and uses the 'predictors' argument

## Install required packages
packages <- c("terra", "rjson", "raster",
"stars", "gdalcubes", "rstac", "downloader")
new.packages <- packages[!(packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)

library("terra")
library("rjson")
library("raster")
library("stars")
library("rstac")
library("gdalcubes")
library("downloader")


setwd(outputFolder)

input <- fromJSON(file=file.path(outputFolder, "input.json"))
print("Inputs: ")
print(input)


stacURL <- "https://stac.geobon.org/"
taxa <- input$taxa

# Check if blank of NULL
# Sometimes it has more than one raster provided, so check ind 1
if(is.null(input$predictors[1]) || input$predictors[1]==""){
predictors <- NULL
}else{
predictors <- terra::rast(input$predictors)
}

fout <- file.path(outputFolder, paste0("heatmapGBIF-",taxa,".tif"))

if(!is.null(predictors)){
s <- stac(stacURL)

it_obj <- s |>
stac_search(collections=c('gbif_heatmaps'),limit=5000) |> get_request()

# Force each dataset to have the data role. Fix 08/2023
for (i in 1:length(it_obj$features)){
it_obj$features[[i]]$assets[[1]]$roles<-'data'
}

st <- gdalcubes::stac_image_collection(it_obj$features,asset_names=c("data"),
property_filter=function(f){f$taxa==taxa})

# Get extent
ee = as.list(ext(predictors))
names(ee) = c("left", "right", "bottom", "top")
# Add time
ee[["t0"]] = "2006-01-01"
ee[["t1"]] = "2006-01-01"

v = cube_view(srs = crs(predictors, proj = T),
extent = ee,
dx = xres(predictors), dy = yres(predictors), dt = "P1D",
aggregation= "mean", resampling = "bilinear")

gdalcubes_options(parallel=TRUE)

raster_cube(st, v) |>
write_tif(COG = TRUE, creation_options = list("COMPRESS" = "DEFLATE")) |>
terra::rast() -> raster.out

writeRaster(raster.out, fout, overwrite = T)

}else{
# Just download the file (some issues using rstac/gdalcubes)
dlink <- paste0(
"https://object-arbutus.cloud.computecanada.ca/bq-io/io/gbif_heatmaps/gbif_",
taxa,
"_density_06-2022.tif"
)

download(dlink, destfile = fout)
}


output <- list("raster" = fout)
jsonData <- toJSON(output, indent=2)
write(jsonData, file.path(outputFolder,"output.json"))
Binary file added scripts/data/heatmapGBIF-reptiles.tif
Binary file not shown.
Loading

0 comments on commit c827d9f

Please sign in to comment.