2

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?

geefrog
  • 23
  • 5

1 Answers1

1

I'm not completely clear what you're trying to do in your script, but divideimage() return an image. Calling get() on an image get you an image property. VH is not a property, it's a band, so you want to use select() instead.

You're also mixing up client-side and server-side operations with ee.Algorithms.If(divideimage(2017,42).get('VH') < -20. Read up on this here.

Maybe this script can give you some ideas how to approach your analysis.

var weeklyMean = calculateWeeklyMean(2017, 1, geometry)
var zeroOrOne = weeklyMean.lt(-20)
Map.addLayer(weeklyMean, {min: -30, max: 5}, 'weeklyMean')
Map.addLayer(zeroOrOne, {}, 'zeroOrOne')
Map.centerObject(geometry, 14)

function calculateWeeklyMean(year, week, geometry) { var date = ee.Date.fromYMD(year, 1, 1) .advance(ee.Number(week).subtract(1), 'weeks') return ee.ImageCollection('COPERNICUS/S1_GRD') .filterDate(date.getRange('week')) .filterBounds(geometry) .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH')) .filter(ee.Filter.eq('instrumentMode', 'IW')) .filter(ee.Filter.eq('orbitProperties_pass', 'DESCENDING')) .select('VH') .mean() // Hack so you get a masked image instead of a 0 band image // when there is no imagery .addBands(ee.Image().rename('VH')).select('VH') }

https://code.earthengine.google.com/d30d7f268beda28ea783dd100e607dbb

Daniel Wiell
  • 14,155
  • 2
  • 11
  • 29