1

I am trying to modify this code , which applies a unique filter date range for each pixel in an image collection.

I have an image where the value of each pixel is the day of the start of the fire. I want to extract climate variables for the day of the fire from a separate image. The trouble is that the climate variables are reported monthly (the date for each climate image is the first day of the month) and my fire start day could be any day.

My idea is to extract the month from the fire start day band, which is in millis. The trouble is I cannot use the ee.Date() command on an image. Here's what I have so far (and here's the link).

/// all fires are in 2001
var image = ee.Image("users/ewebb/fire_imgs/fire_img_2001");
var climatedata = ee.ImageCollection('IDAHO_EPSCOR/TERRACLIMATE')
      .filter(ee.Filter.date('2001-01-01','2001-12-31'));

var dayof_fire = ee.Date(image.select('FireDay')).get('month')


var climatecollection = climatedata.map(function(cimg){
                    var dateBand = ee.Image(cimg.date().get('month'));
                    cimg = cimg.updateMask(dateBand.eq(dayof_fire));
                    return cimg.select("pdsi", 'def') });
   

I also tried

var dayof_fire = image.select('FireDay')
                  .expression('ee.Date(DOF)', 
                  {'DOF': image.select('FireDay')})

1 Answer 1

-1

I have tried in Earth Engine Code Editor like this:

var millis = ee.Date.fromYMD(2023,3,8).millis();
var date = new ee.Date(millis);
print(date.getInfo())

It works.

1
  • But the question is how to get this when the date is stored in an image band, not how to get millis from a date you enter in yourself.
    – webbe
    Mar 9, 2023 at 14:02

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.