-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path01a_fragmentation_edgeArea.js
179 lines (143 loc) · 6.55 KB
/
01a_fragmentation_edgeArea.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// ecosystem fragmentation - edge effect // gt degradaçao - mapbiomas //
// any issue, bug or report write to [email protected] and/or [email protected]
// set version
var version = 1;
// -- * definitions
// set classes in which edge area will be applied
// 3 (forest), 4 (savanna), 5 (mangrove), 6 (flooded forest), 11 (wetland), 12 (grassland)
var native_classes = {
'amazonia': [3, 4, 5, 6, 11, 12, 49, 50],
'caatinga': [3, 4, 5, 11, 12, 49, 50],
'cerrado': [3, 4, 5, 11, 12, 49, 50],
'mata_atlantica': [3, 4, 5, 11, 12, 49, 50],
'pampa': [3, 4, 5, 11, 12, 49, 50],
'pantanal': [3, 4, 5, 11, 12, 49, 50]
};
// dset classes to be ignored (which doesn't produces edge area)
// 13 (other non forest), 29 (rocky outcrop), 32 (hypersaline tidal flat), 33 (water)
var ignore_classes = {
'amazonia': [13, 29, 32, 33],
'caatinga': [13, 29, 32, 33],
'cerrado': [13, 29, 32, 33],
'mata_atlantica': [13, 29, 32, 33],
'pampa': [13, 29, 32, 33],
'pantanal': [13, 29, 32, 33]
};
// definir conjunto de distancias (em metros) para estimar a área sobre efeito de borda
var edge_rules = [30, 60, 90, 120, 150, 300, 600, 1000];
// Set years to be processed
var years_list = [1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
2018, 2019, 2020, 2021, 2022, 2023];
// * -- end of definitions
// * -- ingest infrastructure data
//var dnit_roads = ee.Image('projects/mapbiomas-workspace/DEGRADACAO/INFRASTRUCTURE/dnit_roads_image');
//Map.addLayer(dnit_roads, {}, 'Estradas');
// * -- end o f infrastructure data
// read biomes
var biomes = ee.Image('projects/mapbiomas-workspace/AUXILIAR/biomas-2019-raster');
//Map.addLayer(biomes.randomVisualizer(),{}, 'Biomas');
// build biomes dictionary
var biomes_name = ['amazonia', 'caatinga', 'cerrado', 'mata_atlantica', 'pampa', 'pantanal'];
var biomes_dict = {
'amazonia': 1,
'caatinga': 5,
'cerrado': 4,
'mata_atlantica': 2,
'pampa': 6,
'pantanal': 3
};
// for each edge rule (distance)
edge_rules.forEach(function(distance_i) {
// build recipes
var edge_degrad = ee.Image([]);
var edge_anthropogenic = ee.Image([]);
// for each year
years_list.forEach(function(year_j) {
// build recipes
var edge_degrad_year = ee.Image(0);
var edge_anthropogenic_year = ee.Image(0);
// read collection
var collection = ee.Image('projects/mapbiomas-public/assets/brazil/lulc/collection9/mapbiomas_collection90_integration_v1')
.select('classification_' + year_j);
//.blend(dnit_roads);
// for each biome, compute fragmentation by using specific criteria
biomes_name.forEach(function(biome_k) {
// get native vegetation map
var native_mask = collection
.remap({from: native_classes[biome_k].concat(ignore_classes[biome_k]),
to: native_classes[biome_k].concat(ignore_classes[biome_k]),
defaultValue: 21
})
// add infrastructure
//.blend(dnit_roads.remap([1], [21]))
.updateMask(biomes.eq(biomes_dict[biome_k]));
// mask collection to retain raw classes
var collection_i = collection.updateMask(native_mask.neq(21));
//Map.addLayer(collection_i.randomVisualizer(), {}, year_i + ' ' + distance_i + ' ' + biome_k);
// -- * get edge effect
// retain anthropogenic classes to be used as reference for the edge
var anthropogenic = native_mask.updateMask(native_mask.eq(21));
// compute edge
var edge = anthropogenic.distance(ee.Kernel.euclidean(distance_i + 10, 'meters'), false);
edge = edge.mask(edge.lt(distance_i)).mask(collection).selfMask().updateMask(biomes.eq(biomes_dict[biome_k]));
// remove edges over ignored classes
ignore_classes[biome_k].forEach(function(class_m) {
edge = edge.updateMask(collection_i.neq(class_m));
});
// compute classes that causes edge effect (1px)
if (distance_i === 30) {
var edge_out = edge.distance(ee.Kernel.euclidean(35, 'meters'), false);
edge_out = edge_out.mask(edge_out.lt(distance_i)).mask(anthropogenic).selfMask().updateMask(biomes.eq(biomes_dict[biome_k]));
// blend into recipe
edge_anthropogenic_year = edge_anthropogenic_year.blend(edge_out).selfMask();
//Map.addLayer(edge_out.randomVisualizer())
// bind into recipe
//edge_anthropogenic = edge_anthropogenic.addBands(anthropogenic_estimate);
}
// blend edge into recipe
edge_degrad_year = edge_degrad_year.blend(edge).selfMask();
//edge_degrad = edge_degrad.addBands(edge_estimate);
});
// Retain classes from edge, build-up data and store into recipe
var inner = collection.updateMask(edge_degrad_year)
.rename('edge_' + distance_i + 'm_' + year_j);
var out = collection.updateMask(edge_anthropogenic_year)
.rename('pressure_' + distance_i + 'm_' + year_j);
//Map.addLayer(inner.randomVisualizer(), {}, year_j + ' inner ' + distance_i);
//Map.addLayer(out.randomVisualizer(), {}, year_j + ' out ' + distance_i);
// Build images to export
edge_degrad = edge_degrad.addBands(inner);
edge_anthropogenic = edge_anthropogenic.addBands(out);
});
// Set properties
edge_degrad = edge_degrad.set({'version': version})
.set({'distance': distance_i});
edge_anthropogenic = edge_anthropogenic.set({'version': version})
.set({'distance': distance_i});
// Export
print(edge_degrad, edge_anthropogenic);
// Edge area
Export.image.toAsset({
image: edge_degrad,
description: 'edge_' + distance_i + 'm_col9_v' + version,
assetId: 'projects/mapbiomas-workspace/DEGRADACAO/COLECAO/BETA/PROCESS/edge_area/' + 'edge_' + distance_i + 'm_col9_v' + version,
region: biomes.geometry(),
scale: 30,
maxPixels: 1e13,
priority: 999
});
// Pressure class
if (distance_i === 30) {
Export.image.toAsset({
image: edge_anthropogenic,
description: 'pressure_' + distance_i + 'm_col9_v' + version,
assetId: 'projects/mapbiomas-workspace/DEGRADACAO/COLECAO/BETA/PROCESS/edge_pressure/' + 'pressure_' + distance_i + 'm_col9_v' + version,
region: biomes.geometry(),
scale: 30,
maxPixels: 1e13,
priority: 999
});
}
});