-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGEE Code to generate TCT.txt
More file actions
69 lines (54 loc) · 2.08 KB
/
Copy pathGEE Code to generate TCT.txt
File metadata and controls
69 lines (54 loc) · 2.08 KB
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
var shapefile = ee.FeatureCollection("users/stLuciashp"),
//Import study area shapefile
var shp= ee.FeatureCollection(shapefile);
//Import Sentinel-2 MSI: MultiSpectral Instrument, Level-1C
//from GEE cloud
var dataset = ee.ImageCollection("COPERNICUS/S2")
.filterBounds(shp)
.filterDate('2021-06-01', '2022-12-31')
;
//Display the study area shapefile
Map.addLayer (shapefile, {color: 'blue'}, 'Study Area')
//Display the sentinel image
Map.addLayer(dataset, {bands:['B4', 'B3', 'B2'], min:0, max:3000}, 'Sentinel 2021')
//clip the sentinel image to study area shapefile
//and select the median composite
var clip = dataset.median().clip(shp);
Map.addLayer(clip, {bands:['B4', 'B3', 'B2'], min:0, max:3000}, 'Clip 2020')
// Define an Array of Tasseled Cap coefficients for bands 2,3,4 and 8.
var coefficients = ee.Array([
[0.0822,0.1360,0.2611, 0.3895],
[-0.1128,-0.1680,-0.3480,0.3165],
[0.1363,0.2802,0.3072 ,-0.0807],
]);
//select the four bands from the sentinel image
//where the coefficients will be applied.
var image = clip.select(['B2', 'B3', 'B4', 'B8']);
// Make an Array Image, with a 1-D Array per pixel.
var arrayImage1D = image.toArray();
// Make an Array Image with a 2-D Array per pixel, 6x1.
var arrayImage2D = arrayImage1D.toArray(1);
// Do a matrix multiplication: 6x6 times 6x1.
var componentsImage = ee.Image(coefficients)
.matrixMultiply(arrayImage2D)
// Get rid of the extra dimensions.
.arrayProject([0])
.arrayFlatten(
[['brightness', 'greenness', 'wetness']]);
// Display the first three bands of the result and the input imagery.
var vizParams = {
bands: ['brightness', 'greenness', 'wetness'],
min: 0.5, max: [0.5,0.1,0.1]
};
//Display the TCT images
Map.addLayer(clip, {bands: ['B5', 'B4', 'B3'], min: 0, max: 3000}, 'TCT');
Map.addLayer(componentsImage, vizParams, 'Components');
//Export to google drive folder
Export.image.toDrive({
image: componentsImage,
description: 'Sentinel_TCT_STLucia',
folder: 'GEE',
region: shapefile,
scale: 10,
maxPixels: 1e10
});