0

I want to generate raster for each month , where the value of the pixel refers to the number of days per month and per year where temperature fall under 0 degree celsius. In this example the year range is [2010,2012], which means that i will get 36 images. But what i get , is 36 images with no band.

Any solution ?

var years = ee.List.sequence(2010,2012);
var months = ee.List.sequence(1,12);
var imcol = ee.ImageCollection("MODIS/006/MOD11A1");
var opla = function(image){ return image.select('LST_Day_1km').multiply(0.02).subtract(273.15).lte(0).clip(table)};
var filtred = imcol.map(opla);

var sommation_frost = function(y){
  var sommar = filtred.filter(ee.Filter.calendarRange(y,y,'year'));
  var montar = function(m){
    var x = sommar.filter(ee.Filter.calendarRange(m,m,'month')).reduce(ee.Reducer.sum())
    return x
  }
  return months.map(montar)
}

var sortie = years.map(sommation_frost)

1 Answer 1

1

For each month: Get images for the month, mask pixels above zero, and count how many unmasked pixels you have. Since you have an image per day, that count reflects the number of days below zero.

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

var startDate = ee.Date.fromYMD(2010, 1, 1)
var endDate = ee.Date.fromYMD(2013, 1, 1) // Exclusive
var aoi = Map.getBounds(true) // Replace this with your area

var collection = ee.ImageCollection('MODIS/006/MOD11A1')
  .filterBounds(aoi)

var numberOfMonths = endDate.difference(startDate, 'months').floor()
var daysBelow0Collection = ee.ImageCollection(
  ee.List.sequence(0, numberOfMonths.subtract(1))
    .map(daysBelow0)
)

print(daysBelow0Collection)
Map.addLayer(daysBelow0Collection.first(), {min: 0, max: 20, palette: 'red,orange,yellow,green,blue,white'}, 'First image')

function daysBelow0(monthOffset) {
  var date = startDate.advance(monthOffset, 'months')
  return collection
    .select('LST_Day_1km')
    .filterDate(date, date.advance(1, 'months'))
    .map(function (image) {
      var below0 = image.multiply(0.02).subtract(273.15).lte(0)
      return image.updateMask(below0)
    })
    .count()
    .unmask(0)
    .clip(aoi)
    .set('date', date.format('yyyy-MM-dd'))
}
2
  • It perfectly worked . With regards
    – Issamyax
    Commented Feb 20, 2021 at 11:31
  • @Issamyax Please, mark as accepted this answer because it perfectly worked for you. Thanks.
    – xunilk
    Commented Feb 26, 2021 at 17:36

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.