0

This code give me mask out pixels where in all of wind speeds are below 5, but if I want use this code for many days what should I do? It is hard to write for 30 days. Actually, I want run this code for 01/01/2020 to 30/01/2020.

var fc = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017')
  .filter('wld_rgn == "SE Asia"')

var Windspeed = ee.ImageCollection('NASA/GLDAS/V021/NOAH/G025/T3H')
  .filter(ee.Filter.date('2020-01-01'))
  .select('Wind_f_inst')
  .mean()

var Windspeed1 = ee.ImageCollection('NASA/GLDAS/V021/NOAH/G025/T3H')
  .filter(ee.Filter.date('2020-01-02'))
  .select('Wind_f_inst')
  .mean()
  
var Windspeed2 = ee.ImageCollection('NASA/GLDAS/V021/NOAH/G025/T3H')
  .filter(ee.Filter.date('2020-01-03'))
  .select('Wind_f_inst')
  .mean()  

var Windspeed3 = ee.ImageCollection('NASA/GLDAS/V021/NOAH/G025/T3H')
  .filter(ee.Filter.date('2020-01-04'))
  .select('Wind_f_inst')
  .mean() 
  
var Windspeed4 = ee.ImageCollection('NASA/GLDAS/V021/NOAH/G025/T3H')
  .filter(ee.Filter.date('2020-01-05'))
  .select('Wind_f_inst')
  .mean() 
  
var mask = Windspeed.gt(5).or(Windspeed1.gt(5)).or(Windspeed2.gt(5)).or(Windspeed3.gt(5)).or(Windspeed4.gt(5))

var u = Windspeed.updateMask(mask)
var u1 = Windspeed1.updateMask(mask)
var u2 = Windspeed2.updateMask(mask)
var u3 = Windspeed3.updateMask(mask)
var u4 = Windspeed4.updateMask(mask)

var windt = u.add(u1).add(u2).add(u3).add(u4)

var WindVis = {
  min: 46.05683272577041,
  max: 101.32877871485076,
  palette: ['1303ff', '42fff6', 'f3ff40', 'ff5d0f'],
}


Map.addLayer(windt.clip(fc), WindVis,'U2')

1 Answer 1

0

I know what your problem is. You have in January of 2020, for 'NASA/GLDAS/V021/NOAH/G025/T3H' each 3 hours product, 248 images and you need one image for each day (total 31 images because January has 31 days; not 30). To make a Loop for daily mean wind speed in Google Earth Engine, you can use the following code for entire dates range (2020-01-01, 2020-02-01). It masks all daily images in that range for values lesser than 5 and clip them for your fc area. It also prints only the first image of that dates range because I don't know what do you want to do with this series.

var fc = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017')
  .filter('wld_rgn == "SE Asia"');

Map.centerObject(ee.Geometry.Point (104.359, 16.095), 7);

var windSpeed = ee.ImageCollection('NASA/GLDAS/V021/NOAH/G025/T3H')
  .filter(ee.Filter.date('2020-01-01', '2020-02-01'))
  .select('Wind_f_inst');

print(windSpeed);

var startDate = ee.Date('2020-01-01');
var endDate = ee.Date('2020-02-01');

var days = endDate.difference(startDate, 'days');
var daysStep = 1;

function masked (img) {
  
  var mask = img.gt(5);
  
  return img.updateMask(mask).clip(fc);
  
}

var newWindSpeed = ee.ImageCollection(
  ee.List.sequence(0, days.subtract(1), daysStep)
    .map(function (offsetDays) {
      var start = startDate.advance(offsetDays, 'days');
      var end = start.advance(daysStep, 'days');
      var composite = windSpeed  // former lst
        .filterDate(start, end)
        .mean();
      return composite.set('system:time_start', start.millis());
    })
  ).map(masked);

print(newWindSpeed);

var WindVis = {
  min: 5,
  max: 10,
  palette: ['1303ff', '42fff6', 'f3ff40', 'ff5d0f'],
};

Map.addLayer(newWindSpeed.first(), WindVis,'U2');

After running above code, result looks as follows (centered in 104.359, 16.095 point, zoom 7). All observed pixels in Laos, Thailand, Vietnam and Cambodia have values greater than 5 m/s.

enter image description here

Your Answer

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

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