I'd like to get the weekly VHmean value to compare the threshold value.
I wrote the code with reference to other ones.
For example:
Google Earth Engine: cumulative iteration of weekly mean anomaly
Getting weekly mean composite in Google Earth Engine?
Here is my code.
var geometry = /* color: #00ffff */ee.Geometry.Polygon(
[[[107.5334247704419, 16.553900323143303],
[107.53325310906494, 16.544356397007547],
[107.5268158074292, 16.540982999796455],
[107.5264724846753, 16.53835006342529],
[107.53505555352295, 16.540407048035554],
[107.53574219903076, 16.534482872994197],
[107.54200783928955, 16.536951301364418],
[107.54278031548584, 16.54517916786569]]]);
Map.centerObject(geometry,14);
var bsc1 = {
min:-26,
max:-18,
palette:['red','white']
};
var sentinel_pre = ee.ImageCollection('COPERNICUS/S1_GRD')
.filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
.filter(ee.Filter.eq('instrumentMode', 'IW'))
.filter(ee.Filter.eq('orbitProperties_pass', 'DESCENDING'))
.select('VH');
var divideimage = function (year,week){
var startDate = ee.Date.fromYMD(year,1,1);
var endDate = ee.Date.fromYMD(year,12,31);
var weekDifference = ee.Date(startDate)
.advance(1, 'week').millis()
.subtract(ee.Date(startDate).millis());
var weeks = ee.List.sequence(
ee.Date(startDate).millis(),
ee.Date(endDate).millis(),
weekDifference);
var getsentinel = function(date){
var sentinel = sentinel_pre
.filterDate(date,date.advance(1,'week'))
.filter(ee.Filter.bounds(geometry))
.mean();
return sentinel;
};
var dateMillis = weeks.get(week);
var sentinel1_IC = function(dateMillis){
var date = ee.Date(dateMillis);
return getsentinel(date);
};
return sentinel1_IC(dateMillis);
};
print(divideimage(2017,42).get('VH'));
ee.Algorithms.If(divideimage(2017,42).get('VH') < -20
,print(ee.Number(1))
,print(ee.Number(0)));
var image = function(year,week){
var condition = ee.Algorithms.If(divideimage(year,week) < -20
,ee.Number(1)
,ee.Number(0));
ee.Algorithms.If(condition==1,
Map.addLayer(divideimage(year,week),bsc1,"bsc"+week));
};
image(2017,42);
However, using this code, GEE returned "null" from
print(divideimage(2017,42).get('VH'));
and both "1" and "0" from
ee.Algorithms.If(divideimage(2017,42).get('VH') < -20
,print(ee.Number(1))
,print(ee.Number(0)));
Ideally, I'd like to get images when the VHmean value in the specific area
goes below the threshold value, and I expect to display the area red.
Now, I don't know why but I can display some images.
Could you tell me the reason of getting invalid values and revise my code?
geometry
object?Get Link
button).