forestatrisk.predict package¶
forestatrisk.predict.interpolate_rho module¶
- interpolate_rho(rho, input_raster, output_file='output/rho.tif', csize_orig=10, csize_new=1)[source]¶
Resample rho values with interpolation.
This function resamples the spatial random effects (rho values) obtained from an iCAR model. It performs a cubicspline interpolation at a finer resolution and smoothens the rho values.
- Parameters:
rho – Original rho values estimates with the iCAR model.
input_raster – Path to input raster defining the region.
output_file – Path to output raster file with resampled rho values.
csize_orig – Original size of the spatial cells (in km).
csize_new – New size of the spatial cells for cubicspline interpolation (in km).
forestatrisk.predict.predict_raster module¶
- predict_raster(model, _x_design_info, var_dir='data', input_forest_raster='data/forest.tif', output_file='predictions.tif', blk_rows=128, verbose=True)[source]¶
Predict the spatial probability of deforestation from a statistical model.
This function predicts the spatial probability of deforestation from a statistical model. Computation are done by block and can be performed on large geographical areas.
- Parameters:
model – The model (glm, rf) to predict from. Must have a model.predict_proba() function.
_x_design_info – Design matrix information from patsy.
var_dir – Directory with rasters (.tif) of explicative variables.
input_forest_raster – Path to forest raster (1 for forest).
output_file – Name of the output raster file for predictions.
blk_rows – If > 0, number of rows for computation by block.
verbose – Logical. Whether to print messages or not. Default to
True
.
forestatrisk.predict.predict_raster_binomial_iCAR module¶
- predict_binomial_iCAR(model, new_data, rhos)[source]¶
Function to return the predictions of a model_binomial_iCAR model.
Function to return the predictions of a model_binomial_iCAR model for a new data-set. In this function, rho values for spatial cells are directly provided and not obtained from the model.
- Parameters:
model – The model_binomial_iCAR model to predict from.
new_data – Pandas DataFrame including explicative variables.
rhos – Spatial random effects for each observation (row) in new_data.
- Returns:
Predictions (probabilities).
- predict_raster_binomial_iCAR(model, var_dir='data', input_cell_raster='output/rho.tif', input_forest_raster='data/forest.tif', output_file='output/pred_binomial_iCAR.tif', blk_rows=128, verbose=True)[source]¶
Predict the spatial probability of deforestation from a model.
This function predicts the spatial probability of deforestation from a model_binomial_iCAR model. Computation are done by block and can be performed on large geographical areas.
- Parameters:
model – The model_binomial_iCAR model to predict from.
var_dir – Directory with rasters (.tif) of explicative variables.
input_cell_raster – Path to raster of rho values for spatial cells.
input_forest_raster – Path to forest raster (1 for forest).
output_file – Name of the raster file to output the probability map.
blk_rows – If > 0, number of rows for computation by block.
verbose – Logical. Whether to print messages or not. Default to
True
.
forestatrisk.predict.wrast_rho module¶
- wrast_rho(rho, input_raster, csize=10, output_file='output/rho_orig.tif')[source]¶
Write rho values to GeoTIFF.
This function writes rho values (spatial random effects) to a GeoTIFF raster file.
- Parameters:
rho – original rho values estimates with the iCAR model.
input_raster – path to input raster defining the region.
- Csize:
size of the spatial cells (in km).
- Output_file:
path to output raster file.