I'm working with an image where the value of each pixel corresponds to the day of the year, starting with 2019-01-01.
Date | Pixel value |
---|---|
2019-01-01 | 1 |
2019-01-02 | 2 |
2019-01-03 | 3 |
… | … |
2022-04-11 | 1196 |
I want to convert the value of these pixels (cumulative day of year) into milliseconds, but I couldn't think of a way to do it.
Unfortunately I can't provide an image to reproduce the code.
Best Answer
Since
1196
should give the millis for2022-04-11
, it seems like you want to exclude leap days altogether. Is this the case?If you exclude leap days, it's quite simple:
Otherwise, it's tricky. Since you need to do date manipulations on an image, you cannot rely on
ee.Date
, so you have to manually deal with the date logic, which is notoriously easy to get wrong. Anyway, below is my stab at implementing something like this. I'm sure there are problems with the implementation, it certainly it has some assumptions that causes this to fail if your date is too far in the future (2070s).https://code.earthengine.google.com/16a23b3554e90c869c999de09e2fde90