Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

The ff_analyze function is designed to calculate performance metrics for deforestation predictions. It compares predictions against ground truth data, optionally using a forest mask, and can analyze results for specific geographic areas. The function can save results to a CSV file and return spatial polygons with calculated scores.

Exercises

  1. Basic Usage:
    Analyze predictions against ground truth data.

library(ForestForesight)
library(terra)

# Assume we have prediction and ground truth rasters
predictions_raster <- rast("path/to/predictions.tif")
groundtruth_raster <- rast("path/to/groundtruth.tif")

analysis_results <- ff_analyze(
  predictions = predictions_raster,
  groundtruth = groundtruth_raster,
  verbose = TRUE
)

print(head(analysis_results))
  1. Using a Forest Mask:
    Include a forest mask in the analysis to focus on forested areas.

forest_mask <- rast("path/to/forest_mask.tif")

analysis_results <- ff_analyze(
  predictions = predictions_raster,
  groundtruth = groundtruth_raster,
  forestmask = forest_mask,
  verbose = TRUE
)

print(summary(analysis_results))
  1. Saving Results to CSV:
    Analyze predictions and save results to a CSV file.

ff_analyze(
  predictions = "path/to/predictions.tif",
  groundtruth = "path/to/groundtruth.tif",
  csvfile = "deforestation_analysis_results.csv",
  append = FALSE,
  verbose = TRUE
)

# Check if the CSV file was created
file.exists("deforestation_analysis_results.csv")
  1. Analysis for a Specific Country:
    Perform analysis for a specific country using ISO3 code.

analysis_results <- ff_analyze(
  predictions = predictions_raster,
  groundtruth = groundtruth_raster,
  country = "BRA",  # ISO3 code for Brazil
  verbose = TRUE
)

print(unique(analysis_results$iso3))
  1. Using Custom Analysis Polygons:
    Provide custom polygons for analysis instead of using default degree polygons.

custom_polygons <- vect("path/to/custom_analysis_polygons.shp")

analysis_results <- ff_analyze(
  predictions = predictions_raster,
  groundtruth = groundtruth_raster,
  analysis_polygons = custom_polygons,
  verbose = TRUE
)

plot(analysis_results, "TP")  # Plot True Positives
  1. Analyzing Multiple Dates:
    Perform analysis for multiple dates and append results to a single CSV file.

dates <- c("2023-01-01", "2023-06-01", "2023-12-01")

for (date in dates) {
  predictions_file <- paste0("predictions_", date, ".tif")
  groundtruth_file <- paste0("groundtruth_", date, ".tif")
  
  ff_analyze(
    predictions = predictions_file,
    groundtruth = groundtruth_file,
    date = date,
    csvfile = "multi_date_analysis_results.csv",
    append = TRUE,
    verbose = TRUE
  )
}

# Read and check the combined results
results <- read.csv("multi_date_analysis_results.csv")
print(table(results$date))

These exercises will help you understand how to use the ff_analyze function to evaluate deforestation predictions, work with different data formats, and analyze results across various spatial and temporal contexts. Remember to replace the placeholder file paths with actual paths to your ForestForesight data and results.

  • No labels

0 Comments

You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account.