3

I'm working with RADD alerts stored in the YYDOY (Year-Year-Day-Of-Year) format, and I'm having trouble converting this information to milliseconds.

I've tried the following:

var loadLatestRaddAlert = function() {
    var alerts = ee.ImageCollection('projects/radar-wur/raddalert/v1');
    var geography = 'sa';
    return ee.Image(
        alerts.filter(
            ee.Filter.and(
                ee.Filter.eq('layer', 'alerts'),
                ee.Filter.eq('geography', geography)
            )
        ).sort('system:time_end', false).first()
    ).select('Date');
};

var convertRaddDateToMillis = function(dateBand) {
    var year = dateBand.divide(1000).floor().add(2000);
    var doy = dateBand.mod(1000);
    var daysSinceEpoch = year.subtract(1970).multiply(365).add(doy);
    var millis = daysSinceEpoch.multiply(86400).multiply(1000);
    return millis;
};

The pixel with value 22121 (2022-05-01) should return me 1651363200000, but it returns 1650326400000.

I think it's because of leap years. Any suggestion?

4
  • There really isn't any GIS content here, just date handling in JavaScript. It would be better researched over in Stack Overflow.
    – Vince
    May 16 at 13:17
  • What is your full date range?
    – xunilk
    May 16 at 13:26
  • 1
    @Vince my question concerns the conversion of dates within the Earth Engine platform, from ee.Image objects, and not from a JavaScript Date object. So I believe this is the most appropriate place. May 16 at 13:46
  • @xunilk 19000 to 22121. Data will continue to be updated. May 16 at 13:54

1 Answer 1

4

Okay, so here is a way that should work. Probably not the fastest or cleanest, but the advantage is that you don't have to implement messy date logic with leap years or leap seconds yourself.

I'm basically building a lookup table for a desired time period and remapping the values in the image.

var test = ee.ImageCollection('projects/radar-wur/raddalert/v1').first().select("Date")

var start = ee.Date("2019-01-01")
var end = ee.Date("2023-01-01")
var days = end.difference(start, "days")

var yydoy = ee.List.sequence(0, days).map(function(advance){
  return ee.Number.parse(start.advance(advance, "days").format("yyDDD"))
})
var millis = ee.List.sequence(0, days).map(function(advance){
  return start.advance(advance, "days").millis()
})

var in_millis = test.remap(yydoy, millis, 0)
Map.addLayer(in_millis)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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