89_Simple
89_Simple

Reputation: 3805

conditional disaggregation of coarse raster to high resolution raster

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:

  1. 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)
    
  2. 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
    
  3. 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)
    
  4. 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

Answers (0)

Related Questions