forestatrisk.validate package¶
forestatrisk.validate.diffproj module¶
- mat_diffproj(input_raster, blk_rows=128)[source]¶
Compute a confusion matrix from a raster of differences.
This function computes a confusion matrix from a raster of differences. The raster of differences can be obtained using function
.r_diffproj()
.- Parameters:
input_raster – Raster of differences obtain with forestatrisk.r_projdiff.
- Returns:
A confusion matrix. [[np00, np01], [np10, np11]].
- r_diffproj(inputA, inputB, output_file='diffproj.tif', blk_rows=128)[source]¶
Compute a raster of differences for comparison.
This function compute a raster of differences between two rasters of future forest cover. Rasters must have the same extent and resolution.
- Parameters:
inputA – Path to first raster (predictions).
inputB – Path to second raster of (sd. predictions or observations).
output_file – Name of the output raster file for differences.
blk_rows – If > 0, number of rows for computation by block.
forestatrisk.validate.map_accuracy module¶
- map_accuracy(mat)[source]¶
Compute accuracy indices from a confusion matrix.
Compute Overall Accuracy, Expected Accuracy, Figure of Merit, Specificity, Sensitivity, True Skill Statistics and Cohen’s Kappa from a confusion matrix.
- Parameters:
mat – Confusion matrix. Format: [[n00, n01], [n10, n11]] with pred on lines and obs on columns.
- Returns:
A dictionnary of accuracy indices.
- map_confmat(r_obs0, r_obs1, r_pred0, r_pred1, blk_rows=0)[source]¶
Compute a confusion matrix.
This function computes a confusion matrix at a given resolution. Number of pixels in each category (0, 1) and in each spatial cell are given by r_obs* and r_pred* rasters.
- Parameters:
r_obs0 – Raster counting the number of 0 for observations.
r_obs1 – Raster counting the number of 1 for observations.
r_pred0 – Raster counting the number of 0 for predictions.
r_pred1 – Raster counting the number of 1 for predictions.
blk_rows – If > 0, number of lines per block.
- Returns:
A numpy array of shape (2,2).
forestatrisk.validate.map_validation module¶
- map_validation(pred, obs, blk_rows=128)[source]¶
Compute accuracy indices based on predicted and observed forest-cover change (fcc) maps.
Compute the Overall Accuracy, the Figure of Merit, the Specificity, the Sensitivity, the True Skill Statistics and the Cohen’s Kappa from a confusion matrix built on predictions vs. observations.
- Parameters:
pred – Raster of predicted fcc.
obs – Raster of observed fcc.
blk_rows – If > 0, number of rows for block (else 256x256).
- Returns:
A dictionnary of accuracy indices.
forestatrisk.validate.model_validation module¶
- accuracy_indices(pred, obs)[source]¶
Compute accuracy indices.
Compute the Overall Accuracy, the Figure of Merit, the Specificity, the Sensitivity, the True Skill Statistics and the Cohen’s Kappa from a confusion matrix built on predictions vs. observations.
- Parameters:
pred – List of predictions.
obs – List of observations.
- Returns:
A dictionnary of accuracy indices.
- computeAUC(pos_scores, neg_scores, n_sample=100000)[source]¶
Compute the AUC index.
Compute the Area Under the ROC Curve (AUC). See Liu et al. 2011.
- Parameters:
pos_scores – Scores of positive observations.
neg_scores – Scores of negative observations.
n_samples – Number of samples to approximate AUC.
- Returns:
AUC value.
- cross_validation(data, formula, mod_type='icar', ratio=30, nrep=5, seed=1234, icar_args={'beta_start': 0, 'burnin': 1000, 'mcmc': 1000, 'n_neighbors': None, 'neighbors': None, 'thin': 1}, rf_args={'n_estimators': 100, 'n_jobs': None})[source]¶
Model cross-validation
Performs model cross-validation.
- Parameters:
data – Full dataset.
formula – Model formula.
mod_type – Model type, can be either “icar”, “glm”, or “rf”.
ratio – Percentage of data used for testing.
nrep – Number of repetitions for cross-validation.
seed – Seed for reproducibility.
icar_args – Dictionnary of arguments for the binomial iCAR model.
rf_args – Dictionnary of arguments for the random forest model.
- Returns:
A Pandas data frame with cross-validation results.
forestatrisk.validate.resample_sum module¶
- coarsen_sum(a, c)[source]¶
Resample to coarser resolution using sum
This is an internal function used by resample_sum.
- Parameters:
a – 2D numpy array
c – Coarseness, in number of cells
- resample_sum(input_raster, output_raster, val=0, window_size=2)[source]¶
Resample to coarser resolution with counts.
This function resamples to coarser resolution counting pixel number having a given value. Window’s size is limited to 1000 pixels.
- Parameters:
input_raster – Path to input raster.
val – Pixel value to consider.
window_size – Size of the window in number of pixels.
output_raster – Path to output raster file.