Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Feb 15, 2024
1 parent 6f384de commit ff97f3e
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions maps/Sudan/Darfur_area_estimate
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if (debug > 0){
print("Area (ha)", roi.area().divide(10000))
}

// 2. Color Palettes
// 2. Color Palettes
var palettes = require('users/gena/packages:palettes');
var classVis = {palette: palettes.cmocean.Speed[7].slice(0,-2)}
var classVis2 = {min: 0, max: 1.0, palette: ['yellow', 'green'], opacity: 0.8}
Expand All @@ -46,9 +46,9 @@ var cropPixels = {}
var nonCropPixels = {}
for (var key in roiDict){
var args = {
reducer: ee.Reducer.sum().unweighted(),
geometry: roiDict[key],
scale: 10,
reducer: ee.Reducer.sum().unweighted(),
geometry: roiDict[key],
scale: 10,
maxPixels: 1e12,
}
cropPixels[key] = ee.Number(mask.reduceRegion(args).get("classification"))
Expand All @@ -72,25 +72,25 @@ for (var key in roiDict){
var totalPixels = cropPixels[key].add(nonCropPixels[key])
if (debug > 0){
print("Total Pixels:", totalPixels)
print("Reference Crop Proportion", cropProportion)
print("Reference Crop Proportion", cropProportion)
}
var totalArea = totalPixels.divide(10e7)
var sampleBasedCropArea = cropProportion.multiply(totalArea)
print(key + " Sample Based Crop Area Estimate (Mha) ", sampleBasedCropArea)

// 6. Prepare values for equation
var testSamples = referenceSamples.filter(ee.Filter.or(
ee.Filter.eq("subset", "testing"),
ee.Filter.eq("subset", "testing"),
ee.Filter.eq("subset", "validation")
))
// Get map classification
testSamples = mask.sampleRegions({collection: testSamples, scale: 10})
var W_0 = nonCropPixels[key].divide(totalPixels)
var W_1 = cropPixels[key].divide(totalPixels)
var n_0_ = testSamples.filter("classification == 0").size()
var n_1_ = testSamples.filter("classification == 1").size()
var n_01 = testSamples.filter("classification == 0").filter("label == 1").size()
var n_0_ = testSamples.filter("classification == 0").size()
var n_1_ = testSamples.filter("classification == 1").size()

var n_01 = testSamples.filter("classification == 0").filter("label == 1").size()
var n_11 = testSamples.filter("classification == 1").filter("label == 1").size()
var p_01 = W_0.multiply(n_01.divide(n_0_))
var p_11 = W_1.multiply(n_11.divide(n_1_))
Expand All @@ -100,18 +100,13 @@ for (var key in roiDict){
var numerator1 = (W_1.multiply(p_11)).subtract(p_11.pow(ee.Number(2)))
var denominator0 = n_0_.subtract(ee.Number(1))
var denominator1 = n_1_.subtract(ee.Number(1))

var sum0 = numerator0.divide(denominator0)
var sum1 = numerator1.divide(denominator1)

var standardError = (sum0.add(sum1)).sqrt()
var standardErrorArea = totalArea.multiply(standardError)
var confidenceInterval = ee.Number(1.96).multiply(standardErrorArea)
print(key + " 95% Confidence Interval", confidenceInterval)

}





}

0 comments on commit ff97f3e

Please sign in to comment.