-
Notifications
You must be signed in to change notification settings - Fork 0
/
sentinel-1.js
129 lines (102 loc) · 3.56 KB
/
sentinel-1.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
// Function returns true if leap year, false otherwise.
var isLeapYear = function(year) {
return (year % 4 === 0 && year !== 100) || year % 400 === 0;
};
// Gets the number of days in any month in a year.
var getDaysInMonth = function(year, month) {
var leapYear = isLeapYear(parseInt(year, 10));
var daysInMonth = 0;
var monthNumber = parseInt(month, 10);
if (monthNumber === 2) {
daysInMonth = 28;
//leapyear ? daysInMonth = 29 : daysInMonth = 28;
}
else if (
monthNumber === 4 ||
monthNumber === 6 ||
monthNumber === 9 ||
monthNumber === 11
){
daysInMonth = 30;
}
else {
daysInMonth = 31;
}
return (daysInMonth);
};
// Adds rectangle (the study area) and create a Feature object using the rectangle.
var region = ee.Geometry.Rectangle(-4.5,48.2,-3.4,48.9); //-4.82,48.1,-3.4,48.9
var studyArea = ee.Feature(region, { name: 'france'});
/* Show object properies in the Console. */
print(studyArea);
/* Sets the map view to the center
* of the study area. */
Map.setCenter(-3.5,48.5,9);
//Map.centerObject(studyArea);
// Loads the Sentinel-1 image collection.
var sentinel1 = ee.ImageCollection('COPERNICUS/S1_GRD');
/* Coordinate pairs, set start and end date
* for filtering the collection. */
var point = ee.Geometry.Point(-3.5, 48.5);
var currentYear = new Date().getFullYear();
// User inputs: year and month. Data is available from 12/2014!
var year = prompt('Which year you want to process (between 2014 and ' + currentYear + ')?');
// Use leading 0 if month number < than 10!
var month = prompt('Which month you want to process?', '07');
var daysInMonth = getDaysInMonth(year, month);
var start = ee.Date(year + '-' + month + '-01');
var finish = ee.Date(year + '-' + month + '-' + daysInMonth);
print(finish);
print(daysInMonth);
// Filtering based on metadata properties.
var vh = sentinel1
// Filter to get images with VV and VH dual polarization.
.filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VV'))
.filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
// Filter to get images collected in interferometric wide swath mode.
.filter(ee.Filter.eq('instrumentMode', 'IW'))
.filterBounds(point)
.filterDate(start, finish);
// Filter to get images from different look angles.
var vhAscending = vh.filter(ee.Filter.eq('orbitProperties_pass', 'ASCENDING'));
var vhDescending = vh.filter(ee.Filter.eq('orbitProperties_pass', 'DESCENDING'));
// Create a composite from means at different polarizations and look angles.
var composite = ee.Image.cat([
vhAscending.select('VH').mean(),
ee.ImageCollection(vhAscending.select('VV').merge(vhDescending.select('VV'))).mean(),
vhDescending.select('VV').mean()
]).focal_median();
// Clip composite image with our study area.
var compositeClipped = composite.clip(studyArea);
// Display as a composite of polarization and backscattering characteristics.
Map.addLayer(
compositeClipped,
{
min: [-25, -20, -25],
max: [0, 10, 0]
},
'composite'
);
// Create an empty image into which to paint the features, cast to byte.
var empty = ee.Image().byte();
// Paint all the polygon edges with the same number and width, display.
var outline = empty.paint(
{
featureCollection: studyArea,
color: "black",
width: 2
}
);
Map.addLayer(outline, { palette: 'f00' }, 'Study Area');
print(compositeClipped);
// Save the composite image as GeoTIFF.
Export.image.toDrive(
{
image: compositeClipped,
description: 'Sentinel'+year+month,
scale: 10,
fileFormat: 'GeoTIFF',
maxPixels: 3784216672400,
region: studyArea
}
);