diff --git a/pipelines/BII.json b/pipelines/BII.json index 85f33bc8..319d5c85 100644 --- a/pipelines/BII.json +++ b/pipelines/BII.json @@ -26,8 +26,8 @@ "id": "16", "type": "output", "position": { - "x": 1009, - "y": 164 + "x": 1060, + "y": 110 }, "data": { "label": "Output" @@ -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": [ @@ -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": { @@ -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": [ @@ -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", @@ -156,8 +193,8 @@ "2015", "2020" ], - "weight": 6, - "example": null + "example": "2020", + "weight": 6 } }, "outputs": { @@ -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 } } } \ No newline at end of file diff --git a/scripts/BII/BIIChange.R b/scripts/BII/BIIChange.R index 101a9d5e..59610478 100644 --- a/scripts/BII/BIIChange.R +++ b/scripts/BII/BIIChange.R @@ -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 \ No newline at end of file +jsonData <- toJSON(output, indent=2) +write(jsonData, file.path(outputFolder,"output.json")) \ No newline at end of file diff --git a/scripts/BII/BIIChange.yml b/scripts/BII/BIIChange.yml index 89d1e386..62a909bc 100644 --- a/scripts/BII/BIIChange.yml +++ b/scripts/BII/BIIChange.yml @@ -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 diff --git a/scripts/BII/BIIZonalStats.yml b/scripts/BII/BIIZonalStats.yml index 8a40fe25..5e42c91d 100644 --- a/scripts/BII/BIIZonalStats.yml +++ b/scripts/BII/BIIZonalStats.yml @@ -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