Skip to content

Commit

Permalink
BII pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
JoryGriffith committed Oct 17, 2024
1 parent 09b0462 commit 31338d6
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 27 deletions.
55 changes: 49 additions & 6 deletions pipelines/BII.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"id": "16",
"type": "output",
"position": {
"x": 1009,
"y": 164
"x": 1060,
"y": 110
},
"data": {
"label": "Output"
Expand All @@ -54,6 +54,28 @@
"data": {
"label": "Output"
}
},
{
"id": "19",
"type": "io",
"position": {
"x": 1113.046875,
"y": 196
},
"data": {
"descriptionFile": "BII>BIIChange.yml"
}
},
{
"id": "20",
"type": "output",
"position": {
"x": 1698.046875,
"y": 201
},
"data": {
"label": "Output"
}
}
],
"edges": [
Expand Down Expand Up @@ -91,6 +113,20 @@
"target": "18",
"targetHandle": null,
"id": "reactflow__edge-15rasters-18"
},
{
"source": "15",
"sourceHandle": "rasters",
"target": "19",
"targetHandle": "rasters",
"id": "reactflow__edge-15rasters-19rasters"
},
{
"source": "19",
"sourceHandle": "bii_change",
"target": "20",
"targetHandle": null,
"id": "reactflow__edge-19bii_change-20"
}
],
"inputs": {
Expand Down Expand Up @@ -134,7 +170,8 @@
"weight": 4,
"example": null
},
"BII>BIIZonalStats.yml@15|start_year": {
"BII>BIIChange.yml@19|start_year": {
"description": "Reference BII year for raster plotting",
"label": "Start year for BII raster comparison",
"type": "options",
"options": [
Expand All @@ -146,7 +183,7 @@
"example": "2000",
"weight": 5
},
"BII>BIIZonalStats.yml@15|end_year": {
"BII>BIIChange.yml@19|end_year": {
"description": "BII layer to compare to the start year",
"label": "End year for BII comparison",
"type": "options",
Expand All @@ -156,8 +193,8 @@
"2015",
"2020"
],
"weight": 6,
"example": null
"example": "2020",
"weight": 6
}
},
"outputs": {
Expand All @@ -178,6 +215,12 @@
"label": "Rasters",
"type": "image/tiff;application=geotiff[]",
"weight": 2
},
"BII>BIIChange.yml@19|bii_change": {
"description": "Raster plot of change in BII",
"label": "Change in BII",
"type": "image/tiff;application=geotiff[]",
"weight": 3
}
}
}
29 changes: 28 additions & 1 deletion scripts/BII/BIIChange.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
# This is to look at change in BII over time
library("rjson")
library("terra")
library("dplyr")

source(paste(Sys.getenv("SCRIPT_LOCATION"), "/data/loadFromStacFun.R", sep = "/"))

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

output<- tryCatch({

start_yr <- paste0("bii_nhm_10km_", input$start_year)
end_yr <- paste0("bii_nhm_10km_", input$end_year)

# Load rasters as a raster stack
rasters <- terra::rast(c(input$rasters))
print(names(rasters))

first_raster <- rasters[[names(rasters)==start_yr]]
end_raster <- rasters[[names(rasters)==end_yr]]

print(names(first_raster))
# Summarise
bii_change <- first_raster-end_raster

# Output
bii_change_path <- file.path(outputFolder, "BII_change.tif")
writeRaster(bii_change, bii_change_path)

output <- list("bii_change"=bii_change_path)
}, error = function(e) { list(error = conditionMessage(e)) })

# Output
jsonData <- toJSON(output, indent=2)
write(jsonData, file.path(outputFolder,"output.json"))
6 changes: 6 additions & 0 deletions scripts/BII/BIIChange.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

script: BIIChange.R
name: Biodiversity Intactness Index Change
description: "Look at change in the Biodiversity Intactness Index over time."
author:
- name: Jory Griffith
identifier: https://orcid.org/0000-0001-6020-6690
inputs:
rasters:
label: Rasters of BII
Expand Down
20 changes: 0 additions & 20 deletions scripts/BII/BIIZonalStats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,6 @@ inputs:
- Median
- Mode
example: Mean
start_year:
label: Start year for BII raster comparison
type: options
description: Reference BII year for raster plotting
options:
- "2000"
- "2005"
- "2010"
- "2015"
example: "2000"
end_year:
label: End year for BII comparison
description: BII layer to compare to the start year
type: options
options:
- "2005"
- "2010"
- "2015"
- "2020"
example: "2020"
outputs:
rasters:
label: Rasters
Expand Down

0 comments on commit 31338d6

Please sign in to comment.