-
Notifications
You must be signed in to change notification settings - Fork 1
/
S1_timeSeries_image_point_sameOrbit_downloading
160 lines (135 loc) · 7.05 KB
/
S1_timeSeries_image_point_sameOrbit_downloading
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
//****************************************************************
// setting parameters
//****************************************************************
// choose asc/desc orbits
var pol = 'VH'
var orbitProperties_pass = 'ASCENDING'
// selet images used for multitemporal denoising
var startTimeS1 = '2016-12-01'//
var stopTimeS1 = '2020-09-17'
// select downloading images
var selectS1startTime = '2016-12-01'
var selectS1sopTime = '2020-09-17'
var downloadFileNameVV = 'S1VH_asc_2017'
// loacate the data and choose the area of interest
var endIdex = 38
var geometry = ee.Geometry.Polygon(
[[[5.5539312236135485, 52.59901770733245],
[5.5539312236135485, 52.54173864708035],
[5.6775274150197985, 52.54173864708035],
[5.6775274150197985, 52.59901770733245]]], null, false);
var lon=5.612942504477618; var lat=52.569644116232766;
// var geometry = ee.Geometry.Point(lon,lat);
var pt = ee.Geometry.Point([lon, lat]);
Map.setCenter(lon, lat, 12);
//****************************************************************
//select the same orbit
var sentinel1_liste = ee.ImageCollection('COPERNICUS/S1_GRD').filterBounds(pt)
.filter(ee.Filter.eq('instrumentMode', 'IW'))
.filter(ee.Filter.eq('orbitProperties_pass', orbitProperties_pass))
.sort('system:time_start', true)
.filterDate(startTimeS1, stopTimeS1)
.filterBounds(geometry);
var sentinel1_liste2 = ee.ImageCollection('COPERNICUS/S1_GRD').filterBounds(pt)
.filter(ee.Filter.eq('instrumentMode', 'IW'))
.filter(ee.Filter.eq('orbitProperties_pass', orbitProperties_pass))
.sort('system:time_start', true)
.filterDate(startTimeS1, stopTimeS1)
.filterBounds(geometry);
// a solution to get metadata value of images of a collection
var NbOrbit = sentinel1_liste.aggregate_count_distinct('relativeOrbitNumber_start');
print('Number of Orbits',NbOrbit);
var ListOrbits = sentinel1_liste.aggregate_array('relativeOrbitNumber_start');
print(ListOrbits);
// find orbit numbers and their frequency
var freq = ee.Dictionary(ee.List(ListOrbits).reduce(ee.Reducer.frequencyHistogram()));
var array = ee.Array([freq.keys().map(ee.Number.parse), freq.values()]);
// orbit choice : first, the one with the max frequency
var frequences = array.slice(0,-1);
var arraysort = array.sort(frequences);
var index = ee.Number(NbOrbit).add(-1);
var orbite = arraysort.get([0,ee.Number(index)]);//selet specific orbit data
print('Selected orbit=',orbite);
// find images with the choice orbit
var collection = sentinel1_liste2.filterMetadata('relativeOrbitNumber_start', 'equals', orbite);
// Count the number of images
var count = collection.size();
var S1listA = collection.toList(count);print('S1AmlistA: ', S1listA);
// show temporal average SAR image
Map.addLayer(collection.select([pol]).mean().clip(geometry),{min: -25, max: 1}, 'Temporal average SAR image')
//****************************************************************
// denoising time series, compute space-average for all images
function multitemporalDespeckle(images, radius, units, opt_timeWindow) {
var timeWindow = opt_timeWindow || { before: -3, after: 3, units: 'month' }
var bandNames = ee.Image(images.first()).bandNames()
var bandNamesMean = bandNames.map(function(b) { return ee.String(b).cat('_mean') })
var bandNamesRatio = bandNames.map(function(b) { return ee.String(b).cat('_ratio') })
// compute space-average for all images
var meanSpace = images.map(function(i) {
var reducer = ee.Reducer.mean()
var kernel = ee.Kernel.square(radius, units)
var mean = i.reduceNeighborhood(reducer, kernel).rename(bandNamesMean)
var ratio = i.divide(mean).rename(bandNamesRatio)
return i.addBands(mean).addBands(ratio)
})
//computes a multi-temporal despeckle function for a single image
function multitemporalDespeckleSingle(image) {
var t = image.date()
var from = t.advance(ee.Number(timeWindow.before), timeWindow.units)
var to = t.advance(ee.Number(timeWindow.after), timeWindow.units)
var meanSpace2 = ee.ImageCollection(meanSpace).select(bandNamesRatio).filterDate(from, to)
var b = image.select(bandNamesMean)
return b.multiply(meanSpace2.sum()).divide(meanSpace2.size()).rename(bandNames).copyProperties(image, ['system:time_start'])
}
return meanSpace.map(multitemporalDespeckleSingle).select(bandNames)
}
//denoise images
var radius = 7*10
var units = 'meters'
var collection1 = multitemporalDespeckle(collection, radius, units, { before: -2, after: 2, units: 'month' })
// show noisy and denoised SAR image
Map.addLayer(collection.select([pol]).filterDate('2017-02-19', '2017-02-22').mean().clip(geometry),{min: -25, max: 1}, 'Noisy SAR image')
Map.addLayer(collection1.select([pol]).filterDate('2017-02-19', '2017-02-22').mean().clip(geometry),{min: -25, max: 1}, 'Denoised SAR image')
//****************************************************************
// download images
//****************************************************************
var collectionVV = collection.select(['VV']).filterDate(selectS1startTime, selectS1sopTime);
// Map.addLayer(collection1.select(['VV']).filterDate(selectS1startTime, selectS1sopTime),{min: -18, max: 0}, 'original SAR image');
// Map.addLayer(collectionVV.mean().updateMask(mask).clip(geometry),{min: -18, max: 0}, 'Filtered SAR image');
var collection1VV = collection1.select([pol]);
var count1 = collection1VV.size();print('images:', count1)
var S1listA1 = collection1VV.toList(count1);print('S1AmlistA1: ', S1listA1);
print(ui.Chart.image.series(collection.select(['VH']).filterDate(selectS1startTime, selectS1sopTime), pt, ee.Reducer.mean()),'Sentinel-1 VH');
print(ui.Chart.image.series(collection.select(['VV']).filterDate(selectS1startTime, selectS1sopTime), pt, ee.Reducer.mean()),'Sentinel-1 VV');
print(ui.Chart.image.series(collection1.select(['VV']).filterDate(selectS1startTime, selectS1sopTime), pt, ee.Reducer.mean()),'Sentinel-1 denoised VV');
//****************************************************************
// Download the time series Sentinel-1 VV data
var TSimage = ee.Image(collection1.select(['VV']).mean());
print('ee.Image(S1listA1.get(i))', ee.Image(S1listA1.get(28)))
// print('Projection, crs, and crs_transform:', TSimage.projection());
for (var i=28; i<endIdex; i++) {
var TSimage = TSimage.addBands(ee.Image(S1listA1.get(i)));}
Export.image.toDrive({
image: TSimage.clip(geometry),//.updateMask(mask),//
description: downloadFileNameVV,
scale: 10,
region: geometry,
// crs: 'EPSG:32650'//need modification according to test place
// especially when combining with optical data
});
//****************************************************************
// Download the time series over pt
var createTS = function(img){
var date = img.get('system:time_start');
var value = img.reduceRegion(ee.Reducer.mean(), pt).get('VV');
var ft = ee.Feature(null, {'system:time_start': date,
'date': ee.Date(date).format('Y/M/d'),
'value': value});
return ft;
};
var TS = collectionVV.map(createTS);
Export.table.toDrive({
collection: TS,
description: downloadFileNameVV,
fileFormat: 'CSV'
});