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?

4
  • Can you include the definition of the geometry object? May 2 at 16:06
  • Thank you for the comment! I added my geometry's information.
    – geefrog
    May 3 at 12:00
  • Please provide a complete, running script, with all used assets shared. Ideally, add a link to the code editor too (using the Get Link button). May 4 at 9:07
  • @DanielWiell, Thank you for the advice! I have updated my question. I know I should add my link, but I'm not familiar with privacy problem. So, I was wondering if you could use the written code...
    – geefrog
    May 4 at 12:12

1 Answer 1

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

5
  • Thank you for the wonderful answer! I have got the hint!
    – geefrog
    May 5 at 0:36
  • Oh, I'm sorry, but I'd also like to know the way to convert Image(from weeklyMean) into the Number of VH value...
    – geefrog
    May 5 at 2:06
  • You have different VH values for different pixels. Are you looking for the mean VH across all pixels in your area of interest? If so, that's reduceRegion() you want. May 5 at 4:12
  • Thank you so much! I'll try it!
    – geefrog
    May 5 at 8:43
  • I have complited my task! Thank you!
    – geefrog
    May 5 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.