Last active
July 7, 2025 20:16
-
-
Save richpsharp/c6d9543f73231b5eb5818e79a1370111 to your computer and use it in GitHub Desktop.
"Fragmentation Index" using global pasture watch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var grassland_fragmentation = function(aoi, year) | |
{ | |
var global_pasture_watch = ee.ImageCollection('projects/global-pasture-watch/assets/ggc-30m/v1/grassland_c'); | |
var clipped_gpw = global_pasture_watch.filterDate(year + '-01-01', (year + 1) + '-01-01').first().clip(aoi); | |
// Anything > 1 is grassland "i.e. rangeland" | |
var grassland = clipped_gpw.gte(1); | |
//original code made a 7x7 square kernel on 10m, so we're doing a 3x3 for 30m as close enough | |
var kernel8 = ee.Kernel.square({radius: 1, units: 'pixels', normalize: false }); | |
var grassDensity = grassland.reduceNeighborhood({ reducer: ee.Reducer.mean(), kernel: kernel8}); | |
// the old code declared betweeen 0.3 and 0.6 was fragmented | |
var fragmentedRangeland = grassDensity.gt(0.3).and(grassDensity.lte(0.6)); | |
return fragmentedRangeland; | |
} | |
var years = [2000, 2005, 2010, 2015, 2020]; | |
years.forEach(function(year) { | |
var result = grassland_fragmentation(soknot.geometry(), year); | |
Export.image.toCloudStorage({ | |
image: result.toByte(), // Convert to byte for smaller export size | |
description: 'gpw_frag_index_' + year, | |
bucket: 'ecoshard-root', | |
fileNamePrefix: 'gpw_frag_index/gpw_frag_index_' + year, | |
region: soknot.geometry(), | |
scale: 30, | |
crs: 'EPSG:4326', | |
maxPixels: 1e13 | |
}); | |
// Optionally visualize each year: | |
Map.addLayer(result, {min: 0, max: 1, palette: ['black', 'yellow']}, 'Fragmented Grassland ' + year); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment