I need to run a Propensity Score Analysis with forest loss in a given region between 2017 to 2020. I am new to GEE, and I can't seem to find out how to retrieve total loss from 2017-2020 for the ROI. Ultimately I need deforested area per pixel. I am using ArcGIS for data processing after exporting data from GEE. I tried this:

// Select lossyear band from Hansen and the total ROI

var hansen = hansen.select(['lossyear']).clip(intersection)

// Select relevant years and add them up into one image
var loss2017 = hansen.eq(17)
var loss2018 = hansen.eq(18)
var loss2019 = hansen.eq(19)
var loss2020 = hansen.eq(20)

var allyears = loss2017.add(loss2018).add(loss2019).add(loss2020); 

But it didn't seem right when I mapped it. I had used also

var lossImage = hansen.select(['loss']);
var lossAreaImage = lossImage.multiply(ee.Image.pixelArea()); 

in an attempt to export deforested pixels 2000-2020, but I ended up with total areas for every pixel, which I couldn't use.

How can I do this?

  • Do you want a single value? Like in the study area there were e.g. 500 pixels with forest loss? Or do you want only a mask, where every single pixel is either 0 (no loss) or 1 (loss)?
    – JonasV
    Jul 7, 2021 at 9:56
  • Yes the second one! A mask where every pixel is either 0 or 1 -- because then I need to randomly sample them for inference
    – Julia R.
    Jul 7, 2021 at 14:03

1 Answer 1


If I correctly understand your question that you want an image containing valid pixels where there was loss between 2017 and 2020, then I believe this would do it:

var hansenLossYear = ee.Image('UMD/hansen/global_forest_change_2020_v1_8').select('lossyear').selfMask()
var loss_2017_2020 = hansenLossYear.gte(ee.Image.constant(17)).and(hansenLossYear.lte(ee.Image.constant(20))).selfMask()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.