Reputation: 3805
I have a raster that tells me fraction burnt area in a cell
class : SpatRaster
dimensions : 128, 256, 1 (nrow, ncol, nlyr)
resolution : 1.40625, 1.400437 (x, y)
extent : -180.7031, 179.2969, -89.62795, 89.62795 (xmin, xmax, ymin, ymax)
coord. ref. : lon/lat WGS 84 (EPSG:4326)
source : BurntArea.tif
name : BurntArea
min value : 0.0000000
max value : 0.8538834
I have another raster which is a fine resolution and a binary 1 and 0. 1 implies that pixel is burnable and 0 implies it is unburnable
class : SpatRaster
dimensions : 64800, 129600, 1 (nrow, ncol, nlyr)
resolution : 0.002777778, 0.002777778 (x, y)
extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
coord. ref. : lon/lat WGS 84 (EPSG:4326)
source : binary_raster
name : binary_raster
min value : 0
max value : 1
I want to disaggregate burnt area
to the binary
layer to only those cells which are burnable i.e. have a value of 1. When disaggregating burnt area to the binary layer 1, I need to distribute it equally to all cells equal to 1. I am thinking the best way to do this is:
Do a zonal stats first to calculate number of burnable pixels (binarylayer = 1) in each coarse burnt area cell
count_brpixel <- terra::zonal(binary_raster, BurntArea, fun = "sum", as.raster = T)
Divide the burnt area by total number of burnable pixels such that I get burnt area per burnable pixel
burnt_per_pixel <- BurntArea/count_brpixel
Disaggregate burnt_per_pixel at the same resolution as the binary_raster
res_drop <- res(binary_raster)[1]/res(BurntArea)[1]
burnt_per_pixel_disagg <- terra::disagg(burnt_per_pixel, fact = res_drop)
Multiply burnt_per_pixel_disagg with binary raster.
final_file <- burnt_per_pixel_disagg * binary_raster
The final_file contains the burntarea in a high resolution
I am actually stuck on step (1) where I get the Error: [zonal] extents do not match
. At this point, I don't even know if the rest of steps will generate any error or whether this is right way to go about this. Any help is appreciated.
Upvotes: 0
Views: 104