-
Notifications
You must be signed in to change notification settings - Fork 1
/
03b_fireAge.js
111 lines (92 loc) · 2.91 KB
/
03b_fireAge.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
// get fire age with native coverage (runs in native level)
// by: IPAM, [email protected]
// any issue and/or bug, please report to [email protected] and [email protected]
// --- --- --- DATASETS
// read coverage by mapbiomas collection 9
var coverage = ee.Image('projects/mapbiomas-public/assets/brazil/lulc/collection9/mapbiomas_collection90_integration_v1');
// --- --- FIRE AGE
// read age fire by mapbiomas fogo collection 3.1
var age = ee.Image('projects/mapbiomas-public/assets/brazil/fire/collection3_1/mapbiomas_fire_collection31_time_after_fire_v1');
// get geometry for export params
var region = coverage.geometry();
// --- --- --- PROCESS
// formated image for age information
var fire_age = age
// .slice(0,-1);
// .aside(print);
// --- --- NATIVE COVERAGE
// set classes to be computed native coverage
// 3 (forest), 4 (savanna), 5 (mangrove), 6 (flooded forest), 11 (wetland), 12 (grassland)
var native_classes = [3, 4, 5, 6, 11, 12, 49, 50];
// set native coverage image
var native_coverage = ee.Image(
ee.List(native_classes).iterate(function(current,previous){
var i = ee.Number(current);
var before = ee.Image(previous)
.where(coverage.eq(i),i);
return before;
},
coverage.multiply(0)
)
).selfMask()
.slice(1);
// --- --- CROSSING
var fire_age_native_coverege = fire_age
.multiply(100)
// .unmask(0)
.add(native_coverage);
var oldBands = fire_age_native_coverege.bandNames();
var newBands = oldBands.iterate(function(current,previous){
return ee.List(previous)
.add(ee.String('age_').cat(ee.String(current).slice(-4)));
},[]);
fire_age_native_coverege = fire_age_native_coverege
.select(oldBands,newBands);
print('fire_age_native_coverege',fire_age_native_coverege);
// --- --- --- PLOT
var visParams = {
coverage:{
min:0,
max:62,
palette:[],
bands:['classification_2022']
},
age:{
min:0,
max:3800,
palette:[],
bands:['age_2022']
},
age_2:{
min:0,
max:38,
palette:[],
bands:['classification_2022']
}
};
Map.addLayer(region,{},'region',false);
Map.addLayer(coverage,visParams.coverage,'coverage');
Map.addLayer(native_coverage,visParams.coverage,'native_coverage');
Map.addLayer(fire_age_native_coverege,visParams.age,'fire_age_native_coverege');
Map.addLayer(fire_age,visParams.age_2,'fire_age');
// --- --- --- EXPORT
// Set properties in metadata image
var properties = {
'version':1,
'product':'age'
};
// set export image
var recipe = fire_age_native_coverege.set(properties);
var description = 'age_col9_v'+properties.version;
var assetId = 'projects/mapbiomas-workspace/DEGRADACAO/COLECAO/BETA/PROCESS/fire/' + description;
print(ui.Label('Exporting image:'),recipe,ui.Label(' for address:'+assetId));
// export
Export.image.toAsset({
image: recipe,
description:'fire-'+description,
assetId: assetId,
region: region,
pyramidingPolicy:'mode',
scale: 30,
maxPixels: 1e13,
});